HDU 1556 트 리 배열
3332 단어 HDU데이터 구조 - 트 리 배열
해제
트 리 배열 템 플 릿 문제 구간 염색 + 통계 횟수 를 위로 조회 하고, 아래 통 계 를 통 해 a 이후 구간 에 염색 업 데 이 트 를 한 번 더 한 다음 b 이후 염색 업 데 이 트 를 한 번 줄 이면 [a, b] 데 염색 업 데 이 트 를 완성 합 니 다.
AC code:
#include
#include
#include
using namespace std;
#define lowbit(x) (x & (-x))
#define LL long long
#define debug 1
const int maxn(100005);
const int mod(1e9 + 7);
int c[maxn];
int n;
void add(int x, int y, int v) {
for (int i = x; i <= n; i += lowbit(i)) {
c[i] += v;
}
for (int i = y + 1; i <= n; i += lowbit(i)) {
c[i] -= v;
}
}
int getSum(int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) {
res += c[i];
}
return res;
}
int main() {
#if debug
freopen("in.txt", "r", stdin);
#endif //debug
int a, b;
while (cin >> n, n) {
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; ++i) {
cin >> a >> b;
add(a, b, 1);
}
for (int i = 1; i <= n; i++) {
int ans = getSum(i);
cout << ans << (i == n ? "
" : " ");
}
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
hdu4671(다교리그 7--수 시뮬레이션)클릭하여 링크 열기 제목: n과 서버, m개의 데이터베이스가 있고 모든 데이터베이스는 서버를 연결해야 하지만 모든 데이터베이스는 서버를 연결하는 우선순위가 있습니다.모든 데이터베이스의 서버 우선순위를 구하다.또한 한...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.