#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 matching = 0;
auto b = a;
vector<int> odds;
for (int i = n; i >= 1; i--) {
if (a[i - 1] % 2 == 1) {
odds.push_back(i);
}
}
int ptr = n - 1;
for (auto &x : odds) {
while (ptr >= x / 2 && b[ptr] <= 1)
ptr--;
if (ptr >= x / 2 && b[ptr] > 1) {
b[ptr] -= 2;
matching++;
}
}
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";
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
352 KB |
Output is correct |
8 |
Correct |
14 ms |
340 KB |
Output is correct |
9 |
Correct |
22 ms |
340 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
11 |
Correct |
22 ms |
344 KB |
Output is correct |
12 |
Correct |
22 ms |
340 KB |
Output is correct |
13 |
Correct |
22 ms |
352 KB |
Output is correct |
14 |
Correct |
12 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 |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
352 KB |
Output is correct |
8 |
Correct |
14 ms |
340 KB |
Output is correct |
9 |
Correct |
22 ms |
340 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
11 |
Correct |
22 ms |
344 KB |
Output is correct |
12 |
Correct |
22 ms |
340 KB |
Output is correct |
13 |
Correct |
22 ms |
352 KB |
Output is correct |
14 |
Correct |
12 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 |
21 ms |
356 KB |
Output is correct |
18 |
Correct |
21 ms |
340 KB |
Output is correct |
19 |
Correct |
21 ms |
368 KB |
Output is correct |
20 |
Correct |
21 ms |
376 KB |
Output is correct |
21 |
Correct |
23 ms |
352 KB |
Output is correct |
22 |
Correct |
14 ms |
352 KB |
Output is correct |
23 |
Correct |
23 ms |
352 KB |
Output is correct |
24 |
Correct |
22 ms |
348 KB |
Output is correct |
25 |
Correct |
21 ms |
364 KB |
Output is correct |
26 |
Correct |
24 ms |
340 KB |
Output is correct |
27 |
Correct |
26 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
340 KB |
Output is correct |
3 |
Correct |
63 ms |
688 KB |
Output is correct |
4 |
Execution timed out |
4056 ms |
2912 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
348 KB |
Output is correct |
2 |
Correct |
21 ms |
368 KB |
Output is correct |
3 |
Correct |
22 ms |
372 KB |
Output is correct |
4 |
Correct |
23 ms |
352 KB |
Output is correct |
5 |
Execution timed out |
4043 ms |
3064 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 |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
352 KB |
Output is correct |
8 |
Correct |
14 ms |
340 KB |
Output is correct |
9 |
Correct |
22 ms |
340 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
11 |
Correct |
22 ms |
344 KB |
Output is correct |
12 |
Correct |
22 ms |
340 KB |
Output is correct |
13 |
Correct |
22 ms |
352 KB |
Output is correct |
14 |
Correct |
12 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 |
21 ms |
356 KB |
Output is correct |
18 |
Correct |
21 ms |
340 KB |
Output is correct |
19 |
Correct |
21 ms |
368 KB |
Output is correct |
20 |
Correct |
21 ms |
376 KB |
Output is correct |
21 |
Correct |
23 ms |
352 KB |
Output is correct |
22 |
Correct |
14 ms |
352 KB |
Output is correct |
23 |
Correct |
23 ms |
352 KB |
Output is correct |
24 |
Correct |
22 ms |
348 KB |
Output is correct |
25 |
Correct |
21 ms |
364 KB |
Output is correct |
26 |
Correct |
24 ms |
340 KB |
Output is correct |
27 |
Correct |
26 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
24 ms |
344 KB |
Output is correct |
30 |
Correct |
24 ms |
340 KB |
Output is correct |
31 |
Correct |
63 ms |
688 KB |
Output is correct |
32 |
Execution timed out |
4056 ms |
2912 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |