#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using pll=array<ll,2>;
const ll inf=1e18;
const int N=2e5+5;
int n,q;
ll a[N],cnt[N],sum;
struct ST{
ll T[2*N]={0},S[2*N]={0};
void upd(int nd,int l,int r,int x,int v){
if(l==r){
S[nd]+=v;
T[nd]=min(0ll,S[nd]);
return;
}
int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
if(x<=m) upd(ln,l,m,x,v);
else upd(rn,m+1,r,x,v);
T[nd]=min(T[ln],S[ln]+T[rn]);
S[nd]=S[ln]+S[rn];
}
}T;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i]/2;
T.upd(1,1,n,i,a[i]%2);
T.upd(1,1,n,min(n,2*i-1),-(a[i]/2));
}
for(int i,c,t=1;t<=q;t++){
cin>>i>>c;
sum-=a[i]/2;
T.upd(1,1,n,i,-(a[i]%2));
T.upd(1,1,n,min(n,2*i-1),(a[i]/2));
a[i]+=c;
sum+=a[i]/2;
T.upd(1,1,n,i,(a[i]%2));
T.upd(1,1,n,min(n,2*i-1),-(a[i]/2));
if(T.T[1]>=0) cout<<sum<<"\n";
else cout<<sum-(-T.T[1]+2)/3<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
42 ms |
672 KB |
Output is correct |
4 |
Correct |
162 ms |
9388 KB |
Output is correct |
5 |
Correct |
164 ms |
9512 KB |
Output is correct |
6 |
Correct |
161 ms |
9472 KB |
Output is correct |
7 |
Correct |
155 ms |
9420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
154 ms |
9624 KB |
Output is correct |
6 |
Correct |
178 ms |
11332 KB |
Output is correct |
7 |
Correct |
176 ms |
11340 KB |
Output is correct |
8 |
Correct |
174 ms |
11428 KB |
Output is correct |
9 |
Correct |
178 ms |
11308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
42 ms |
672 KB |
Output is correct |
32 |
Correct |
162 ms |
9388 KB |
Output is correct |
33 |
Correct |
164 ms |
9512 KB |
Output is correct |
34 |
Correct |
161 ms |
9472 KB |
Output is correct |
35 |
Correct |
155 ms |
9420 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
154 ms |
9624 KB |
Output is correct |
41 |
Correct |
178 ms |
11332 KB |
Output is correct |
42 |
Correct |
176 ms |
11340 KB |
Output is correct |
43 |
Correct |
174 ms |
11428 KB |
Output is correct |
44 |
Correct |
178 ms |
11308 KB |
Output is correct |
45 |
Correct |
192 ms |
11372 KB |
Output is correct |
46 |
Correct |
168 ms |
11340 KB |
Output is correct |
47 |
Correct |
177 ms |
11340 KB |
Output is correct |
48 |
Correct |
161 ms |
9588 KB |
Output is correct |
49 |
Correct |
170 ms |
11356 KB |
Output is correct |
50 |
Correct |
160 ms |
10044 KB |
Output is correct |
51 |
Correct |
124 ms |
10088 KB |
Output is correct |
52 |
Correct |
175 ms |
11412 KB |
Output is correct |
53 |
Correct |
119 ms |
9496 KB |
Output is correct |
54 |
Correct |
153 ms |
9540 KB |
Output is correct |