#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e15;
void strat1(int q){
int l;
cin >> l;
vector<tuple<int,bool,int>> elements; // Sugar is false
auto solve = [&](){
int ans = 0;
queue<pair<int,int>> sugars;
sort(elements.begin(),elements.end());
for(auto[idx,type,amt]:elements){
if(type==false){sugars.emplace(idx,amt);continue;}
while(!sugars.empty() and sugars.front().first<idx-2*l)sugars.pop();
while(!sugars.empty()){
if(amt>=sugars.front().second){
amt-=sugars.front().second;
ans+=sugars.front().second;
sugars.pop();
} else {
ans+=amt;
sugars.front().second-=amt;
break;
}
}
}
return ans;
};
for(int i=1;i<=q;i++){
int type,x,a;cin>>type>>x>>a;
if(type==1){
elements.emplace_back(x+l,true,a);
} else {
elements.emplace_back(x,false,a);
}
cout << solve() << '\n';
}
exit(0);
}
struct node{
vector<vector<int>> DP;
int sugar;
node(int sugar=0,int ants=0):DP(2,vector<int>(2)),sugar(sugar){
DP[0][1]=DP[1][0]=-INF;
DP[1][1]=ants-sugar;
}
node(const node &a,const node &b):DP(2,vector<int>(2)),sugar(b.sugar){
for(int x=0;x<2;x++){
for(int y=0;y<2;y++){
DP[x][y]=max({a.DP[x][0]+b.DP[0][y],a.DP[x][1]+b.DP[1][y],a.DP[x][1]+b.DP[0][y],a.DP[x][0]+b.DP[1][y]-a.sugar});
}
}
}
};
struct segtree{
vector<node> tree;
segtree():tree(1048576){}
void update(int k,int s,int a){
k+=524288;
tree[k]={s,a};
while(k/=2){
tree[k]={tree[2*k],tree[2*k+1]};
}
}
};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
if(q<=3000)strat1(q);
vector<int> sugars(q+1);
vector<int> ants(q+1);
int antssum = 0;
int l;cin>>l;
segtree seg;
for(int i=1;i<=q;i++){
int t,x,a;cin>>t>>x>>a;x=(x+1ll)/2ll;
if(t==1){ants[x]+=a;antssum+=a;}
else sugars[x]+=a;
seg.update(x,sugars[x],ants[x]);
cout << antssum-max({seg.tree[1].DP[0][0],seg.tree[1].DP[0][1],seg.tree[1].DP[1][0],seg.tree[1].DP[1][1]}) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
81 ms |
584 KB |
Output is correct |
7 |
Correct |
62 ms |
564 KB |
Output is correct |
8 |
Correct |
14 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
520 KB |
Output is correct |
10 |
Correct |
157 ms |
596 KB |
Output is correct |
11 |
Correct |
167 ms |
600 KB |
Output is correct |
12 |
Correct |
161 ms |
604 KB |
Output is correct |
13 |
Correct |
161 ms |
612 KB |
Output is correct |
14 |
Correct |
148 ms |
568 KB |
Output is correct |
15 |
Correct |
156 ms |
604 KB |
Output is correct |
16 |
Correct |
144 ms |
588 KB |
Output is correct |
17 |
Correct |
151 ms |
660 KB |
Output is correct |
18 |
Correct |
147 ms |
604 KB |
Output is correct |
19 |
Correct |
165 ms |
604 KB |
Output is correct |
20 |
Correct |
148 ms |
596 KB |
Output is correct |
21 |
Correct |
167 ms |
600 KB |
Output is correct |
22 |
Correct |
151 ms |
596 KB |
Output is correct |
23 |
Correct |
177 ms |
596 KB |
Output is correct |
24 |
Correct |
147 ms |
600 KB |
Output is correct |
25 |
Correct |
176 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1999 ms |
175440 KB |
Output is correct |
5 |
Correct |
625 ms |
171836 KB |
Output is correct |
6 |
Correct |
2349 ms |
177232 KB |
Output is correct |
7 |
Correct |
617 ms |
171964 KB |
Output is correct |
8 |
Correct |
2798 ms |
179772 KB |
Output is correct |
9 |
Correct |
1062 ms |
180212 KB |
Output is correct |
10 |
Correct |
3668 ms |
179696 KB |
Output is correct |
11 |
Correct |
1055 ms |
180112 KB |
Output is correct |
12 |
Correct |
596 ms |
169812 KB |
Output is correct |
13 |
Correct |
771 ms |
171964 KB |
Output is correct |
14 |
Correct |
1151 ms |
176984 KB |
Output is correct |
15 |
Correct |
1090 ms |
179192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
581 ms |
173812 KB |
Output is correct |
3 |
Correct |
734 ms |
177572 KB |
Output is correct |
4 |
Correct |
1121 ms |
185936 KB |
Output is correct |
5 |
Correct |
1133 ms |
185936 KB |
Output is correct |
6 |
Incorrect |
2344 ms |
181608 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
81 ms |
584 KB |
Output is correct |
7 |
Correct |
62 ms |
564 KB |
Output is correct |
8 |
Correct |
14 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
520 KB |
Output is correct |
10 |
Correct |
157 ms |
596 KB |
Output is correct |
11 |
Correct |
167 ms |
600 KB |
Output is correct |
12 |
Correct |
161 ms |
604 KB |
Output is correct |
13 |
Correct |
161 ms |
612 KB |
Output is correct |
14 |
Correct |
148 ms |
568 KB |
Output is correct |
15 |
Correct |
156 ms |
604 KB |
Output is correct |
16 |
Correct |
144 ms |
588 KB |
Output is correct |
17 |
Correct |
151 ms |
660 KB |
Output is correct |
18 |
Correct |
147 ms |
604 KB |
Output is correct |
19 |
Correct |
165 ms |
604 KB |
Output is correct |
20 |
Correct |
148 ms |
596 KB |
Output is correct |
21 |
Correct |
167 ms |
600 KB |
Output is correct |
22 |
Correct |
151 ms |
596 KB |
Output is correct |
23 |
Correct |
177 ms |
596 KB |
Output is correct |
24 |
Correct |
147 ms |
600 KB |
Output is correct |
25 |
Correct |
176 ms |
624 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1999 ms |
175440 KB |
Output is correct |
30 |
Correct |
625 ms |
171836 KB |
Output is correct |
31 |
Correct |
2349 ms |
177232 KB |
Output is correct |
32 |
Correct |
617 ms |
171964 KB |
Output is correct |
33 |
Correct |
2798 ms |
179772 KB |
Output is correct |
34 |
Correct |
1062 ms |
180212 KB |
Output is correct |
35 |
Correct |
3668 ms |
179696 KB |
Output is correct |
36 |
Correct |
1055 ms |
180112 KB |
Output is correct |
37 |
Correct |
596 ms |
169812 KB |
Output is correct |
38 |
Correct |
771 ms |
171964 KB |
Output is correct |
39 |
Correct |
1151 ms |
176984 KB |
Output is correct |
40 |
Correct |
1090 ms |
179192 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
581 ms |
173812 KB |
Output is correct |
43 |
Correct |
734 ms |
177572 KB |
Output is correct |
44 |
Correct |
1121 ms |
185936 KB |
Output is correct |
45 |
Correct |
1133 ms |
185936 KB |
Output is correct |
46 |
Incorrect |
2344 ms |
181608 KB |
Output isn't correct |
47 |
Halted |
0 ms |
0 KB |
- |