#include <cstdio>
const int N = 1e5, M = 1e9;
int L, R, l[N<<2], r[N<<2], s[N<<2], lz[N<<2], ALLOC = 2;
void pg(int ind, int low, int high){
if(low != high){
if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
lz[l[ind]] = lz[r[ind]] = lz[ind];
}
lz[ind] = 0;
}
void upd(int ind, int low, int high){
if(lz[ind]){s[ind] = high-low+1; pg(ind, low, high); }
if(low > R || high < L) return;
if(L <= low && high <= R){s[ind] = high-low+1; lz[ind] = true; pg(ind, low, high); return;}
if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
int mid = low + ((high-low)>>1);
upd(l[ind], low, mid); upd(r[ind], mid+1, high);
s[ind] = ((l[ind])? s[l[ind]] : 0) + ((r[ind])? s[r[ind]] : 0);
}
int qry(int ind, int low, int high){
if(lz[ind]){s[ind] = high-low+1; pg(ind, low, high);}
if(low > R || high < L) return 0;
if(L <= low && high <= R) return s[ind];
int mid = low + ((high-low)>>1);
return ((l[ind])? qry(l[ind], low, mid) : 0) + ((r[ind])? qry(r[ind], mid+1, high) : 0);
}
signed main(){
int m, c = 0, d; scanf("%d", &m);
while(m--){
scanf("%d %d %d", &d, &L, &R); L += c; R += c;
if(d == 1) printf("%d\n", c = qry(1, 1, M));
else upd(1, 1, M);
}
}
Compilation message
apple.cpp: In function 'void pg(int, int, int)':
apple.cpp:6:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
6 | if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
| ^~
apple.cpp:6:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
6 | if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
| ^~
apple.cpp: In function 'void upd(int, int, int)':
apple.cpp:15:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
15 | if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
| ^~
apple.cpp:15:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
15 | if(!l[ind]) l[ind] = ALLOC++; if(!r[ind]) r[ind] = ALLOC++;
| ^~
apple.cpp: In function 'int main()':
apple.cpp:28:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | int m, c = 0, d; scanf("%d", &m);
| ~~~~~^~~~~~~~~~
apple.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d %d %d", &d, &L, &R); L += c; R += c;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
8 ms |
3256 KB |
Output is correct |
5 |
Correct |
10 ms |
3932 KB |
Output is correct |
6 |
Correct |
10 ms |
3676 KB |
Output is correct |
7 |
Correct |
9 ms |
3932 KB |
Output is correct |
8 |
Runtime error |
15 ms |
13404 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |