답안 #882974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882974 2023-12-04T09:51:38 Z tsumondai Triangle Collection (CCO23_day2problem3) C++14
25 / 25
232 ms 20828 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 2e5 + 5;

const int oo = 1e9, mod = 1e9 + 7;

int n, m, k, a[N];
int nodes[4 * N], lazy[4 * N];
vector<int> arr;

void push_down(int c) {
	nodes[c << 1] += lazy[c];
	nodes[c << 1 | 1] += lazy[c];
	lazy[c << 1] += lazy[c];
	lazy[c << 1 | 1] += lazy[c];
	lazy[c] = 0;
}

void update(int c, int cl, int cr, int l, int r, int val) {
	if (l <= cl and cr <= r) {
		nodes[c] += val;
		lazy[c] += val;
		return;
	}
	push_down(c);
	int mid = cl + cr >> 1;
	if (l <= mid) update(c << 1, cl, mid, l, r, val);
	if (r > mid) update(c << 1 | 1, mid + 1, cr, l, r, val);
	nodes[c] = min(nodes[c << 1], nodes[c << 1 | 1]);
}

void process() {
	cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	foru(i, 1, n) {
		cin >> a[i];
		if (a[i] % 2 == 1) update(1, 1, n, 1, i, -1);
		update(1, 1, n, 1, min(n, 2 * i - 1), a[i] / 2);
		cnt1 += a[i] % 2;
		cnt2 += a[i] / 2;
	}
	while (m--) {
		int x, y;
		cin >> x >> y;
		cnt1 -= a[x] % 2, cnt2 -= a[x] / 2;
		if (a[x] % 2 == 1) update(1, 1, n, 1, x, 1);
		update(1, 1, n, 1, min(n, 2 * x - 1), - a[x] / 2);
		a[x] += y;
		cnt1 += a[x] % 2, cnt2 += a[x] / 2;
		if (a[x] % 2 == 1) update(1, 1, n, 1, x, -1);
		update(1, 1, n, 1, min(n, 2 * x - 1), a[x] / 2);
		int tmp = -nodes[1];
		tmp = max(0ll, tmp);
		int ans = cnt1 - tmp;
		ans += (2 * cnt2 - 2 * ans) / 3;
		cout << ans << "\n";
	}
	return;
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);
	process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

// dont stop

Compilation message

Main.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |  int mid = cl + cr >> 1;
      |            ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2536 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2400 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2536 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2400 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2572 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2400 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2400 KB Output is correct
22 Correct 1 ms 2428 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 1 ms 2400 KB Output is correct
25 Correct 2 ms 2400 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 1 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2400 KB Output is correct
2 Correct 2 ms 2520 KB Output is correct
3 Correct 39 ms 3648 KB Output is correct
4 Correct 145 ms 15688 KB Output is correct
5 Correct 161 ms 15580 KB Output is correct
6 Correct 190 ms 15732 KB Output is correct
7 Correct 180 ms 15564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 2 ms 2520 KB Output is correct
5 Correct 164 ms 15824 KB Output is correct
6 Correct 198 ms 19372 KB Output is correct
7 Correct 184 ms 19148 KB Output is correct
8 Correct 213 ms 19124 KB Output is correct
9 Correct 202 ms 19028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2536 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2400 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2572 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2400 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 2 ms 2400 KB Output is correct
22 Correct 1 ms 2428 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 1 ms 2400 KB Output is correct
25 Correct 2 ms 2400 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 1 ms 2404 KB Output is correct
29 Correct 2 ms 2400 KB Output is correct
30 Correct 2 ms 2520 KB Output is correct
31 Correct 39 ms 3648 KB Output is correct
32 Correct 145 ms 15688 KB Output is correct
33 Correct 161 ms 15580 KB Output is correct
34 Correct 190 ms 15732 KB Output is correct
35 Correct 180 ms 15564 KB Output is correct
36 Correct 3 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2520 KB Output is correct
40 Correct 164 ms 15824 KB Output is correct
41 Correct 198 ms 19372 KB Output is correct
42 Correct 184 ms 19148 KB Output is correct
43 Correct 213 ms 19124 KB Output is correct
44 Correct 202 ms 19028 KB Output is correct
45 Correct 206 ms 20828 KB Output is correct
46 Correct 204 ms 19160 KB Output is correct
47 Correct 214 ms 20480 KB Output is correct
48 Correct 232 ms 15748 KB Output is correct
49 Correct 118 ms 19028 KB Output is correct
50 Correct 196 ms 17724 KB Output is correct
51 Correct 94 ms 17928 KB Output is correct
52 Correct 198 ms 20572 KB Output is correct
53 Correct 108 ms 17500 KB Output is correct
54 Correct 198 ms 16716 KB Output is correct