#include <bits/stdc++.h>
using namespace std;
class tree{
// keeps the god
struct node{
node* l = nullptr;
node* r = nullptr;
int val=0,lz=0;
};
typedef node* pnode;
public:
pnode rt = nullptr;
void upd(pnode t,int l,int r) {
if(t->lz) {
if(!t->l) t->l = new node();
if(!t->r) t->r = new node();
t->l->lz=1;
t->r->lz=1;
t->val+=(r-l+1);
t->lz=0;
}
}
int query(pnode& t,int l,int r,int ll,int rr) {
if(l>r || r < ll || l > rr)return 0;
if(!t) t = new node();
upd(t,l,r);
if(l>=ll && r<=rr) return t->val;
int mid = l + (r-l)/2;
return query(t->l,l,mid,ll,rr) + query(t->r,mid+1,r,ll,rr);
}
void upd(pnode& t,int l,int r,int ll,int rr) {
if(l>r || r < ll || l > rr)return;
if(!t) t = new node();
upd(t,l,r);
if(l>=ll && r<=rr) {
t->lz = 1;
upd(t,l,r);
return;
}
int mid = l + (r-l)/2;
upd(t->l,l,mid,ll,rr);
upd(t->r,mid+1,r,ll,rr);
t->val = (t->l?t->l->val:0) + (t->r?t->r->val:0);
}
}t;
int main() {
int q,a,b,c,val=0;cin>>q;
while(q--) {
cin>>a>>b>>c;
if(a==1) {
val = t.query(t.rt,1,1e9,b+val,c+val);
cout << val << "\n";
} else {
t.upd(t.rt,1,1e9,b+val,c+val);
}
}
}
/*
4
2 2 3
1 1 3
2 2 3
1 -1 3
3
2 5 8
2 7 10
1 1 10
2
2 1 10
1 1 100
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |