#include <bits/stdc++.h>
#define Tree int &h,int l,int r
#define Left v[h][1],l,(l+r)/2
#define Right v[h][2],(l+r)/2+1,r
using namespace std;
const int N=5000006;
int nodes=1,n,L,R,ANS,Root,type;
int v[2*N][5];
inline void Shift(int h,int l,int r) {
if (!v[h][4]) return ;
v[h][0]=r-l+1;
if (l!=r) {
if (!v[h][1]) v[h][1]=++nodes;
if (!v[h][2]) v[h][2]=++nodes;
v[v[h][1]][4]=1,v[v[h][2]][4]=1;
}
v[h][4]=0;
}
inline int Get (Tree) {
if (!h) h=++nodes;
Shift(h,l,r);
if (r<L || R<l) return 0;
if (L<=l && r<=R) return v[h][0];
return Get(Left)+Get(Right);
}
inline void Upd (Tree) {
if (!h) h=++nodes;
Shift(h,l,r);
if (r<L || R<l) return ;
if (L<=l && r<=R) { v[h][4]=1; Shift(h,l,r); return ; }
Upd(Left),Upd(Right);
v[h][0]=v[v[h][1]][0]+v[v[h][2]][0];
}
main () {
scanf("%d",&n);
for (int i=1; i<=n; i++) {
scanf("%d %d %d",&type,&L,&R);
L+=ANS,R+=ANS,Root=1;
if (type==1) {
ANS=Get(Root,1,1e9);
printf("%d\n",ANS);
}
else Upd(Root,1,1e9);
}
}
Compilation message
apple.cpp:37:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
apple.cpp: In function 'int main()':
apple.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
apple.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&type,&L,&R);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
20 ms |
3960 KB |
Output is correct |
5 |
Correct |
24 ms |
4728 KB |
Output is correct |
6 |
Correct |
24 ms |
4600 KB |
Output is correct |
7 |
Correct |
24 ms |
4728 KB |
Output is correct |
8 |
Correct |
171 ms |
33400 KB |
Output is correct |
9 |
Correct |
353 ms |
56952 KB |
Output is correct |
10 |
Correct |
354 ms |
63544 KB |
Output is correct |
11 |
Correct |
369 ms |
68732 KB |
Output is correct |
12 |
Correct |
384 ms |
71172 KB |
Output is correct |
13 |
Correct |
345 ms |
88268 KB |
Output is correct |
14 |
Correct |
348 ms |
88952 KB |
Output is correct |
15 |
Correct |
516 ms |
160600 KB |
Output is correct |
16 |
Correct |
509 ms |
161708 KB |
Output is correct |
17 |
Correct |
357 ms |
92024 KB |
Output is correct |
18 |
Correct |
359 ms |
92216 KB |
Output is correct |
19 |
Correct |
518 ms |
165380 KB |
Output is correct |
20 |
Correct |
537 ms |
165496 KB |
Output is correct |