Submission #899910

# Submission time Handle Problem Language Result Execution time Memory
899910 2024-01-07T09:42:26 Z TAhmed33 Fish 2 (JOI22_fish2) C++
25 / 100
4000 ms 11044 KB
#include <bits/stdc++.h>
using namespace std;
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
const int MAXN = 1e5 + 25;
typedef long long ll;
ll a[MAXN], pref[MAXN];
int sparse[17][MAXN];
inline int query (int l, int r) {
	int m = __lg(r - l + 1);
	int x = sparse[m][l], y = sparse[m][r - (1 << m) + 1];
	if (a[x] > a[y]) return x;
	return y;
}
inline ll get (int l, int r) {
	return pref[r] - pref[l - 1];
}
int n;
void build () {
	for (int i = 1; i <= n; i++) {
		pref[i] = a[i] + pref[i - 1];
		sparse[0][i] = i;
	}
	for (int i = 1; i < 17; i++) {
		for (int j = 1; j + (1 << i) - 1 <= n; j++) {
			int x = sparse[i - 1][j], y = sparse[i - 1][j + (1 << (i - 1))];
			if (a[x] > a[y]) sparse[i][j] = x;
			else sparse[i][j] = y;
		}
	}
}
int ans (int l, int r) {
	if (l == r) return 1;
	auto u = query(l, r);
	int ret = 1;
	if (u - 1 >= l && get(l, u - 1) >= a[u]) ret += ans(l, u - 1);
	if (u + 1 <= r && get(u + 1, r) >= a[u]) ret += ans(u + 1, r);
	return ret; 
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int q;
	cin >> q;
	int last = 0;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			int x, y;
			cin >> x >> y;
			a[x] = y;
			last = 0;
		} else {
			int l, r;
			cin >> l >> r;
			if (last == 0) {
				last = 1;
				build();
			}
			cout << ans(l, r) << '\n';
		}
	}
}
# Verdict Execution time Memory 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 1 ms 2396 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4592 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 3 ms 4600 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 9 ms 8796 KB Output is correct
3 Correct 8 ms 8672 KB Output is correct
4 Correct 9 ms 8880 KB Output is correct
5 Correct 8 ms 8540 KB Output is correct
6 Correct 13 ms 9184 KB Output is correct
7 Correct 8 ms 8540 KB Output is correct
8 Correct 13 ms 9012 KB Output is correct
9 Correct 8 ms 8404 KB Output is correct
10 Correct 10 ms 8796 KB Output is correct
11 Correct 8 ms 8540 KB Output is correct
12 Correct 8 ms 8540 KB Output is correct
13 Correct 8 ms 8540 KB Output is correct
14 Correct 10 ms 9160 KB Output is correct
15 Correct 11 ms 9308 KB Output is correct
# Verdict Execution time Memory 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 1 ms 2396 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4592 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 3 ms 4600 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 9 ms 8796 KB Output is correct
23 Correct 8 ms 8672 KB Output is correct
24 Correct 9 ms 8880 KB Output is correct
25 Correct 8 ms 8540 KB Output is correct
26 Correct 13 ms 9184 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 13 ms 9012 KB Output is correct
29 Correct 8 ms 8404 KB Output is correct
30 Correct 10 ms 8796 KB Output is correct
31 Correct 8 ms 8540 KB Output is correct
32 Correct 8 ms 8540 KB Output is correct
33 Correct 8 ms 8540 KB Output is correct
34 Correct 10 ms 9160 KB Output is correct
35 Correct 11 ms 9308 KB Output is correct
36 Correct 388 ms 9108 KB Output is correct
37 Correct 382 ms 8536 KB Output is correct
38 Correct 94 ms 8868 KB Output is correct
39 Correct 273 ms 9012 KB Output is correct
40 Correct 101 ms 8540 KB Output is correct
41 Correct 787 ms 9188 KB Output is correct
42 Correct 558 ms 9552 KB Output is correct
43 Correct 559 ms 8788 KB Output is correct
44 Correct 256 ms 8536 KB Output is correct
45 Correct 461 ms 9044 KB Output is correct
46 Correct 381 ms 9000 KB Output is correct
47 Correct 96 ms 8700 KB Output is correct
48 Correct 551 ms 8700 KB Output is correct
49 Correct 247 ms 8756 KB Output is correct
50 Correct 614 ms 9304 KB Output is correct
51 Correct 869 ms 9812 KB Output is correct
52 Correct 527 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 9 ms 8796 KB Output is correct
3 Correct 8 ms 8672 KB Output is correct
4 Correct 9 ms 8880 KB Output is correct
5 Correct 8 ms 8540 KB Output is correct
6 Correct 13 ms 9184 KB Output is correct
7 Correct 8 ms 8540 KB Output is correct
8 Correct 13 ms 9012 KB Output is correct
9 Correct 8 ms 8404 KB Output is correct
10 Correct 10 ms 8796 KB Output is correct
11 Correct 8 ms 8540 KB Output is correct
12 Correct 8 ms 8540 KB Output is correct
13 Correct 8 ms 8540 KB Output is correct
14 Correct 10 ms 9160 KB Output is correct
15 Correct 11 ms 9308 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 189 ms 9780 KB Output is correct
18 Correct 1303 ms 11044 KB Output is correct
19 Correct 190 ms 10420 KB Output is correct
20 Correct 159 ms 10324 KB Output is correct
21 Correct 184 ms 10324 KB Output is correct
22 Correct 1264 ms 10968 KB Output is correct
23 Correct 171 ms 10324 KB Output is correct
24 Correct 184 ms 10320 KB Output is correct
25 Correct 179 ms 10308 KB Output is correct
26 Correct 179 ms 10328 KB Output is correct
27 Execution timed out 4065 ms 9740 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 9 ms 8796 KB Output is correct
3 Correct 8 ms 8672 KB Output is correct
4 Correct 9 ms 8880 KB Output is correct
5 Correct 8 ms 8540 KB Output is correct
6 Correct 13 ms 9184 KB Output is correct
7 Correct 8 ms 8540 KB Output is correct
8 Correct 13 ms 9012 KB Output is correct
9 Correct 8 ms 8404 KB Output is correct
10 Correct 10 ms 8796 KB Output is correct
11 Correct 8 ms 8540 KB Output is correct
12 Correct 8 ms 8540 KB Output is correct
13 Correct 8 ms 8540 KB Output is correct
14 Correct 10 ms 9160 KB Output is correct
15 Correct 11 ms 9308 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Execution timed out 4056 ms 9388 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 ms 2396 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4592 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 3 ms 4600 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 9 ms 8796 KB Output is correct
23 Correct 8 ms 8672 KB Output is correct
24 Correct 9 ms 8880 KB Output is correct
25 Correct 8 ms 8540 KB Output is correct
26 Correct 13 ms 9184 KB Output is correct
27 Correct 8 ms 8540 KB Output is correct
28 Correct 13 ms 9012 KB Output is correct
29 Correct 8 ms 8404 KB Output is correct
30 Correct 10 ms 8796 KB Output is correct
31 Correct 8 ms 8540 KB Output is correct
32 Correct 8 ms 8540 KB Output is correct
33 Correct 8 ms 8540 KB Output is correct
34 Correct 10 ms 9160 KB Output is correct
35 Correct 11 ms 9308 KB Output is correct
36 Correct 388 ms 9108 KB Output is correct
37 Correct 382 ms 8536 KB Output is correct
38 Correct 94 ms 8868 KB Output is correct
39 Correct 273 ms 9012 KB Output is correct
40 Correct 101 ms 8540 KB Output is correct
41 Correct 787 ms 9188 KB Output is correct
42 Correct 558 ms 9552 KB Output is correct
43 Correct 559 ms 8788 KB Output is correct
44 Correct 256 ms 8536 KB Output is correct
45 Correct 461 ms 9044 KB Output is correct
46 Correct 381 ms 9000 KB Output is correct
47 Correct 96 ms 8700 KB Output is correct
48 Correct 551 ms 8700 KB Output is correct
49 Correct 247 ms 8756 KB Output is correct
50 Correct 614 ms 9304 KB Output is correct
51 Correct 869 ms 9812 KB Output is correct
52 Correct 527 ms 9812 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 189 ms 9780 KB Output is correct
55 Correct 1303 ms 11044 KB Output is correct
56 Correct 190 ms 10420 KB Output is correct
57 Correct 159 ms 10324 KB Output is correct
58 Correct 184 ms 10324 KB Output is correct
59 Correct 1264 ms 10968 KB Output is correct
60 Correct 171 ms 10324 KB Output is correct
61 Correct 184 ms 10320 KB Output is correct
62 Correct 179 ms 10308 KB Output is correct
63 Correct 179 ms 10328 KB Output is correct
64 Execution timed out 4065 ms 9740 KB Time limit exceeded
65 Halted 0 ms 0 KB -