#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];
void solve(){
ll ret=0,cur=0;
for(int i=1;i<=n;i++) cnt[i]=0;
for(int i=1;i<=n;i++) cnt[min(n,2*i-1)]+=a[i]/2;
for(int i=1;i<=n;i++){
if(a[i]&1) cur++;
// cur + 2 * d >= cnt[i] - d
// d >= (cnt [i] - cur) / 3
if(cur<cnt[i]){
ll d=(cnt[i]-cur+2)/3;
cnt[i]-=d;
cur+=2*d;
}
ret+=cnt[i];
cur-=cnt[i];
}
cout<<ret<<"\n";
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i,c,T=1;T<=q;T++){
cin>>i>>c;
a[i]+=c;
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
11 ms |
340 KB |
Output is correct |
7 |
Correct |
11 ms |
364 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
368 KB |
Output is correct |
10 |
Correct |
11 ms |
368 KB |
Output is correct |
11 |
Correct |
11 ms |
372 KB |
Output is correct |
12 |
Correct |
11 ms |
340 KB |
Output is correct |
13 |
Correct |
11 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
11 ms |
340 KB |
Output is correct |
7 |
Correct |
11 ms |
364 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
368 KB |
Output is correct |
10 |
Correct |
11 ms |
368 KB |
Output is correct |
11 |
Correct |
11 ms |
372 KB |
Output is correct |
12 |
Correct |
11 ms |
340 KB |
Output is correct |
13 |
Correct |
11 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
16 ms |
376 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
19 |
Correct |
15 ms |
368 KB |
Output is correct |
20 |
Correct |
16 ms |
360 KB |
Output is correct |
21 |
Correct |
11 ms |
368 KB |
Output is correct |
22 |
Correct |
17 ms |
376 KB |
Output is correct |
23 |
Correct |
12 ms |
340 KB |
Output is correct |
24 |
Correct |
11 ms |
380 KB |
Output is correct |
25 |
Correct |
16 ms |
340 KB |
Output is correct |
26 |
Correct |
11 ms |
372 KB |
Output is correct |
27 |
Correct |
12 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
340 KB |
Output is correct |
3 |
Correct |
39 ms |
608 KB |
Output is correct |
4 |
Execution timed out |
4040 ms |
3476 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
340 KB |
Output is correct |
2 |
Correct |
16 ms |
388 KB |
Output is correct |
3 |
Correct |
16 ms |
380 KB |
Output is correct |
4 |
Correct |
11 ms |
380 KB |
Output is correct |
5 |
Execution timed out |
4067 ms |
3480 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
11 ms |
340 KB |
Output is correct |
7 |
Correct |
11 ms |
364 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
368 KB |
Output is correct |
10 |
Correct |
11 ms |
368 KB |
Output is correct |
11 |
Correct |
11 ms |
372 KB |
Output is correct |
12 |
Correct |
11 ms |
340 KB |
Output is correct |
13 |
Correct |
11 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
16 ms |
376 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
19 |
Correct |
15 ms |
368 KB |
Output is correct |
20 |
Correct |
16 ms |
360 KB |
Output is correct |
21 |
Correct |
11 ms |
368 KB |
Output is correct |
22 |
Correct |
17 ms |
376 KB |
Output is correct |
23 |
Correct |
12 ms |
340 KB |
Output is correct |
24 |
Correct |
11 ms |
380 KB |
Output is correct |
25 |
Correct |
16 ms |
340 KB |
Output is correct |
26 |
Correct |
11 ms |
372 KB |
Output is correct |
27 |
Correct |
12 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
11 ms |
340 KB |
Output is correct |
30 |
Correct |
11 ms |
340 KB |
Output is correct |
31 |
Correct |
39 ms |
608 KB |
Output is correct |
32 |
Execution timed out |
4040 ms |
3476 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |