# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
791307 | lukehsiao | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 318 ms | 139508 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct node {
int sum;
bool lz;
node* c[2];
node() {
sum = 0;
lz = false;
c[0] = c[1] = NULL;
}
void push(int l, int mid, int r) {
if (lz) {
c[0]->sum = mid-l+1;
c[1]->sum = r-mid;
c[0]->lz = c[1]->lz = true;
lz = false;
}
}
void upd(int a, int b, int l=0, int r=1e9-1) {
if (l > b || r < a) return;
if (l >= a && r <= b) {
sum = r-l+1;
lz = true;
} else {
int mid = (l+r)/2;
if (!c[0]) c[0] = new node();
if (!c[1]) c[1] = new node();
push(l, mid, r);
c[0]->upd(a, b, l, mid);
c[1]->upd(a, b, mid+1, r);
sum = c[0]->sum + c[1]->sum;
}
}
int qry(int a, int b, int l=0, int r=1e9-1) {
if (l > b || r < a) return 0;
if (l >= a && r <= b) return sum;
int mid = (l+r)/2;
if (!c[0]) c[0] = new node();
if (!c[1]) c[1] = new node();
push(l, mid, r);
return c[0]->qry(a, b, l, mid) + c[1]->qry(a, b, mid+1, r);
}
};
int m, c;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
node root = node();
cin >> m;
for (int i=0, d, x, y; i<m; ++i) {
cin >> d >> x >> y;
if (d == 1) {
c = root.qry(x+c-1, y+c-1);
cout << c << '\n';
} else {
root.upd(x+c-1, y+c-1);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |