| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 314466 | Vince729 | 원숭이와 사과 나무 (IZhO12_apple) | C++11 | 51 ms | 3096 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int MAXN = 100003;
const int MOD = 1000000007;
struct Node {
int l, r, sum;
bool z;
Node *ln, *rn;
Node(int _l, int _r): l(_l), r(_r), sum(0), z(0), ln(nullptr), rn(nullptr) {}
void upd(int a, int b) {
if (z) return;
if (a <= l && b >= r) {
sum = r-l+1;
z = true;
} else {
int mid = (l+r)/2;
if (a <= mid) {
if (!ln) ln = new Node(l, mid);
ln->upd(a, b);
}
if (b > mid) {
if (!rn) rn = new Node(mid+1, r);
rn->upd(a, b);
}
sum = 0;
if (ln) sum += ln->sum;
if (rn) sum += rn->sum;
}
}
int qry(int a, int b) {
if (b < l || a > r) return 0;
if (a <= l && b >= r) return sum;
if (z) return min(b, r)-max(a, l)+1;
int ret = 0;
if (ln) ret += ln->qry(a, b);
if (rn) ret += rn->qry(a, b);
return ret;
}
};
int m;
Node root(1, 1000000000);
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> m;
int c = 0;
while (m--) {
int d, x, y; cin >> d >> x >> y;
if (d == 2) {
root.upd(x+c, y+c);
} else {
c = root.qry(x+c, y+c);
cout << c << '\n';
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
