#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
//#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
struct node{
int s, e, m, val;
bool lazy;
node *l, *r;
void create(){
if (l==nullptr){
l = new node(s, m);
r = new node(m+1, e);
}
}
void propagate(){
if (!lazy)return;
val=(e-s+1);
if (s!=e){
create();
l->lazy=lazy;
r->lazy=lazy;
}
lazy=0;
}
node(int S, int E){
s = S, e = E, m = (s+e)/2;
val=0;
lazy=0;
l=r=nullptr;
}
void up(int left, int right){
propagate();
if (s==left && e==right)lazy=1, del();
else{
create();
if (right<=m)l->up(left, right);
else if (left>m)r->up(left, right);
else l->up(left, m), r->up(m+1, right);
r->propagate(), l->propagate();
val=l->val+r->val;
if (val==e-s+1)del();
}
}
int query(int left, int right){
propagate();
if (s==left && e==right)return val;
if (val==e-s+1&&s<=left&&right<=e)return right-left+1;
create();
if (right<=m)return l->query(left, right);
else if (left>m)return r->query(left, right);
else return l->query(left, m)+r->query(m+1, right);
}
void del(){
if (l!=nullptr){
l->del();
r->del();
delete l;
delete r;
l = nullptr;
r = nullptr;
}
}
}*st;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, ans=0, a, b, c;
cin>>q;
st = new node(1, 1000000005);
while (q--){
cin>>a>>b>>c, b+=ans, c+=ans;
if (a==1)ans=st->query(b, c), cout<<ans<<"\n";
else st->up(b, c);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |