#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()
const int max_q = 200010, max_n2 = 524288;
int n;
int q;
int qx[max_q];
int qd[max_q];
int ql[max_q];
ll lx[max_n2];
ll ly[max_n2];
ll x[max_n2];
ll y[max_n2];
inline void col(int p){ x[p]=x[p*2+1]; y[p]=y[p*2]; }
inline void acq(int p, ll vx, ll vy){ x[p] += vx; lx[p] += vx; y[p] += vy; ly[p] += vy; }
void init(int p=1, int pl=1, int pr=n){
if(pl == pr){
x[p]=pl-1; y[p]=-pl; return;
}
int mid = (pl+pr)/2;
init(p*2, pl, mid); init(p*2+1, mid+1, pr); col(p);
}
void pd(int p){
acq(p*2, lx[p], ly[p]);
acq(p*2+1, lx[p], ly[p]);
lx[p] = 0; ly[p] = 0;
}
void upd(ll vx, ll vy, int l, int r, int p=1, int pl=1, int pr=n){
if(pl!=pr) pd(p);
if(r<pl || pr<l) return;
if(l<=pl && pr<=r){
acq(p, vx, vy); return;
}
int mid = (pl+pr)/2;
upd(vx, vy, l, r, p*2, pl, mid);
upd(vx, vy, l, r, p*2+1, mid+1, pr);
col(p);
}
void dfs(int p=1, int pl=1, int pr=n){
if(pl == pr){
printf("%lld\n", -(x[p]+y[p])/2);
return;
}
pd(p);
int mid=(pl+pr)/2;
dfs(p*2, pl, mid); dfs(p*2+1, mid+1, pr);
}
int main()
{
read(n, q);
rep(i, q) read(qx[i], qd[i], ql[i]);
init();
for(int i=q-1; 0<=i; --i){
if(qd[i] == 1){
ll v=-qx[i];
if(v > y[1]) continue;
int p=1, pl=1, pr=n;
while(pl != pr){
pd(p);
int mid = (pl+pr)/2;
if(y[p*2+1] >= v) p=p*2+1, pl=mid+1;
else p=p*2, pr=mid;
}
upd(-2*ql[i], 0, 1, pl);
} else {
ll v=qx[i];
if(x[1] < v) continue;
int p=1, pl=1, pr=n;
while(pl != pr){
pd(p);
int mid = (pl+pr)/2;
if(x[p*2]<v) p=p*2+1, pl=mid+1;
else p=p*2, pr=mid;
}
upd(0, -2*ql[i], pl, n);
}
}
dfs();
return 0;
}
Compilation message
2016_ho_t5.cpp: In function 'void read(int&)':
2016_ho_t5.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
6 | void read(int& x){ scanf("%d",&x); }
| ~~~~~^~~~~~~~~
2016_ho_t5.cpp: In function 'void read(ll&)':
2016_ho_t5.cpp:7:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
7 | void read(ll& x){ scanf("%lld",&x); }
| ~~~~~^~~~~~~~~~~
2016_ho_t5.cpp: In function 'void read(pp&)':
2016_ho_t5.cpp:8:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
8 | void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t5.cpp: In function 'void read(pll&)':
2016_ho_t5.cpp:9:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
9 | void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
380 KB |
Output is correct |
23 |
Correct |
1 ms |
380 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
380 KB |
Output is correct |
23 |
Correct |
1 ms |
380 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
3 ms |
768 KB |
Output is correct |
30 |
Correct |
3 ms |
768 KB |
Output is correct |
31 |
Correct |
3 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
33 |
Correct |
3 ms |
768 KB |
Output is correct |
34 |
Correct |
3 ms |
744 KB |
Output is correct |
35 |
Correct |
3 ms |
768 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
39 |
Correct |
3 ms |
768 KB |
Output is correct |
40 |
Correct |
5 ms |
768 KB |
Output is correct |
41 |
Correct |
3 ms |
768 KB |
Output is correct |
42 |
Correct |
3 ms |
768 KB |
Output is correct |
43 |
Correct |
3 ms |
768 KB |
Output is correct |
44 |
Correct |
3 ms |
768 KB |
Output is correct |
45 |
Correct |
5 ms |
768 KB |
Output is correct |
46 |
Correct |
3 ms |
768 KB |
Output is correct |
47 |
Correct |
4 ms |
768 KB |
Output is correct |
48 |
Correct |
4 ms |
792 KB |
Output is correct |
49 |
Correct |
4 ms |
768 KB |
Output is correct |
50 |
Correct |
4 ms |
768 KB |
Output is correct |
51 |
Correct |
4 ms |
768 KB |
Output is correct |
52 |
Correct |
5 ms |
748 KB |
Output is correct |
53 |
Correct |
4 ms |
768 KB |
Output is correct |
54 |
Correct |
7 ms |
696 KB |
Output is correct |
55 |
Correct |
5 ms |
768 KB |
Output is correct |
56 |
Correct |
5 ms |
708 KB |
Output is correct |
57 |
Correct |
5 ms |
740 KB |
Output is correct |
58 |
Correct |
7 ms |
768 KB |
Output is correct |
59 |
Correct |
4 ms |
768 KB |
Output is correct |
60 |
Correct |
5 ms |
768 KB |
Output is correct |
61 |
Correct |
5 ms |
768 KB |
Output is correct |
62 |
Correct |
3 ms |
768 KB |
Output is correct |
63 |
Correct |
4 ms |
768 KB |
Output is correct |
64 |
Correct |
4 ms |
768 KB |
Output is correct |
65 |
Correct |
3 ms |
768 KB |
Output is correct |
66 |
Correct |
6 ms |
768 KB |
Output is correct |
67 |
Correct |
5 ms |
656 KB |
Output is correct |
68 |
Correct |
5 ms |
768 KB |
Output is correct |
69 |
Correct |
4 ms |
768 KB |
Output is correct |
70 |
Correct |
1 ms |
640 KB |
Output is correct |
71 |
Correct |
2 ms |
640 KB |
Output is correct |
72 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
380 KB |
Output is correct |
23 |
Correct |
1 ms |
380 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
3 ms |
768 KB |
Output is correct |
30 |
Correct |
3 ms |
768 KB |
Output is correct |
31 |
Correct |
3 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
33 |
Correct |
3 ms |
768 KB |
Output is correct |
34 |
Correct |
3 ms |
744 KB |
Output is correct |
35 |
Correct |
3 ms |
768 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
39 |
Correct |
3 ms |
768 KB |
Output is correct |
40 |
Correct |
5 ms |
768 KB |
Output is correct |
41 |
Correct |
3 ms |
768 KB |
Output is correct |
42 |
Correct |
3 ms |
768 KB |
Output is correct |
43 |
Correct |
3 ms |
768 KB |
Output is correct |
44 |
Correct |
3 ms |
768 KB |
Output is correct |
45 |
Correct |
5 ms |
768 KB |
Output is correct |
46 |
Correct |
3 ms |
768 KB |
Output is correct |
47 |
Correct |
4 ms |
768 KB |
Output is correct |
48 |
Correct |
4 ms |
792 KB |
Output is correct |
49 |
Correct |
4 ms |
768 KB |
Output is correct |
50 |
Correct |
4 ms |
768 KB |
Output is correct |
51 |
Correct |
4 ms |
768 KB |
Output is correct |
52 |
Correct |
5 ms |
748 KB |
Output is correct |
53 |
Correct |
4 ms |
768 KB |
Output is correct |
54 |
Correct |
7 ms |
696 KB |
Output is correct |
55 |
Correct |
5 ms |
768 KB |
Output is correct |
56 |
Correct |
5 ms |
708 KB |
Output is correct |
57 |
Correct |
5 ms |
740 KB |
Output is correct |
58 |
Correct |
7 ms |
768 KB |
Output is correct |
59 |
Correct |
4 ms |
768 KB |
Output is correct |
60 |
Correct |
5 ms |
768 KB |
Output is correct |
61 |
Correct |
5 ms |
768 KB |
Output is correct |
62 |
Correct |
3 ms |
768 KB |
Output is correct |
63 |
Correct |
4 ms |
768 KB |
Output is correct |
64 |
Correct |
4 ms |
768 KB |
Output is correct |
65 |
Correct |
3 ms |
768 KB |
Output is correct |
66 |
Correct |
6 ms |
768 KB |
Output is correct |
67 |
Correct |
5 ms |
656 KB |
Output is correct |
68 |
Correct |
5 ms |
768 KB |
Output is correct |
69 |
Correct |
4 ms |
768 KB |
Output is correct |
70 |
Correct |
1 ms |
640 KB |
Output is correct |
71 |
Correct |
2 ms |
640 KB |
Output is correct |
72 |
Correct |
2 ms |
640 KB |
Output is correct |
73 |
Correct |
303 ms |
22392 KB |
Output is correct |
74 |
Correct |
318 ms |
22440 KB |
Output is correct |
75 |
Correct |
307 ms |
22688 KB |
Output is correct |
76 |
Correct |
322 ms |
22768 KB |
Output is correct |
77 |
Correct |
278 ms |
22680 KB |
Output is correct |
78 |
Correct |
295 ms |
22688 KB |
Output is correct |
79 |
Correct |
285 ms |
22688 KB |
Output is correct |
80 |
Correct |
237 ms |
22928 KB |
Output is correct |
81 |
Correct |
236 ms |
23196 KB |
Output is correct |
82 |
Correct |
225 ms |
23288 KB |
Output is correct |
83 |
Correct |
262 ms |
23952 KB |
Output is correct |
84 |
Correct |
232 ms |
24056 KB |
Output is correct |
85 |
Correct |
241 ms |
24092 KB |
Output is correct |
86 |
Correct |
190 ms |
24684 KB |
Output is correct |
87 |
Correct |
175 ms |
25208 KB |
Output is correct |
88 |
Correct |
204 ms |
26360 KB |
Output is correct |
89 |
Correct |
219 ms |
26404 KB |
Output is correct |
90 |
Correct |
457 ms |
24824 KB |
Output is correct |
91 |
Correct |
409 ms |
21496 KB |
Output is correct |
92 |
Correct |
474 ms |
21880 KB |
Output is correct |
93 |
Correct |
302 ms |
25080 KB |
Output is correct |
94 |
Correct |
277 ms |
22524 KB |
Output is correct |
95 |
Correct |
291 ms |
24440 KB |
Output is correct |
96 |
Correct |
273 ms |
22604 KB |
Output is correct |
97 |
Correct |
294 ms |
23544 KB |
Output is correct |
98 |
Correct |
283 ms |
22392 KB |
Output is correct |
99 |
Correct |
294 ms |
24180 KB |
Output is correct |
100 |
Correct |
278 ms |
22396 KB |
Output is correct |
101 |
Correct |
287 ms |
23636 KB |
Output is correct |
102 |
Correct |
279 ms |
22520 KB |
Output is correct |
103 |
Correct |
285 ms |
24440 KB |
Output is correct |
104 |
Correct |
272 ms |
22264 KB |
Output is correct |
105 |
Correct |
393 ms |
23928 KB |
Output is correct |
106 |
Correct |
267 ms |
22520 KB |
Output is correct |
107 |
Correct |
215 ms |
24240 KB |
Output is correct |
108 |
Correct |
285 ms |
22392 KB |
Output is correct |
109 |
Correct |
303 ms |
23928 KB |
Output is correct |
110 |
Correct |
295 ms |
22520 KB |
Output is correct |
111 |
Correct |
547 ms |
25596 KB |
Output is correct |
112 |
Correct |
502 ms |
22520 KB |
Output is correct |
113 |
Correct |
498 ms |
25720 KB |
Output is correct |
114 |
Correct |
407 ms |
22648 KB |
Output is correct |
115 |
Correct |
473 ms |
22904 KB |
Output is correct |
116 |
Correct |
421 ms |
22648 KB |
Output is correct |
117 |
Correct |
484 ms |
25848 KB |
Output is correct |
118 |
Correct |
426 ms |
22648 KB |
Output is correct |
119 |
Correct |
41 ms |
18936 KB |
Output is correct |
120 |
Correct |
35 ms |
17152 KB |
Output is correct |