# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21879 | ulna | 원숭이와 사과 나무 (IZhO12_apple) | C++11 | 466 ms | 138244 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// why am I so weak
int m;
struct node {
int sum;
int lazy;
node *left, *right;
node(int sum) : sum(sum), lazy(-1) {left = right = NULL;}
} *root = new node(0);
void push(node *u, int x, int y) {
if (u->lazy < 0) return;
int mid = (x + y) >> 1;
u->left->lazy = u->right->lazy = 1;
u->left->sum = mid - x + 1;
u->right->sum = y - mid;
u->lazy = -1;
}
int query(node *u, int x, int y, int l, int r) {
if (!u) return 0;
if (l > y || r < x) return 0;
if (l <= x && y <= r) return u->sum;
int mid = (x + y) >> 1;
if (!u->left) u->left = new node(0);
if (!u->right) u->right = new node(0);
push(u, x, y);
return query(u->left, x, mid, l, r) + query(u->right, mid + 1, y, l, r);
}
void update(node *u, int x, int y, int l, int r) {
if (l > y || r < x) return;
if (l <= x && y <= r) {
u->sum = y - x + 1;
u->lazy = 1;
return;
}
int mid = (x + y) >> 1;
if (!u->left) u->left = new node(0);
if (!u->right) u->right = new node(0);
push(u, x, y);
update(u->left, x, mid, l, r);
update(u->right, mid + 1, y, l, r);
u->sum = u->left->sum + u->right->sum;
}
int main() {
scanf("%d", &m);
int c = 0;
while (m--) {
int ope, x, y;
scanf("%d %d %d", &ope, &x, &y);
x += c, y += c;
if (ope == 1) {
printf("%d\n", c = query(root, 1, (int)1e9, x, y));
} else {
update(root, 1, (int)1e9, x, y);
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |