#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (auto &x : a)
cin >> x;
auto solve = [&]() {
lint deficiency = 0;
lint runsum = 0;
int ptr = n - 1;
int oddcnt = 0;
for (int x = n; x >= 1; x--) {
runsum += a[x - 1] % 2;
oddcnt += a[x - 1] % 2;
while (ptr >= x / 2) {
runsum -= a[ptr--] / 2;
}
deficiency = max(deficiency, runsum);
}
lint matching = oddcnt - deficiency;
lint moksum = 0;
for (int i = 1; i <= n; i++) {
moksum += a[i - 1] / 2;
}
return matching + (2 * moksum - 2 * matching) / 3;
};
while (q--) {
int i, d;
cin >> i >> d;
a[i - 1] += d;
cout << solve() << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
328 KB |
Output is correct |
7 |
Correct |
13 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
212 KB |
Output is correct |
9 |
Correct |
13 ms |
212 KB |
Output is correct |
10 |
Correct |
13 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
332 KB |
Output is correct |
12 |
Correct |
13 ms |
332 KB |
Output is correct |
13 |
Correct |
13 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
328 KB |
Output is correct |
7 |
Correct |
13 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
212 KB |
Output is correct |
9 |
Correct |
13 ms |
212 KB |
Output is correct |
10 |
Correct |
13 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
332 KB |
Output is correct |
12 |
Correct |
13 ms |
332 KB |
Output is correct |
13 |
Correct |
13 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
13 ms |
340 KB |
Output is correct |
18 |
Correct |
14 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
344 KB |
Output is correct |
20 |
Correct |
13 ms |
352 KB |
Output is correct |
21 |
Correct |
14 ms |
328 KB |
Output is correct |
22 |
Correct |
14 ms |
328 KB |
Output is correct |
23 |
Correct |
13 ms |
332 KB |
Output is correct |
24 |
Correct |
13 ms |
340 KB |
Output is correct |
25 |
Correct |
13 ms |
332 KB |
Output is correct |
26 |
Correct |
14 ms |
212 KB |
Output is correct |
27 |
Correct |
14 ms |
328 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
332 KB |
Output is correct |
2 |
Correct |
14 ms |
212 KB |
Output is correct |
3 |
Correct |
38 ms |
636 KB |
Output is correct |
4 |
Execution timed out |
4062 ms |
1252 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
344 KB |
Output is correct |
3 |
Correct |
14 ms |
328 KB |
Output is correct |
4 |
Correct |
13 ms |
332 KB |
Output is correct |
5 |
Execution timed out |
4046 ms |
1252 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
13 ms |
328 KB |
Output is correct |
7 |
Correct |
13 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
212 KB |
Output is correct |
9 |
Correct |
13 ms |
212 KB |
Output is correct |
10 |
Correct |
13 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
332 KB |
Output is correct |
12 |
Correct |
13 ms |
332 KB |
Output is correct |
13 |
Correct |
13 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
320 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
13 ms |
340 KB |
Output is correct |
18 |
Correct |
14 ms |
340 KB |
Output is correct |
19 |
Correct |
13 ms |
344 KB |
Output is correct |
20 |
Correct |
13 ms |
352 KB |
Output is correct |
21 |
Correct |
14 ms |
328 KB |
Output is correct |
22 |
Correct |
14 ms |
328 KB |
Output is correct |
23 |
Correct |
13 ms |
332 KB |
Output is correct |
24 |
Correct |
13 ms |
340 KB |
Output is correct |
25 |
Correct |
13 ms |
332 KB |
Output is correct |
26 |
Correct |
14 ms |
212 KB |
Output is correct |
27 |
Correct |
14 ms |
328 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
14 ms |
332 KB |
Output is correct |
30 |
Correct |
14 ms |
212 KB |
Output is correct |
31 |
Correct |
38 ms |
636 KB |
Output is correct |
32 |
Execution timed out |
4062 ms |
1252 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |