#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define rep(i,l,r) for(int i = (l); i < r; i++)
#define per(i,r,l) for(int i = (r); i >= l; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define ss second
const ll mod = 998244353, maxn = 2e6 + 5, inf = 1e9 + 5;
struct Node{
Node *l, *r;
int sum = 0;
} *root = new Node();
void upd(int l, int r, Node *x = root, int lx = 0, int rx = inf){
if(l <= lx && r >= rx){
x->sum = rx - lx;
return;
} if(l >= rx || r <= lx || x->sum == rx - lx) return;
int mid = (lx + rx) >> 1;
if(!x->l) x->l = new Node();
if(!x->r) x->r = new Node();
upd(l, r, x->l, lx, mid);
upd(l, r, x->r, mid, rx);
x->sum = x->l->sum + x->r->sum;
}
int query(int l, int r, Node *x = root, int lx = 0, int rx = inf){
if(l <= lx && r >= rx) return x->sum;
if(l >= rx || r <= lx) return 0;
if(!x->l) x->l = new Node();
if(!x->r) x->r = new Node();
int mid = (lx + rx) >> 1;
return query(l, r, x->l, lx, mid) + query(l, r, x->r, mid, rx);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int q; cin >> q;
int c = 0;
while(q--){
int d, l, r; cin >> d >> l >> r;
if(d == 1){
c = query(c + l, c + r + 1);
cout << c << '\n';
}else upd(c + l, c + r + 1);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |