#include <bits/stdc++.h>
using namespace std;
#define sped ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define s second
#define f first
const int N = 1e6 + 1;
int t[N*36],L[N * 36],R[N * 36];
int z[N * 36];
int cntv = 2;
void push(int v, int l, int r){
    if(z[v] != 0){
        t[v] = r - l + 1;
        if(l != r){
            if(L[v] == 0) L[v] = cntv++;
            if(R[v] == 0) R[v] = cntv++;
            z[L[v]] = 1;
            z[R[v]] = 1;
        }
        z[v] = 0;
    }
}
void update(int v,int tl,int tr,int l,int r){
   push(v,tl,tr);
   if(tl > r || l > tr) return;
   if(tl >= l && tr <= r){
        z[v] = 1;
   push(v,tl,tr);
   }
   else{
     int tm = (tl + tr) / 2;
     if(L[v] == 0) L[v] = cntv++;
     if(R[v] == 0) R[v] = cntv++;
     update(L[v],tl,tm,l,r);
     update(R[v],tm + 1,tr,l,r);
     t[v] = t[L[v]] + t[R[v]];
   }
}
int get(int v,int tl,int tr,int l,int r){
  push(v,tl,tr);
  if(t[v] == 0) return 0;
  if(tl > r || l > tr) return 0;
   if(tl >= l && tr <= r){
       return t[v];
   }
   int tm = (tl + tr) / 2;
   return get(L[v] ,tl,tm,l,r) + get(R[v] ,tm+1,tr,l,r);
}
void okok(){
  int q;
  cin >> q;
  int c = 0;
  while(q--){
    int type;
    cin >> type;
    int l,r;
    cin >> l >> r;
    int NN = 1e9;
    if(type == 2){
        update(1,1,NN,l + c,r + c);
    }
    else{
        int cc = get(1,1,NN,l + c,r + c);
        cout << cc << '\n';
        c = cc;
    }
  }
}
signed main() {
//freopen("bank.in", "r", stdin) ;
//freopen("bansk.out", "w", stdout);
sped
int tt = 1;
//cin >> tt;
while(tt--){
    okok();
    //cout << '\n';
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |