Submission #793643

# Submission time Handle Problem Language Result Execution time Memory
793643 2023-07-26T05:02:39 Z GEN 이지후(#10094) Triangle Collection (CCO23_day2problem3) C++17
25 / 25
259 ms 12648 KB
#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 MAXT = 530000;

struct seg {
	lint tree[MAXT], lazy[MAXT];
	void lazydown(int p) {
		for (int i = 2 * p; i < 2 * p + 2; i++) {
			tree[i] += lazy[p];
			lazy[i] += lazy[p];
		}
		lazy[p] = 0;
	}
	void add(int s, int e, int ps, int pe, int p, lint v) {
		if (e < ps || pe < s)
			return;
		if (s <= ps && pe <= e) {
			tree[p] += v;
			lazy[p] += v;
			return;
		}
		lazydown(p);
		int pm =(ps+pe)/2;
		add(s, e, ps, pm, 2 * p, v);
		add(s, e, pm + 1, pe, 2 * p + 1, v);
		tree[p] = max(tree[2 * p], tree[2 * p + 1]);
	}
} seg;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	lint moksum = 0, oddcnt = 0;
	for (auto &x : a)
		cin >> x, moksum += x / 2, oddcnt += x % 2;
	auto solve = [&]() {
		lint deficiency = max(0ll, seg.tree[1]);
		lint matching = oddcnt - deficiency;
		return matching + (2 * moksum - 2 * matching) / 3;
	};
	for (int i = 1; i <= n; i++) {
		seg.add(1, i, 1, n, 1, a[i - 1] % 2);
		seg.add(1, min(n, 2 * i - 1), 1, n, 1, -(a[i - 1] / 2));
	}
	while (q--) {
		int i, d;
		cin >> i >> d;
		moksum -= a[i - 1] / 2;
		oddcnt -= a[i - 1] % 2;
		seg.add(1, i, 1, n, 1, -a[i - 1] % 2);
		seg.add(1, 2 * i - 1, 1, n, 1, +(a[i - 1] / 2));
		a[i - 1] += d;
		moksum += a[i - 1] / 2;
		oddcnt += a[i - 1] % 2;
		seg.add(1, i, 1, n, 1, a[i - 1] % 2);
		seg.add(1, 2 * i - 1, 1, n, 1, -(a[i - 1] / 2));
		cout << solve() << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 2 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 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 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 42 ms 700 KB Output is correct
4 Correct 229 ms 10512 KB Output is correct
5 Correct 213 ms 10624 KB Output is correct
6 Correct 220 ms 10624 KB Output is correct
7 Correct 208 ms 10668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 ms 340 KB Output is correct
5 Correct 210 ms 10712 KB Output is correct
6 Correct 231 ms 12536 KB Output is correct
7 Correct 235 ms 12520 KB Output is correct
8 Correct 222 ms 12528 KB Output is correct
9 Correct 231 ms 12544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 2 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 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 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 42 ms 700 KB Output is correct
32 Correct 229 ms 10512 KB Output is correct
33 Correct 213 ms 10624 KB Output is correct
34 Correct 220 ms 10624 KB Output is correct
35 Correct 208 ms 10668 KB Output is correct
36 Correct 2 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 2 ms 340 KB Output is correct
40 Correct 210 ms 10712 KB Output is correct
41 Correct 231 ms 12536 KB Output is correct
42 Correct 235 ms 12520 KB Output is correct
43 Correct 222 ms 12528 KB Output is correct
44 Correct 231 ms 12544 KB Output is correct
45 Correct 232 ms 12628 KB Output is correct
46 Correct 229 ms 12648 KB Output is correct
47 Correct 259 ms 12584 KB Output is correct
48 Correct 215 ms 10724 KB Output is correct
49 Correct 199 ms 12444 KB Output is correct
50 Correct 227 ms 11212 KB Output is correct
51 Correct 101 ms 11120 KB Output is correct
52 Correct 214 ms 12552 KB Output is correct
53 Correct 99 ms 10816 KB Output is correct
54 Correct 204 ms 10620 KB Output is correct