Submission #899903

# Submission time Handle Problem Language Result Execution time Memory
899903 2024-01-07T09:19:07 Z TAhmed33 Fish 2 (JOI22_fish2) C++
13 / 100
4000 ms 4956 KB
#include <bits/stdc++.h>
using namespace std;
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
const int MAXN = 1e5 + 25;
typedef long long ll;
struct SegmentTree {
	int a[MAXN]; ll sum[MAXN << 1];
	pair <int, int> mx[MAXN << 1];
	void build (int l, int r, int node) {
		if (l == r) {
			sum[node] = a[l];
			mx[node] = {a[l], l};
		} else {
			build(l, mid, tl);
			build(mid + 1, r, tr);
			mx[node] = max(mx[tl], mx[tr]);
			sum[node] = sum[tl] + sum[tr];
		}
	}
	void update (int l, int r, int a2, int b, int node) {
		if (l == r) {
			sum[node] = b; a[l] = b;
			mx[node] = {b, l};
			return;
		}
		if (a2 <= mid) update(l, mid, a2, b, tl);
		else update(mid + 1, r, a2, b, tr);
		mx[node] = max(mx[tl], mx[tr]);
		sum[node] = sum[tl] + sum[tr];
	}
	ll get_sum (int l, int r, int a, int b, int node) {
		if (l >= a && r <= b) return sum[node];
		if (l > b || r < a) return 0;
		return get_sum(l, mid, a, b, tl) + get_sum(mid + 1, r, a, b, tr);
	}
	pair <int, int> get_mx (int l, int r, int a, int b, int node) {
		if (l >= a && r <= b) return mx[node];
		if (l > b || r < a) return {0, 0};
		return max(get_mx(l, mid, a, b, tl), get_mx(mid + 1, r, a, b, tr));
	}
} cur;
int n;
int ans (int l, int r) {
	if (l == r) return 1;
	auto u = cur.get_mx(1, n, l, r, 1);
	int ret = 1;
	if (u.second - 1 >= l && cur.get_sum(1, n, l, u.second - 1, 1) >= cur.a[u.second]) ret += ans(l, u.second - 1);
	if (u.second + 1 <= r && cur.get_sum(1, n, u.second + 1, r, 1) >= cur.a[u.second]) ret += ans(u.second + 1, r);
	return ret; 
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> cur.a[i];
	cur.build(1, n, 1);
	int q;
	cin >> q;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int x, y;
			cin >> x >> y;
			cur.update(1, n, x, y, 1);
		} else {
			int l, r;
			cin >> l >> r;
			cout << ans(l, r) << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3672 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 2 ms 3676 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 4 ms 3828 KB Output is correct
11 Correct 8 ms 3676 KB Output is correct
12 Correct 2 ms 3820 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3824 KB Output is correct
15 Correct 2 ms 3672 KB Output is correct
16 Correct 3 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 3 ms 3828 KB Output is correct
20 Correct 10 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 10 ms 3980 KB Output is correct
3 Correct 7 ms 3980 KB Output is correct
4 Correct 10 ms 3932 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 27 ms 3840 KB Output is correct
7 Correct 6 ms 3928 KB Output is correct
8 Correct 27 ms 3936 KB Output is correct
9 Correct 6 ms 3932 KB Output is correct
10 Correct 10 ms 3932 KB Output is correct
11 Correct 7 ms 3880 KB Output is correct
12 Correct 6 ms 3932 KB Output is correct
13 Correct 9 ms 4188 KB Output is correct
14 Correct 20 ms 4736 KB Output is correct
15 Correct 19 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3672 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 2 ms 3676 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 4 ms 3828 KB Output is correct
11 Correct 8 ms 3676 KB Output is correct
12 Correct 2 ms 3820 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3824 KB Output is correct
15 Correct 2 ms 3672 KB Output is correct
16 Correct 3 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 3 ms 3828 KB Output is correct
20 Correct 10 ms 3676 KB Output is correct
21 Correct 1 ms 3672 KB Output is correct
22 Correct 10 ms 3980 KB Output is correct
23 Correct 7 ms 3980 KB Output is correct
24 Correct 10 ms 3932 KB Output is correct
25 Correct 7 ms 3932 KB Output is correct
26 Correct 27 ms 3840 KB Output is correct
27 Correct 6 ms 3928 KB Output is correct
28 Correct 27 ms 3936 KB Output is correct
29 Correct 6 ms 3932 KB Output is correct
30 Correct 10 ms 3932 KB Output is correct
31 Correct 7 ms 3880 KB Output is correct
32 Correct 6 ms 3932 KB Output is correct
33 Correct 9 ms 4188 KB Output is correct
34 Correct 20 ms 4736 KB Output is correct
35 Correct 19 ms 4696 KB Output is correct
36 Correct 308 ms 4944 KB Output is correct
37 Correct 133 ms 4316 KB Output is correct
38 Correct 90 ms 4188 KB Output is correct
39 Correct 146 ms 4696 KB Output is correct
40 Correct 97 ms 4188 KB Output is correct
41 Execution timed out 4054 ms 4956 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 10 ms 3980 KB Output is correct
3 Correct 7 ms 3980 KB Output is correct
4 Correct 10 ms 3932 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 27 ms 3840 KB Output is correct
7 Correct 6 ms 3928 KB Output is correct
8 Correct 27 ms 3936 KB Output is correct
9 Correct 6 ms 3932 KB Output is correct
10 Correct 10 ms 3932 KB Output is correct
11 Correct 7 ms 3880 KB Output is correct
12 Correct 6 ms 3932 KB Output is correct
13 Correct 9 ms 4188 KB Output is correct
14 Correct 20 ms 4736 KB Output is correct
15 Correct 19 ms 4696 KB Output is correct
16 Correct 1 ms 3672 KB Output is correct
17 Execution timed out 4046 ms 4256 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 10 ms 3980 KB Output is correct
3 Correct 7 ms 3980 KB Output is correct
4 Correct 10 ms 3932 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 27 ms 3840 KB Output is correct
7 Correct 6 ms 3928 KB Output is correct
8 Correct 27 ms 3936 KB Output is correct
9 Correct 6 ms 3932 KB Output is correct
10 Correct 10 ms 3932 KB Output is correct
11 Correct 7 ms 3880 KB Output is correct
12 Correct 6 ms 3932 KB Output is correct
13 Correct 9 ms 4188 KB Output is correct
14 Correct 20 ms 4736 KB Output is correct
15 Correct 19 ms 4696 KB Output is correct
16 Correct 1 ms 3672 KB Output is correct
17 Execution timed out 4081 ms 4732 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 1 ms 3676 KB Output is correct
3 Correct 1 ms 3672 KB Output is correct
4 Correct 1 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 2 ms 3676 KB Output is correct
7 Correct 1 ms 3676 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 4 ms 3828 KB Output is correct
11 Correct 8 ms 3676 KB Output is correct
12 Correct 2 ms 3820 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3824 KB Output is correct
15 Correct 2 ms 3672 KB Output is correct
16 Correct 3 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 3 ms 3828 KB Output is correct
20 Correct 10 ms 3676 KB Output is correct
21 Correct 1 ms 3672 KB Output is correct
22 Correct 10 ms 3980 KB Output is correct
23 Correct 7 ms 3980 KB Output is correct
24 Correct 10 ms 3932 KB Output is correct
25 Correct 7 ms 3932 KB Output is correct
26 Correct 27 ms 3840 KB Output is correct
27 Correct 6 ms 3928 KB Output is correct
28 Correct 27 ms 3936 KB Output is correct
29 Correct 6 ms 3932 KB Output is correct
30 Correct 10 ms 3932 KB Output is correct
31 Correct 7 ms 3880 KB Output is correct
32 Correct 6 ms 3932 KB Output is correct
33 Correct 9 ms 4188 KB Output is correct
34 Correct 20 ms 4736 KB Output is correct
35 Correct 19 ms 4696 KB Output is correct
36 Correct 308 ms 4944 KB Output is correct
37 Correct 133 ms 4316 KB Output is correct
38 Correct 90 ms 4188 KB Output is correct
39 Correct 146 ms 4696 KB Output is correct
40 Correct 97 ms 4188 KB Output is correct
41 Execution timed out 4054 ms 4956 KB Time limit exceeded
42 Halted 0 ms 0 KB -