#include <bits/stdc++.h>
#define MAX 8000001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,m,n2,m2,k,cnt=0,x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3;
//ll c[1501][1501];
//ll fact[MAX];
//ll inv_fact[MAX];
//string str[MAX];
string s1,s2;
const int mod = 998244353;
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct dsu{
vector<ll> e;
void init(int n){
e.resize(n+1,-1);
}
int get(int x){
if(e[x]<0){
return x;
}
else{
return e[x]=get(e[x]);
}
}
int size(int x){
return -e[get(x)];
}
bool same_set(int x,int y){
return (get(x)==get(y));
}
bool unite(int x,int y){
x=get(x);
y=get(y);
if(x==y){
return false;
}
if(e[x]>e[y]){
swap(x,y);
}
e[x]+=e[y];
e[y]=x;
return true;
}
};
struct node{
int l,r,rn,ln,res,lazy;
node(): res(0),lazy(0),rn(-1),ln(-1){}
};
node tree[MAX];
void propogate(int x){
if(tree[x].lazy){
tree[x].res=tree[x].r-tree[x].l+1;
if(tree[x].r-tree[x].l==0){
return;
}
int mid=(tree[x].l+tree[x].r)/2;
if(tree[x].ln==-1){
tree[x].ln=cnt;
tree[cnt].l=tree[x].l;
tree[cnt].r=mid;
cnt++;
}
if(tree[x].rn==-1){
tree[x].rn=cnt;
tree[cnt].l=mid+1;
tree[cnt].r=tree[x].r;
cnt++;
}
tree[x].lazy=0;
tree[tree[x].ln].lazy=1;
tree[tree[x].rn].lazy=1;
}
}
void upd(int x,int l,int r){
propogate(x);
if(l==tree[x].l && r==tree[x].r){
tree[x].lazy=1;
propogate(x);
return;
}
int mid=(tree[x].l+tree[x].r)/2;
if(tree[x].ln==-1){
tree[x].ln=cnt;
tree[cnt].l=tree[x].l;
tree[cnt].r=mid;
cnt++;
}
if(tree[x].rn==-1){
tree[x].rn=cnt;
tree[cnt].l=mid+1;
tree[cnt].r=tree[x].r;
cnt++;
}
if(l>mid){
upd(tree[x].rn,l,r);
}
else if(r<=mid){
upd(tree[x].ln,l,r);
}
else{
upd(tree[x].ln,l,mid);
upd(tree[x].rn,mid+1,r);
}
propogate(tree[x].ln);
propogate(tree[x].rn);
tree[x].res=tree[tree[x].ln].res+tree[tree[x].rn].res;
}
int get(int x,int l,int r){
propogate(x);
if(tree[x].l==l && tree[x].r==r){
return tree[x].res;
}
int mid=(tree[x].l+tree[x].r)/2;
if(tree[x].ln==-1){
tree[x].ln=cnt;
tree[cnt].l=tree[x].l;
tree[cnt].r=mid;
cnt++;
}
if(tree[x].rn==-1){
tree[x].rn=cnt;
tree[cnt].l=mid+1;
tree[cnt].r=tree[x].r;
cnt++;
}
if(l>mid){
return get(tree[x].rn,l,r);
}
else if(r<=mid){
return get(tree[x].ln,l,r);
}
else{
return get(tree[x].ln,l,mid)+get(tree[x].rn,mid+1,r);
}
}
void solve(){
cin >> n;
tree[cnt].l=1;
tree[cnt].r=1e9;
cnt++;
k=0;
for(int i=0;i<n;i++){
cin >> m >> x >> y;
if(m==1){
k=get(0,x+k,y+k);
cout << k << "\n";
}
else{
upd(0,x+k,y+k);
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//USACO("poetry");
//freopen("input.txt","r",stdin);
//cin >> t;
ll cnt1=1;
while(t--){
solve();
cnt1++;
}
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
ll b[51][51];
b[0][0] = 1;
for (int n = 1; n <= 50; ++n){
b[n][0] = b[n][n] = 1;
for (int k = 1; k < n; ++k)
b[n][k] = b[n - 1][k - 1] + b[n - 1][k];
}
*/
Compilation message
apple.cpp: In constructor 'node::node()':
apple.cpp:108:23: warning: 'node::lazy' will be initialized after [-Wreorder]
108 | int l,r,rn,ln,res,lazy;
| ^~~~
apple.cpp:108:13: warning: 'int node::rn' [-Wreorder]
108 | int l,r,rn,ln,res,lazy;
| ^~
apple.cpp:109:5: warning: when initialized here [-Wreorder]
109 | node(): res(0),lazy(0),rn(-1),ln(-1){}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
188108 KB |
Output is correct |
2 |
Correct |
84 ms |
188128 KB |
Output is correct |
3 |
Correct |
77 ms |
188168 KB |
Output is correct |
4 |
Correct |
88 ms |
188236 KB |
Output is correct |
5 |
Correct |
86 ms |
188368 KB |
Output is correct |
6 |
Correct |
94 ms |
188320 KB |
Output is correct |
7 |
Correct |
94 ms |
188364 KB |
Output is correct |
8 |
Correct |
166 ms |
189168 KB |
Output is correct |
9 |
Correct |
288 ms |
190260 KB |
Output is correct |
10 |
Correct |
347 ms |
190296 KB |
Output is correct |
11 |
Correct |
298 ms |
190480 KB |
Output is correct |
12 |
Correct |
299 ms |
190292 KB |
Output is correct |
13 |
Correct |
271 ms |
190604 KB |
Output is correct |
14 |
Correct |
265 ms |
190720 KB |
Output is correct |
15 |
Correct |
355 ms |
190780 KB |
Output is correct |
16 |
Correct |
352 ms |
190784 KB |
Output is correct |
17 |
Correct |
271 ms |
190704 KB |
Output is correct |
18 |
Correct |
272 ms |
190848 KB |
Output is correct |
19 |
Correct |
375 ms |
190840 KB |
Output is correct |
20 |
Correct |
389 ms |
190784 KB |
Output is correct |