#include <cstdio>
const int N = 1e5 + 5, M = 1e9;
int L, R, l[16000400], r[16000400], s[16000400], lz[16000400], 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;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
8 ms |
5040 KB |
Output is correct |
5 |
Correct |
9 ms |
3676 KB |
Output is correct |
6 |
Correct |
10 ms |
5468 KB |
Output is correct |
7 |
Correct |
9 ms |
3672 KB |
Output is correct |
8 |
Correct |
72 ms |
28424 KB |
Output is correct |
9 |
Correct |
164 ms |
47868 KB |
Output is correct |
10 |
Correct |
175 ms |
53240 KB |
Output is correct |
11 |
Correct |
193 ms |
57428 KB |
Output is correct |
12 |
Correct |
167 ms |
59096 KB |
Output is correct |
13 |
Correct |
147 ms |
73044 KB |
Output is correct |
14 |
Correct |
155 ms |
73552 KB |
Output is correct |
15 |
Correct |
213 ms |
130640 KB |
Output is correct |
16 |
Correct |
225 ms |
131664 KB |
Output is correct |
17 |
Correct |
143 ms |
76120 KB |
Output is correct |
18 |
Correct |
145 ms |
76120 KB |
Output is correct |
19 |
Correct |
220 ms |
134756 KB |
Output is correct |
20 |
Correct |
215 ms |
134832 KB |
Output is correct |