/*input
6
2 1 7
2 10 12
1 7 11
2 11 13
1 8 10
1 15 17
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int ll
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
int power(int a,int b,int m = MOD){
if(b == 0) return 1;
if(b == 1) return a;
int x = power(a,b/2,m)%m;
x = (x*x)%m;
if(b%2) return (x*a)%m;
return x;
}
struct node{
int l,r,xl,xr,val,lazy;
};
int SZ = 1;
node seg[10000005];
void neww(int ind){
int mid = (seg[ind].xl+seg[ind].xr)/2;
if(seg[ind].l == -1){
seg[ind].l = ++SZ;
seg[seg[ind].l].xl = seg[ind].xl;
seg[seg[ind].l].xr = mid;
seg[seg[ind].l].l = -1;
seg[seg[ind].l].r = -1;
seg[seg[ind].l].val = 0;
seg[seg[ind].l].lazy = 0;
}
if(seg[ind].r == -1){
seg[ind].r = ++SZ;
seg[seg[ind].r].xl = mid+1;
seg[seg[ind].r].xr = seg[ind].xr;
seg[seg[ind].r].l = -1;
seg[seg[ind].r].r = -1;
seg[seg[ind].r].val = 0;
seg[seg[ind].r].lazy = 0;
}
}
void push(int ind){
if(!seg[ind].lazy) return;
seg[ind].val = seg[ind].xr-seg[ind].xl+1;
if(seg[ind].val == 1) return;
neww(ind);
seg[seg[ind].l].lazy = seg[seg[ind].r].lazy = 1;
seg[ind].lazy = 0;
}
void upd(int ind,int l,int r){
// cout << ind << " " << seg[ind].xl << " " << seg[ind].xr << " " << l << " " << r << endl;
if(r < l or seg[ind].xr < l or seg[ind].xl > r) return;
push(ind);
if(seg[ind].xl >= l and seg[ind].xr <= r){
seg[ind].lazy = 1;
push(ind);
// cout << ind << " " << seg[ind].xl << " " << seg[ind].xr << " " << l << " " << r << " " << seg[ind].val << endl;
return;
}
neww(ind);
int mid = (seg[ind].xl+seg[ind].xr)/2;
upd(seg[ind].l,l,r);
upd(seg[ind].r,l,r);
push(seg[ind].l);
push(seg[ind].r);
seg[ind].val = seg[seg[ind].l].val+seg[seg[ind].r].val;
// cout << ind << " " << seg[ind].xl << " " << seg[ind].xr << " " << l << " " << r << " " << seg[ind].val << endl;
}
int quer(int ind,int l,int r){
// cout << ind << " " << seg[ind].xl << " " << seg[ind].xr << " " << l << " " << r << endl;
if(r < l or seg[ind].xr < l or seg[ind].xl > r) return 0;
push(ind);
if(seg[ind].xl >= l and seg[ind].xr <= r){
// cout << ind << " " << seg[ind].xl << " " << seg[ind].xr << " " << l << " " << r << " " << seg[ind].val << endl;
return seg[ind].val;
}
neww(ind);
int mid = (seg[ind].xl+seg[ind].xr)/2;
int ans = quer(seg[ind].l,l,r)+quer(seg[ind].r,l,r);
// cout << ind << " " << seg[ind].xl << " " << seg[ind].xr << " " << l << " " << r << " " << ans << endl;
return ans;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m,c = 0;
cin >> m;
seg[1] = {-1,-1,1,INF,0,0};
WL(m){
int d,x,y; cin >> d >> x >> y;
x += c;
y += c;
// cout << d << " " << x << " " << y << endl;
if(d == 1){
c = quer(1,x,y);
cout << c << endl;
}
else{
upd(1,x,y);
}
// cout << SZ << " ----------------------------\n";
// FOR(i,1,11){
// // int l,r,xl,xr,val,lazy;
// node P = seg[i];
// cout << P.l << " " << P.r << " " << P.xl << " " << P.xr << " " << P.val << " " << P.lazy << endl;
// }
}
}
Compilation message
apple.cpp: In function 'void upd(int, int, int)':
apple.cpp:100:6: warning: unused variable 'mid' [-Wunused-variable]
int mid = (seg[ind].xl+seg[ind].xr)/2;
^
apple.cpp: In function 'int quer(int, int, int)':
apple.cpp:118:6: warning: unused variable 'mid' [-Wunused-variable]
int mid = (seg[ind].xl+seg[ind].xr)/2;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
236548 KB |
Output is correct |
2 |
Correct |
0 ms |
236548 KB |
Output is correct |
3 |
Correct |
0 ms |
236548 KB |
Output is correct |
4 |
Correct |
36 ms |
236548 KB |
Output is correct |
5 |
Correct |
26 ms |
236548 KB |
Output is correct |
6 |
Correct |
56 ms |
236548 KB |
Output is correct |
7 |
Correct |
19 ms |
236548 KB |
Output is correct |
8 |
Correct |
353 ms |
236548 KB |
Output is correct |
9 |
Runtime error |
706 ms |
236548 KB |
Execution timed out (wall clock limit exceeded) |
10 |
Halted |
0 ms |
0 KB |
- |