답안 #1046574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046574 2024-08-06T17:28:19 Z GusterGoose27 Mizuyokan 2 (JOI23_mizuyokan2) C++17
28 / 100
240 ms 23316 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 25e4+5;
int Arr[MAXN];
int arr[MAXN];
typedef long long ll;
ll pre[MAXN];
int n;

ll sum(int l, int r) {
	return pre[r+1] - pre[l];
}

int dp[MAXN];
vector<int> to_activate[MAXN];
int tmx[2*MAXN];

void reset() {
	fill(tmx, tmx+2*n+2, -1);
}

void upd(int p, int v) {
	p += n+1;
	tmx[p] = max(tmx[p], v);
	for (p /= 2; p > 0; p /= 2) {
		tmx[p] = max(tmx[2*p], tmx[2*p+1]);
	}
}

int get_mx(int l, int r) {
	l += n+1;
	r += n+2;
	int ans = -1;
	for (; r > l; l /= 2, r /= 2) {
		if (l & 1) ans = max(ans, tmx[l++]);
		if (r & 1) ans = max(ans, tmx[--r]);
	}
	return ans;
}

typedef array<int, 2> ar2;

int solve() {
	reset();
	for (int i = 0; i < n; i++) to_activate[i].clear();
	pre[0] = 0;
	for (int i = 0; i < n; i++) pre[i+1] = pre[i] + arr[i];
	dp[n] = 0;
	to_activate[n-1].push_back(n);
	vector<int> fin_activate;
	for (int i = n-1; i >= 0; i--) {
		for (int v: to_activate[i]) {
			upd(v, dp[v]);
		}
		if (i == n-1) {
			dp[i] = 1;
		}
		else {
			if (sum(i+1, n-1) <= arr[i]) dp[i] = -1;
			else {
				int mn = i+1, mx = n;
				while (mx > mn+1) {
					int mid = (mn+mx)/2;
					if (sum(i+1, mid-1) > arr[i]) mx = mid;
					else mn = mid;
				}
				dp[i] = 2+get_mx(mx, n);
				assert(dp[i] >= 2);
			}
		}
		if (sum(0, i-1) > arr[i]) {
			int mn = -1;
			int mx = i-1;
			while (mx > mn+1) {
				int mid = (mn+mx)/2;
				if (sum(mid+1, i-1) > arr[i]) mn = mid;
				else mx = mid;
			}
			if (mn == -1) fin_activate.push_back(i);
			else to_activate[mn].push_back(i);
		}
	}
	for (int v: fin_activate) {
		upd(v, dp[v]);
	}
	return max(dp[0], 1+get_mx(1, n));
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int N, q;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> Arr[i];
	}
	cin >> q;
	assert(q <= 10);
	while (q--) {
		int x, y, l, r;
		cin >> x >> y >> l >> r;
		Arr[x-1] = y;
		vector<int> cur;
		for (int i = l; i < r; i++) arr[i-l] = Arr[i];
		n = r-l;
		cout << solve() << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 1 ms 12636 KB Output is correct
9 Correct 1 ms 12636 KB Output is correct
10 Correct 1 ms 12772 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12732 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 1 ms 12636 KB Output is correct
20 Correct 1 ms 12636 KB Output is correct
21 Correct 1 ms 12632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 1 ms 12636 KB Output is correct
9 Correct 1 ms 12636 KB Output is correct
10 Correct 1 ms 12772 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12732 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 1 ms 12636 KB Output is correct
20 Correct 1 ms 12636 KB Output is correct
21 Correct 1 ms 12632 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 1 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 2 ms 12812 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 12640 KB Output is correct
30 Correct 2 ms 12640 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12640 KB Output is correct
33 Correct 2 ms 12792 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
39 Correct 1 ms 12636 KB Output is correct
40 Correct 2 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 1 ms 12636 KB Output is correct
9 Correct 1 ms 12636 KB Output is correct
10 Correct 1 ms 12772 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12732 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 1 ms 12636 KB Output is correct
20 Correct 1 ms 12636 KB Output is correct
21 Correct 1 ms 12632 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 1 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 2 ms 12812 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 12640 KB Output is correct
30 Correct 2 ms 12640 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12640 KB Output is correct
33 Correct 2 ms 12792 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
39 Correct 1 ms 12636 KB Output is correct
40 Correct 2 ms 12636 KB Output is correct
41 Correct 13 ms 14680 KB Output is correct
42 Correct 14 ms 14932 KB Output is correct
43 Correct 16 ms 15120 KB Output is correct
44 Correct 14 ms 14936 KB Output is correct
45 Correct 54 ms 18256 KB Output is correct
46 Correct 169 ms 19024 KB Output is correct
47 Correct 130 ms 18884 KB Output is correct
48 Correct 200 ms 21840 KB Output is correct
49 Correct 240 ms 21436 KB Output is correct
50 Correct 162 ms 19536 KB Output is correct
51 Correct 154 ms 20416 KB Output is correct
52 Correct 96 ms 19280 KB Output is correct
53 Correct 210 ms 21332 KB Output is correct
54 Correct 211 ms 20564 KB Output is correct
55 Correct 166 ms 21328 KB Output is correct
56 Correct 141 ms 18784 KB Output is correct
57 Correct 99 ms 17744 KB Output is correct
58 Correct 170 ms 20392 KB Output is correct
59 Correct 42 ms 18252 KB Output is correct
60 Correct 68 ms 18432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 12636 KB Output is correct
2 Runtime error 18 ms 23256 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 1 ms 12640 KB Output is correct
3 Runtime error 16 ms 23316 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 1 ms 12636 KB Output is correct
9 Correct 1 ms 12636 KB Output is correct
10 Correct 1 ms 12772 KB Output is correct
11 Correct 2 ms 12636 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 1 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 12636 KB Output is correct
17 Correct 2 ms 12732 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 1 ms 12636 KB Output is correct
20 Correct 1 ms 12636 KB Output is correct
21 Correct 1 ms 12632 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 1 ms 12636 KB Output is correct
25 Correct 2 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 2 ms 12812 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 12640 KB Output is correct
30 Correct 2 ms 12640 KB Output is correct
31 Correct 2 ms 12636 KB Output is correct
32 Correct 2 ms 12640 KB Output is correct
33 Correct 2 ms 12792 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 12636 KB Output is correct
36 Correct 2 ms 12636 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 12636 KB Output is correct
39 Correct 1 ms 12636 KB Output is correct
40 Correct 2 ms 12636 KB Output is correct
41 Correct 13 ms 14680 KB Output is correct
42 Correct 14 ms 14932 KB Output is correct
43 Correct 16 ms 15120 KB Output is correct
44 Correct 14 ms 14936 KB Output is correct
45 Correct 54 ms 18256 KB Output is correct
46 Correct 169 ms 19024 KB Output is correct
47 Correct 130 ms 18884 KB Output is correct
48 Correct 200 ms 21840 KB Output is correct
49 Correct 240 ms 21436 KB Output is correct
50 Correct 162 ms 19536 KB Output is correct
51 Correct 154 ms 20416 KB Output is correct
52 Correct 96 ms 19280 KB Output is correct
53 Correct 210 ms 21332 KB Output is correct
54 Correct 211 ms 20564 KB Output is correct
55 Correct 166 ms 21328 KB Output is correct
56 Correct 141 ms 18784 KB Output is correct
57 Correct 99 ms 17744 KB Output is correct
58 Correct 170 ms 20392 KB Output is correct
59 Correct 42 ms 18252 KB Output is correct
60 Correct 68 ms 18432 KB Output is correct
61 Correct 1 ms 12636 KB Output is correct
62 Runtime error 18 ms 23256 KB Execution killed with signal 6
63 Halted 0 ms 0 KB -