#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()
const int MAXN = 2005;
struct fen {
pi tree[MAXN];
void clear() { fill(tree, tree + MAXN, pi{int(1e9), -1}); }
void add(int x, pi v) {
for (int i = x + 2; i < MAXN; i += i & -i)
tree[i] = min(tree[i], v);
}
pi query(int x) {
pi ret{int(1e9), -1};
for (int i = x + 2; i; i -= i & -i)
ret = min(ret, tree[i]);
return ret;
}
} bit;
pi dp[MAXN][MAXN];
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 ans = 0;
auto b = a;
vector<int> odds;
for (int i = n; i >= 1; i--) {
if (b[i - 1] % 2 == 1) {
odds.push_back(i);
b[i - 1]--;
}
}
int ptr = n - 1;
for (auto &x : odds) {
while (ptr >= x / 2 && b[ptr] == 0)
ptr--;
if (ptr >= x / 2 && b[ptr] > 0) {
b[ptr] -= 2;
ans++;
}
}
lint cnt = 0;
for (int i = 1; i <= n; i++) {
cnt += b[i - 1];
}
ans += cnt / 3;
return ans;
};
while (q--) {
int i, d;
cin >> i >> d;
a[i - 1] += d;
cout << solve() << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
21 ms |
356 KB |
Output is correct |
7 |
Correct |
21 ms |
340 KB |
Output is correct |
8 |
Correct |
15 ms |
344 KB |
Output is correct |
9 |
Correct |
23 ms |
356 KB |
Output is correct |
10 |
Correct |
23 ms |
356 KB |
Output is correct |
11 |
Correct |
19 ms |
368 KB |
Output is correct |
12 |
Correct |
23 ms |
340 KB |
Output is correct |
13 |
Correct |
27 ms |
360 KB |
Output is correct |
14 |
Correct |
13 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
21 ms |
356 KB |
Output is correct |
7 |
Correct |
21 ms |
340 KB |
Output is correct |
8 |
Correct |
15 ms |
344 KB |
Output is correct |
9 |
Correct |
23 ms |
356 KB |
Output is correct |
10 |
Correct |
23 ms |
356 KB |
Output is correct |
11 |
Correct |
19 ms |
368 KB |
Output is correct |
12 |
Correct |
23 ms |
340 KB |
Output is correct |
13 |
Correct |
27 ms |
360 KB |
Output is correct |
14 |
Correct |
13 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
20 ms |
384 KB |
Output is correct |
18 |
Correct |
21 ms |
372 KB |
Output is correct |
19 |
Correct |
21 ms |
352 KB |
Output is correct |
20 |
Correct |
21 ms |
372 KB |
Output is correct |
21 |
Correct |
23 ms |
368 KB |
Output is correct |
22 |
Correct |
13 ms |
348 KB |
Output is correct |
23 |
Correct |
20 ms |
360 KB |
Output is correct |
24 |
Correct |
19 ms |
372 KB |
Output is correct |
25 |
Correct |
21 ms |
384 KB |
Output is correct |
26 |
Correct |
24 ms |
340 KB |
Output is correct |
27 |
Correct |
24 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
356 KB |
Output is correct |
2 |
Correct |
27 ms |
340 KB |
Output is correct |
3 |
Correct |
66 ms |
676 KB |
Output is correct |
4 |
Execution timed out |
4062 ms |
2860 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
340 KB |
Output is correct |
2 |
Correct |
22 ms |
388 KB |
Output is correct |
3 |
Correct |
23 ms |
372 KB |
Output is correct |
4 |
Correct |
23 ms |
368 KB |
Output is correct |
5 |
Execution timed out |
4040 ms |
3024 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
21 ms |
356 KB |
Output is correct |
7 |
Correct |
21 ms |
340 KB |
Output is correct |
8 |
Correct |
15 ms |
344 KB |
Output is correct |
9 |
Correct |
23 ms |
356 KB |
Output is correct |
10 |
Correct |
23 ms |
356 KB |
Output is correct |
11 |
Correct |
19 ms |
368 KB |
Output is correct |
12 |
Correct |
23 ms |
340 KB |
Output is correct |
13 |
Correct |
27 ms |
360 KB |
Output is correct |
14 |
Correct |
13 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
20 ms |
384 KB |
Output is correct |
18 |
Correct |
21 ms |
372 KB |
Output is correct |
19 |
Correct |
21 ms |
352 KB |
Output is correct |
20 |
Correct |
21 ms |
372 KB |
Output is correct |
21 |
Correct |
23 ms |
368 KB |
Output is correct |
22 |
Correct |
13 ms |
348 KB |
Output is correct |
23 |
Correct |
20 ms |
360 KB |
Output is correct |
24 |
Correct |
19 ms |
372 KB |
Output is correct |
25 |
Correct |
21 ms |
384 KB |
Output is correct |
26 |
Correct |
24 ms |
340 KB |
Output is correct |
27 |
Correct |
24 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
296 KB |
Output is correct |
29 |
Correct |
21 ms |
356 KB |
Output is correct |
30 |
Correct |
27 ms |
340 KB |
Output is correct |
31 |
Correct |
66 ms |
676 KB |
Output is correct |
32 |
Execution timed out |
4062 ms |
2860 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |