#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e18;
struct T{
int mx[2][2];
T(){memset(mx,0,sizeof(mx));}
}st[4000001];
int lazy[4000001],lazy2[4000001],cnt[4000001];
int q,l,t[500001],x[500001],a[500001],s;
vector <int> ve;
T f(T a, T b, int cnt){
T c;
for (int i=0;i<2;i++)
for (int j=0;j<2;j++)
c.mx[i][j]=max(a.mx[i][0]+b.mx[0][j],a.mx[i][1]+b.mx[1][j]-cnt);
for (int i=0;i<2;i++){
c.mx[i][0]=max(c.mx[i][0],a.mx[i][0]);
c.mx[0][i]=max(c.mx[0][i],b.mx[0][i]);
}
return c;
}
void down(int node, int l, int r){
if (l==r)
return;
for (int i=0;i<2;i++)
for (int j=0;j<2;j++){
st[node<<1].mx[i][j]+=lazy[node];
st[node<<1|1].mx[i][j]+=lazy[node];
}
lazy[node<<1]+=lazy[node];
lazy[node<<1|1]+=lazy[node];
lazy[node]=0;
cnt[node<<1]+=lazy2[node];
cnt[node<<1|1]+=lazy2[node];
lazy2[node<<1]+=lazy2[node];
lazy2[node<<1|1]+=lazy2[node];
lazy2[node]=0;
}
void update(int node, int l, int r, int u, int v, int val){
if (l>v||r<u||l>r)
return;
if (l>=u&&r<=v){
for (int i=0;i<2;i++)
for (int j=0;j<2;j++)
st[node].mx[i][j]+=val;
lazy[node]+=val;
cnt[node]+=val;
lazy2[node]+=val;
return;
}
down(node,l,r);
int mid=(l+r)>>1;
if (mid>=u&&mid<v)
cnt[node]+=val;
update(node<<1,l,mid,u,v,val);
update(node<<1|1,mid+1,r,u,v,val);
st[node]=f(st[node<<1],st[node<<1|1],cnt[node]);
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> q >> l;
for (int i=0;i<q;i++){
cin >> t[i] >> x[i] >> a[i];
if (t[i]==1)
ve.push_back(x[i]);
else{
ve.push_back(x[i]-l);
ve.push_back(x[i]+l);
}
}
sort(ve.begin(),ve.end());
ve.resize(unique(ve.begin(),ve.end())-ve.begin());
for (int i=0;i<q;i++){
if (t[i]==1){
s+=a[i];
int pos=lower_bound(ve.begin(),ve.end(),x[i])-ve.begin();
update(1,0,ve.size()-1,pos,pos,a[i]);
}
else{
int u=lower_bound(ve.begin(),ve.end(),x[i]-l)-ve.begin();
int v=lower_bound(ve.begin(),ve.end(),x[i]+l)-ve.begin();
update(1,0,ve.size()-1,u,v,-a[i]);
}
cout << s-max(st[1].mx[0][0],0LL) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
132700 KB |
Output is correct |
2 |
Correct |
16 ms |
132696 KB |
Output is correct |
3 |
Correct |
16 ms |
132700 KB |
Output is correct |
4 |
Correct |
19 ms |
132972 KB |
Output is correct |
5 |
Correct |
18 ms |
136792 KB |
Output is correct |
6 |
Correct |
18 ms |
132700 KB |
Output is correct |
7 |
Correct |
18 ms |
132700 KB |
Output is correct |
8 |
Correct |
17 ms |
132696 KB |
Output is correct |
9 |
Correct |
18 ms |
132660 KB |
Output is correct |
10 |
Correct |
19 ms |
132952 KB |
Output is correct |
11 |
Correct |
19 ms |
132956 KB |
Output is correct |
12 |
Correct |
20 ms |
133124 KB |
Output is correct |
13 |
Correct |
19 ms |
133212 KB |
Output is correct |
14 |
Correct |
20 ms |
132976 KB |
Output is correct |
15 |
Correct |
20 ms |
133212 KB |
Output is correct |
16 |
Correct |
22 ms |
133012 KB |
Output is correct |
17 |
Correct |
18 ms |
132932 KB |
Output is correct |
18 |
Correct |
19 ms |
132956 KB |
Output is correct |
19 |
Correct |
20 ms |
132952 KB |
Output is correct |
20 |
Correct |
19 ms |
132952 KB |
Output is correct |
21 |
Correct |
19 ms |
133212 KB |
Output is correct |
22 |
Correct |
20 ms |
132968 KB |
Output is correct |
23 |
Correct |
20 ms |
133036 KB |
Output is correct |
24 |
Correct |
19 ms |
133152 KB |
Output is correct |
25 |
Correct |
19 ms |
133128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
132696 KB |
Output is correct |
2 |
Correct |
17 ms |
132700 KB |
Output is correct |
3 |
Correct |
17 ms |
136792 KB |
Output is correct |
4 |
Correct |
499 ms |
164416 KB |
Output is correct |
5 |
Correct |
232 ms |
157888 KB |
Output is correct |
6 |
Correct |
596 ms |
173772 KB |
Output is correct |
7 |
Correct |
230 ms |
159016 KB |
Output is correct |
8 |
Correct |
742 ms |
177156 KB |
Output is correct |
9 |
Correct |
467 ms |
176628 KB |
Output is correct |
10 |
Correct |
754 ms |
177076 KB |
Output is correct |
11 |
Correct |
463 ms |
176456 KB |
Output is correct |
12 |
Correct |
206 ms |
156400 KB |
Output is correct |
13 |
Correct |
286 ms |
165380 KB |
Output is correct |
14 |
Correct |
481 ms |
173164 KB |
Output is correct |
15 |
Correct |
454 ms |
171812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
132688 KB |
Output is correct |
2 |
Correct |
212 ms |
154196 KB |
Output is correct |
3 |
Correct |
311 ms |
165108 KB |
Output is correct |
4 |
Correct |
488 ms |
174772 KB |
Output is correct |
5 |
Correct |
454 ms |
173240 KB |
Output is correct |
6 |
Correct |
666 ms |
180584 KB |
Output is correct |
7 |
Correct |
50 ms |
141468 KB |
Output is correct |
8 |
Correct |
296 ms |
162184 KB |
Output is correct |
9 |
Correct |
500 ms |
177276 KB |
Output is correct |
10 |
Correct |
973 ms |
208316 KB |
Output is correct |
11 |
Correct |
960 ms |
209388 KB |
Output is correct |
12 |
Correct |
993 ms |
209564 KB |
Output is correct |
13 |
Correct |
1055 ms |
209824 KB |
Output is correct |
14 |
Correct |
1062 ms |
209572 KB |
Output is correct |
15 |
Correct |
941 ms |
208316 KB |
Output is correct |
16 |
Correct |
1006 ms |
209396 KB |
Output is correct |
17 |
Correct |
1055 ms |
209064 KB |
Output is correct |
18 |
Correct |
1108 ms |
208776 KB |
Output is correct |
19 |
Correct |
1120 ms |
209360 KB |
Output is correct |
20 |
Correct |
1124 ms |
209420 KB |
Output is correct |
21 |
Correct |
1167 ms |
209336 KB |
Output is correct |
22 |
Correct |
1178 ms |
210096 KB |
Output is correct |
23 |
Correct |
1210 ms |
209796 KB |
Output is correct |
24 |
Correct |
1085 ms |
208816 KB |
Output is correct |
25 |
Correct |
1170 ms |
211664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
132700 KB |
Output is correct |
2 |
Correct |
16 ms |
132696 KB |
Output is correct |
3 |
Correct |
16 ms |
132700 KB |
Output is correct |
4 |
Correct |
19 ms |
132972 KB |
Output is correct |
5 |
Correct |
18 ms |
136792 KB |
Output is correct |
6 |
Correct |
18 ms |
132700 KB |
Output is correct |
7 |
Correct |
18 ms |
132700 KB |
Output is correct |
8 |
Correct |
17 ms |
132696 KB |
Output is correct |
9 |
Correct |
18 ms |
132660 KB |
Output is correct |
10 |
Correct |
19 ms |
132952 KB |
Output is correct |
11 |
Correct |
19 ms |
132956 KB |
Output is correct |
12 |
Correct |
20 ms |
133124 KB |
Output is correct |
13 |
Correct |
19 ms |
133212 KB |
Output is correct |
14 |
Correct |
20 ms |
132976 KB |
Output is correct |
15 |
Correct |
20 ms |
133212 KB |
Output is correct |
16 |
Correct |
22 ms |
133012 KB |
Output is correct |
17 |
Correct |
18 ms |
132932 KB |
Output is correct |
18 |
Correct |
19 ms |
132956 KB |
Output is correct |
19 |
Correct |
20 ms |
132952 KB |
Output is correct |
20 |
Correct |
19 ms |
132952 KB |
Output is correct |
21 |
Correct |
19 ms |
133212 KB |
Output is correct |
22 |
Correct |
20 ms |
132968 KB |
Output is correct |
23 |
Correct |
20 ms |
133036 KB |
Output is correct |
24 |
Correct |
19 ms |
133152 KB |
Output is correct |
25 |
Correct |
19 ms |
133128 KB |
Output is correct |
26 |
Correct |
16 ms |
132696 KB |
Output is correct |
27 |
Correct |
17 ms |
132700 KB |
Output is correct |
28 |
Correct |
17 ms |
136792 KB |
Output is correct |
29 |
Correct |
499 ms |
164416 KB |
Output is correct |
30 |
Correct |
232 ms |
157888 KB |
Output is correct |
31 |
Correct |
596 ms |
173772 KB |
Output is correct |
32 |
Correct |
230 ms |
159016 KB |
Output is correct |
33 |
Correct |
742 ms |
177156 KB |
Output is correct |
34 |
Correct |
467 ms |
176628 KB |
Output is correct |
35 |
Correct |
754 ms |
177076 KB |
Output is correct |
36 |
Correct |
463 ms |
176456 KB |
Output is correct |
37 |
Correct |
206 ms |
156400 KB |
Output is correct |
38 |
Correct |
286 ms |
165380 KB |
Output is correct |
39 |
Correct |
481 ms |
173164 KB |
Output is correct |
40 |
Correct |
454 ms |
171812 KB |
Output is correct |
41 |
Correct |
21 ms |
132688 KB |
Output is correct |
42 |
Correct |
212 ms |
154196 KB |
Output is correct |
43 |
Correct |
311 ms |
165108 KB |
Output is correct |
44 |
Correct |
488 ms |
174772 KB |
Output is correct |
45 |
Correct |
454 ms |
173240 KB |
Output is correct |
46 |
Correct |
666 ms |
180584 KB |
Output is correct |
47 |
Correct |
50 ms |
141468 KB |
Output is correct |
48 |
Correct |
296 ms |
162184 KB |
Output is correct |
49 |
Correct |
500 ms |
177276 KB |
Output is correct |
50 |
Correct |
973 ms |
208316 KB |
Output is correct |
51 |
Correct |
960 ms |
209388 KB |
Output is correct |
52 |
Correct |
993 ms |
209564 KB |
Output is correct |
53 |
Correct |
1055 ms |
209824 KB |
Output is correct |
54 |
Correct |
1062 ms |
209572 KB |
Output is correct |
55 |
Correct |
941 ms |
208316 KB |
Output is correct |
56 |
Correct |
1006 ms |
209396 KB |
Output is correct |
57 |
Correct |
1055 ms |
209064 KB |
Output is correct |
58 |
Correct |
1108 ms |
208776 KB |
Output is correct |
59 |
Correct |
1120 ms |
209360 KB |
Output is correct |
60 |
Correct |
1124 ms |
209420 KB |
Output is correct |
61 |
Correct |
1167 ms |
209336 KB |
Output is correct |
62 |
Correct |
1178 ms |
210096 KB |
Output is correct |
63 |
Correct |
1210 ms |
209796 KB |
Output is correct |
64 |
Correct |
1085 ms |
208816 KB |
Output is correct |
65 |
Correct |
1170 ms |
211664 KB |
Output is correct |
66 |
Correct |
455 ms |
178936 KB |
Output is correct |
67 |
Correct |
549 ms |
181064 KB |
Output is correct |
68 |
Correct |
789 ms |
185040 KB |
Output is correct |
69 |
Correct |
603 ms |
182532 KB |
Output is correct |
70 |
Correct |
970 ms |
214956 KB |
Output is correct |
71 |
Correct |
945 ms |
215948 KB |
Output is correct |
72 |
Correct |
978 ms |
215740 KB |
Output is correct |
73 |
Correct |
988 ms |
215544 KB |
Output is correct |
74 |
Correct |
1074 ms |
209732 KB |
Output is correct |
75 |
Correct |
1076 ms |
215312 KB |
Output is correct |
76 |
Correct |
796 ms |
186908 KB |
Output is correct |
77 |
Correct |
780 ms |
181072 KB |
Output is correct |
78 |
Correct |
821 ms |
181244 KB |
Output is correct |
79 |
Correct |
1039 ms |
214744 KB |
Output is correct |
80 |
Correct |
787 ms |
181184 KB |
Output is correct |
81 |
Correct |
999 ms |
215464 KB |
Output is correct |
82 |
Correct |
832 ms |
181456 KB |
Output is correct |
83 |
Correct |
1192 ms |
212628 KB |
Output is correct |
84 |
Correct |
843 ms |
181180 KB |
Output is correct |
85 |
Correct |
1248 ms |
215284 KB |
Output is correct |
86 |
Correct |
865 ms |
181208 KB |
Output is correct |
87 |
Correct |
1176 ms |
214708 KB |
Output is correct |
88 |
Correct |
860 ms |
181204 KB |
Output is correct |
89 |
Correct |
1012 ms |
215608 KB |
Output is correct |