#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct segTree{
struct Node{
ll done, prv, nxt;
Node(){}
Node(ll done, ll prv, ll nxt): done(done), prv(prv), nxt(nxt){}
Node operator+(const Node &r)const{
ll tmp = min(r.prv, nxt);
return Node(done+r.done+tmp, prv, r.nxt);
}
} tree[1000002];
void update(int i, int l, int r, int x, ll v){
if(l==r){
if(v>0) tree[i].prv+=v;
else tree[i].nxt-=v;
ll tmp = min(tree[i].prv, tree[i].nxt);
tree[i].prv -= tmp, tree[i].nxt -= tmp;
tree[i].done += tmp;
return;
}
int m = (l+r)>>1;
if(x<=m) update(i*2, l, m, x, v);
else update(i*2+1, m+1, r, x, v);
tree[i] = tree[i*2] + tree[i*2+1];
}
ll query(){
return tree[1].done;
}
} tree;
int q, l;
int main(){
int MAX = 250000;
scanf("%d %d", &q, &l);
for(int qc=1; qc<=q; qc++){
int t, x, y;
scanf("%d %d %d", &t, &x, &y);
x=(x+1)/2;
if(t==1) tree.update(1, 1, MAX, x, y);
else tree.update(1, 1, MAX, x, -y);
printf("%lld\n", tree.query());
}
}
Compilation message
sugar.cpp: In function 'int main()':
sugar.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d %d", &q, &l);
| ~~~~~^~~~~~~~~~~~~~~~~
sugar.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d %d %d", &t, &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Incorrect |
263 ms |
21120 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |