#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define debug if(0)
const int mod = 1e9 + 7;
const ll infL = 1e18 + 7;
const int inf = 1e9 + 7;
struct node {
int l, r;
ll sum = 0, lazy = -1;
node *left = nullptr, *right = nullptr;
node(int lb, int rb) {
l = lb;
r = rb;
}
void extend() {
if(!left && l != r) {
int t = (l+r)/2;
left = new node(l, t);
right = new node(t+1, r);
}
}
void push() {
if(lazy != -1) {
extend();
left->lazy = lazy;
right->lazy = lazy;
int m = (l+r)/2;
left->sum = m-l+1;
right->sum = r-(m+1)+1;
lazy = -1;
}
}
void set(int lx, int rx) {
if(lx <= l && rx >= r) {
sum = r-l+1;
lazy = 1;
return;
}
if(lx > r || rx < l) return;
push();
extend();
left->set(lx, rx); right->set(lx, rx);
sum = left->sum + right->sum;
}
ll get(int lx, int rx) {
if(lx <= l && rx >= r) return sum;
if(lx > r || rx < l) return 0;
push();
extend();
return left->get(lx, rx) + right->get(lx, rx);
}
};
const int N = 1e9 + 4;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int m, c = 0; cin>>m;
node root(0, N);
for(int i=0; i<m; i++) {
int d, x, y; cin>>d>>x>>y;
x += c; y += c;
if(d == 1) {
c = root.get(x, y);
cout<<c<<"\n";
}
else {
root.set(x, y);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
13 ms |
4948 KB |
Output is correct |
5 |
Correct |
18 ms |
5972 KB |
Output is correct |
6 |
Correct |
15 ms |
5844 KB |
Output is correct |
7 |
Correct |
14 ms |
5972 KB |
Output is correct |
8 |
Correct |
112 ms |
44472 KB |
Output is correct |
9 |
Correct |
259 ms |
77340 KB |
Output is correct |
10 |
Correct |
275 ms |
85380 KB |
Output is correct |
11 |
Correct |
289 ms |
91708 KB |
Output is correct |
12 |
Correct |
278 ms |
94484 KB |
Output is correct |
13 |
Correct |
252 ms |
110072 KB |
Output is correct |
14 |
Correct |
232 ms |
111104 KB |
Output is correct |
15 |
Correct |
403 ms |
201680 KB |
Output is correct |
16 |
Correct |
394 ms |
203288 KB |
Output is correct |
17 |
Correct |
239 ms |
114748 KB |
Output is correct |
18 |
Correct |
284 ms |
114824 KB |
Output is correct |
19 |
Correct |
406 ms |
207652 KB |
Output is correct |
20 |
Correct |
428 ms |
207616 KB |
Output is correct |