#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); i++)
using ll = long long;
int m;
struct Node{
ll begin, end;
bool ripe;
Node *left, *right;
Node(ll b, ll e){
begin = b;
end = e;
}
void ins(ll a, ll b){
if(a <= begin && b >= end){
ripe = true;
return;
} if(b < begin || a > end) return;
if(left == NULL){
ll mid = (begin + end) / 2;
left = new Node(begin, mid);
right = new Node(mid + 1, end);
}
left->ins(a, b);
right->ins(a, b);
}
ll get(ll a, ll b){
if(a > end || b < begin) return 0;
if(ripe) {
return min(end, b) - max(begin, a) + 1;
} if(left == NULL){
return 0;
}
return left->get(a, b) + right->get(a, b);
}
} root(0, 1LL << 20);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> m;
ll c = 0;
rep(i, 0, m){
ll d, x, y;
cin >> d >> x >> y;
x += c;
y += c;
if(d == 2){
root.ins(x, y);
} else {
c = root.get(x, y);
cout << c << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
6 ms |
2892 KB |
Output is correct |
5 |
Correct |
9 ms |
3472 KB |
Output is correct |
6 |
Correct |
8 ms |
3540 KB |
Output is correct |
7 |
Correct |
9 ms |
3592 KB |
Output is correct |
8 |
Incorrect |
27 ms |
8064 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |