# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
467210 | Rico64 | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 1 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
const int MAX_SIZE = 1073741824;
using namespace std;
struct node {
node *l, *r;
int c;
node() : l(nullptr), r(nullptr), c(0) {}
~node() {
delete l;
delete r;
delete &c;
}
} *root;
void qpaint(node *v, int l, int r, int sz) {
if (l >= sz || r <= 0 || v->c == sz) return;
if (l <= 0 && r >= sz) {
v->c = sz;
delete v->l;
delete v->r;
v->l = v->r = nullptr;
return;
}
if (v->l == nullptr) {
v->l = new node();
v->r = new node();
}
qpaint(v->l, l, r, sz >> 1);
qpaint(v->r, l - (sz >> 1), r - (sz >> 1), sz >> 1);
v->c = v->l->c + v->r->c;
}
int qcount(node *v, int l, int r, int sz) {
if (l >= sz || r <= 0 || v->c == 0) return 0;
if (l <= 0 && r >= sz) {
return v->c;
}
if (v->l == nullptr) {
v->l = new node();
v->r = new node();
v->l->c = v->r->c = sz >> 1;
}
return qcount(v->l, l, r, sz >> 1) + qcount(v->r, l - (sz >> 1), r - (sz >> 1), sz >> 1);
}
int main() {
int ql;
cin >> ql;
root = new node();
int c = 0;
for (int it = 0, type; it < ql; ++it) {
cin >> type;
if (type == 1) {
int l, r;
cin >> l >> r;
c = qcount(root, l - 1 + c, r + c, MAX_SIZE);
cout << c << endl;
} else if (type == 2) {
int l, r;
cin >> l >> r;
qpaint(root, l - 1 + c, r + c, MAX_SIZE);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |