#include <bits/stdc++.h>   
using namespace std;  
#define int long long  
#define F first 
#define S second 
#define pb push_back 
#define skip continue
const int N = 1e6, NN=1e9 + 7;  
const int mod = 1e9 + 7;
int t[N*30], z[N*30], a[N*30],tl[N*30],tr[N*30];
int cnt = 2;
void push(int v, int l, int r) {
    if(z[v] != 0){
        t[v] = r - l + 1;
        if(l != r){
            if(tl[v] == 0) tl[v]=cnt++;
            if(tr[v] == 0) tr[v]=cnt++;
            z[tl[v]] = 1;
            z[tr[v]] = 1;
        }
        z[v] = 0;
    }
}
void upd(int v, int l, int r, int ll, int rr){
    push(v, l, r);
    if(ll<=l && r<=rr){
        z[v]++;
        push(v, l, r);
        return;
    }
    if(ll>r || l>rr) return;
    int m=(l+r)/2;
    if(tl[v] == 0) tl[v]=cnt++;
    if(tr[v] == 0) tr[v]=cnt++;
    upd(tl[v], l, m, ll, rr);
    upd(tr[v], m+1, r, ll, rr);
    t[v] = t[tl[v]] + t[tr[v]];
}
int get(int v, int l, int r, int ll, int rr){
    push(v, l, r);
    if(ll<=l && r<=rr) return t[v];
    if(l>rr || ll>r) return 0;
    int m=(l+r)/2;
    if(tl[v] == 0) tl[v]=cnt++;
    if(tr[v] == 0) tr[v]=cnt++;
    int g=get(tl[v], l, m, ll, rr), h=get(tr[v], m+1, r, ll, rr);
    return g+h;
}
int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int binpow(int a,int b){if(!b)return 1; if(b&1)return a*binpow(a,b-1)%mod; int x=binpow(a,b/2); return x*x%mod;}
signed main(){   
    ios_base::sync_with_stdio(0);   
    cin.tie(0);   
    cout.tie(0);   
    int n;
    cin>>n;
    int c = 0;
    for(int i=1;i<=n;i++){
        int ty,l,r;
        cin>>ty>>l>>r;
        if(ty == 1){
            int res = get(1,1,1e9,l + c,r + c);
            cout<<res<<endl;
            c=res;
        }
        else upd(1,1,1e9,l,r);
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |