#include <bits/stdc++.h>
#define int long long
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->val = r - l + 1;
t->l->lz = t->r->lz = 1;
}
}
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 = max(t->val,(t->l?t->l->val:0) + (t->r?t->r->val:0));
}
}t;
int32_t main() {
int q,a,b,c,val=0;cin>>q;
while(q--) {
cin>>a>>b>>c;
if(a==1) {
int tmp = t.query(t.rt,1,1e9,b+val,c+val);
cout << tmp << "\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
5
2 5 8
2 7 10
1 5 8
1 7 10
1 1 10
2
2 1 10
1 1 100
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |