# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568889 | 2022-05-26T10:05:17 Z | nonsensenonsense1 | Fish 2 (JOI22_fish2) | C++17 | 4000 ms | 5136 KB |
#include <cstdio> #include <cstring> #include <utility> #include <algorithm> const int N = 100005; int n, q, a[N], le[N], ri[N], cnt[N]; std::pair<int, int> b[N], b1[N]; bool u[N]; long long sum[N]; int c[(1 << 16) + 1]; void countsort(int len) { for (int t = 0; t < 2; ++t) { memset(c, 0, sizeof c); for (int i = 0; i < len; ++i) ++c[(b[i].first >> t * 16 & 65535) + 1]; for (int i = 1; i < 65536; ++i) c[i] += c[i - 1]; for (int i = 0; i < len; ++i) b1[c[b[i].first >> t * 16 & 65535]++] = b[i]; std::swap(b, b1); } } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", a + i); scanf("%d", &q); while (q--) { int t; scanf("%d", &t); if (t == 1) { int x, y; scanf("%d%d", &x, &y); a[x - 1] = y; } else { int l, r; scanf("%d%d", &l, &r); --l; int len = r - l; for (int i = 0; i < len; ++i) { b[i] = std::make_pair(a[l + i], i); sum[i + 1] = sum[i] + a[l + i]; le[i] = ri[i] = i; cnt[i] = 0; u[i] = 0; } //std::sort(b, b + len); countsort(len); for (int i = 0; i < len; ++i) { int id = b[i].second; u[id] = 1; int ll = id && u[id - 1] ? le[id - 1] : id, rr = id + 1 < len && u[id + 1] ? ri[id + 1] : id, curcnt = 1; if (sum[rr + 1] - sum[id + 1] >= sum[id + 1] - sum[id]) curcnt += cnt[id + 1]; if (sum[id] - sum[ll] >= sum[id + 1] - sum[id]) curcnt += cnt[id - 1]; ri[ll] = rr; le[rr] = ll; cnt[ll] = cnt[rr] = curcnt; } printf("%d\n", cnt[0]); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2132 KB | Output is correct |
2 | Correct | 3 ms | 2136 KB | Output is correct |
3 | Correct | 7 ms | 2132 KB | Output is correct |
4 | Correct | 4 ms | 2132 KB | Output is correct |
5 | Correct | 71 ms | 2136 KB | Output is correct |
6 | Correct | 293 ms | 2156 KB | Output is correct |
7 | Correct | 71 ms | 2132 KB | Output is correct |
8 | Correct | 236 ms | 2140 KB | Output is correct |
9 | Correct | 345 ms | 2140 KB | Output is correct |
10 | Correct | 121 ms | 2144 KB | Output is correct |
11 | Correct | 334 ms | 2148 KB | Output is correct |
12 | Correct | 67 ms | 2144 KB | Output is correct |
13 | Correct | 304 ms | 2140 KB | Output is correct |
14 | Correct | 85 ms | 2136 KB | Output is correct |
15 | Correct | 156 ms | 2132 KB | Output is correct |
16 | Correct | 295 ms | 2140 KB | Output is correct |
17 | Correct | 115 ms | 2136 KB | Output is correct |
18 | Correct | 335 ms | 2144 KB | Output is correct |
19 | Correct | 151 ms | 2140 KB | Output is correct |
20 | Correct | 344 ms | 2144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2132 KB | Output is correct |
2 | Correct | 20 ms | 4560 KB | Output is correct |
3 | Correct | 17 ms | 4556 KB | Output is correct |
4 | Correct | 20 ms | 4612 KB | Output is correct |
5 | Correct | 17 ms | 4556 KB | Output is correct |
6 | Correct | 25 ms | 4736 KB | Output is correct |
7 | Correct | 16 ms | 4564 KB | Output is correct |
8 | Correct | 25 ms | 4732 KB | Output is correct |
9 | Correct | 18 ms | 4636 KB | Output is correct |
10 | Correct | 19 ms | 4652 KB | Output is correct |
11 | Correct | 16 ms | 4628 KB | Output is correct |
12 | Correct | 19 ms | 4564 KB | Output is correct |
13 | Correct | 18 ms | 4564 KB | Output is correct |
14 | Correct | 19 ms | 4552 KB | Output is correct |
15 | Correct | 19 ms | 4660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2132 KB | Output is correct |
2 | Correct | 3 ms | 2136 KB | Output is correct |
3 | Correct | 7 ms | 2132 KB | Output is correct |
4 | Correct | 4 ms | 2132 KB | Output is correct |
5 | Correct | 71 ms | 2136 KB | Output is correct |
6 | Correct | 293 ms | 2156 KB | Output is correct |
7 | Correct | 71 ms | 2132 KB | Output is correct |
8 | Correct | 236 ms | 2140 KB | Output is correct |
9 | Correct | 345 ms | 2140 KB | Output is correct |
10 | Correct | 121 ms | 2144 KB | Output is correct |
11 | Correct | 334 ms | 2148 KB | Output is correct |
12 | Correct | 67 ms | 2144 KB | Output is correct |
13 | Correct | 304 ms | 2140 KB | Output is correct |
14 | Correct | 85 ms | 2136 KB | Output is correct |
15 | Correct | 156 ms | 2132 KB | Output is correct |
16 | Correct | 295 ms | 2140 KB | Output is correct |
17 | Correct | 115 ms | 2136 KB | Output is correct |
18 | Correct | 335 ms | 2144 KB | Output is correct |
19 | Correct | 151 ms | 2140 KB | Output is correct |
20 | Correct | 344 ms | 2144 KB | Output is correct |
21 | Correct | 2 ms | 2132 KB | Output is correct |
22 | Correct | 20 ms | 4560 KB | Output is correct |
23 | Correct | 17 ms | 4556 KB | Output is correct |
24 | Correct | 20 ms | 4612 KB | Output is correct |
25 | Correct | 17 ms | 4556 KB | Output is correct |
26 | Correct | 25 ms | 4736 KB | Output is correct |
27 | Correct | 16 ms | 4564 KB | Output is correct |
28 | Correct | 25 ms | 4732 KB | Output is correct |
29 | Correct | 18 ms | 4636 KB | Output is correct |
30 | Correct | 19 ms | 4652 KB | Output is correct |
31 | Correct | 16 ms | 4628 KB | Output is correct |
32 | Correct | 19 ms | 4564 KB | Output is correct |
33 | Correct | 18 ms | 4564 KB | Output is correct |
34 | Correct | 19 ms | 4552 KB | Output is correct |
35 | Correct | 19 ms | 4660 KB | Output is correct |
36 | Correct | 861 ms | 4624 KB | Output is correct |
37 | Correct | 1275 ms | 4460 KB | Output is correct |
38 | Correct | 1547 ms | 4540 KB | Output is correct |
39 | Correct | 381 ms | 4440 KB | Output is correct |
40 | Correct | 1688 ms | 4556 KB | Output is correct |
41 | Correct | 1671 ms | 4828 KB | Output is correct |
42 | Correct | 2143 ms | 4616 KB | Output is correct |
43 | Correct | 1355 ms | 4620 KB | Output is correct |
44 | Correct | 1546 ms | 4584 KB | Output is correct |
45 | Correct | 933 ms | 4644 KB | Output is correct |
46 | Correct | 1312 ms | 4572 KB | Output is correct |
47 | Correct | 1571 ms | 4640 KB | Output is correct |
48 | Correct | 519 ms | 4524 KB | Output is correct |
49 | Correct | 1583 ms | 4560 KB | Output is correct |
50 | Correct | 861 ms | 4636 KB | Output is correct |
51 | Correct | 2508 ms | 4660 KB | Output is correct |
52 | Correct | 3161 ms | 5136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2132 KB | Output is correct |
2 | Correct | 20 ms | 4560 KB | Output is correct |
3 | Correct | 17 ms | 4556 KB | Output is correct |
4 | Correct | 20 ms | 4612 KB | Output is correct |
5 | Correct | 17 ms | 4556 KB | Output is correct |
6 | Correct | 25 ms | 4736 KB | Output is correct |
7 | Correct | 16 ms | 4564 KB | Output is correct |
8 | Correct | 25 ms | 4732 KB | Output is correct |
9 | Correct | 18 ms | 4636 KB | Output is correct |
10 | Correct | 19 ms | 4652 KB | Output is correct |
11 | Correct | 16 ms | 4628 KB | Output is correct |
12 | Correct | 19 ms | 4564 KB | Output is correct |
13 | Correct | 18 ms | 4564 KB | Output is correct |
14 | Correct | 19 ms | 4552 KB | Output is correct |
15 | Correct | 19 ms | 4660 KB | Output is correct |
16 | Correct | 7 ms | 2132 KB | Output is correct |
17 | Execution timed out | 4078 ms | 4720 KB | Time limit exceeded |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2132 KB | Output is correct |
2 | Correct | 20 ms | 4560 KB | Output is correct |
3 | Correct | 17 ms | 4556 KB | Output is correct |
4 | Correct | 20 ms | 4612 KB | Output is correct |
5 | Correct | 17 ms | 4556 KB | Output is correct |
6 | Correct | 25 ms | 4736 KB | Output is correct |
7 | Correct | 16 ms | 4564 KB | Output is correct |
8 | Correct | 25 ms | 4732 KB | Output is correct |
9 | Correct | 18 ms | 4636 KB | Output is correct |
10 | Correct | 19 ms | 4652 KB | Output is correct |
11 | Correct | 16 ms | 4628 KB | Output is correct |
12 | Correct | 19 ms | 4564 KB | Output is correct |
13 | Correct | 18 ms | 4564 KB | Output is correct |
14 | Correct | 19 ms | 4552 KB | Output is correct |
15 | Correct | 19 ms | 4660 KB | Output is correct |
16 | Correct | 5 ms | 2132 KB | Output is correct |
17 | Execution timed out | 4056 ms | 4756 KB | Time limit exceeded |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2132 KB | Output is correct |
2 | Correct | 3 ms | 2136 KB | Output is correct |
3 | Correct | 7 ms | 2132 KB | Output is correct |
4 | Correct | 4 ms | 2132 KB | Output is correct |
5 | Correct | 71 ms | 2136 KB | Output is correct |
6 | Correct | 293 ms | 2156 KB | Output is correct |
7 | Correct | 71 ms | 2132 KB | Output is correct |
8 | Correct | 236 ms | 2140 KB | Output is correct |
9 | Correct | 345 ms | 2140 KB | Output is correct |
10 | Correct | 121 ms | 2144 KB | Output is correct |
11 | Correct | 334 ms | 2148 KB | Output is correct |
12 | Correct | 67 ms | 2144 KB | Output is correct |
13 | Correct | 304 ms | 2140 KB | Output is correct |
14 | Correct | 85 ms | 2136 KB | Output is correct |
15 | Correct | 156 ms | 2132 KB | Output is correct |
16 | Correct | 295 ms | 2140 KB | Output is correct |
17 | Correct | 115 ms | 2136 KB | Output is correct |
18 | Correct | 335 ms | 2144 KB | Output is correct |
19 | Correct | 151 ms | 2140 KB | Output is correct |
20 | Correct | 344 ms | 2144 KB | Output is correct |
21 | Correct | 2 ms | 2132 KB | Output is correct |
22 | Correct | 20 ms | 4560 KB | Output is correct |
23 | Correct | 17 ms | 4556 KB | Output is correct |
24 | Correct | 20 ms | 4612 KB | Output is correct |
25 | Correct | 17 ms | 4556 KB | Output is correct |
26 | Correct | 25 ms | 4736 KB | Output is correct |
27 | Correct | 16 ms | 4564 KB | Output is correct |
28 | Correct | 25 ms | 4732 KB | Output is correct |
29 | Correct | 18 ms | 4636 KB | Output is correct |
30 | Correct | 19 ms | 4652 KB | Output is correct |
31 | Correct | 16 ms | 4628 KB | Output is correct |
32 | Correct | 19 ms | 4564 KB | Output is correct |
33 | Correct | 18 ms | 4564 KB | Output is correct |
34 | Correct | 19 ms | 4552 KB | Output is correct |
35 | Correct | 19 ms | 4660 KB | Output is correct |
36 | Correct | 861 ms | 4624 KB | Output is correct |
37 | Correct | 1275 ms | 4460 KB | Output is correct |
38 | Correct | 1547 ms | 4540 KB | Output is correct |
39 | Correct | 381 ms | 4440 KB | Output is correct |
40 | Correct | 1688 ms | 4556 KB | Output is correct |
41 | Correct | 1671 ms | 4828 KB | Output is correct |
42 | Correct | 2143 ms | 4616 KB | Output is correct |
43 | Correct | 1355 ms | 4620 KB | Output is correct |
44 | Correct | 1546 ms | 4584 KB | Output is correct |
45 | Correct | 933 ms | 4644 KB | Output is correct |
46 | Correct | 1312 ms | 4572 KB | Output is correct |
47 | Correct | 1571 ms | 4640 KB | Output is correct |
48 | Correct | 519 ms | 4524 KB | Output is correct |
49 | Correct | 1583 ms | 4560 KB | Output is correct |
50 | Correct | 861 ms | 4636 KB | Output is correct |
51 | Correct | 2508 ms | 4660 KB | Output is correct |
52 | Correct | 3161 ms | 5136 KB | Output is correct |
53 | Correct | 7 ms | 2132 KB | Output is correct |
54 | Execution timed out | 4078 ms | 4720 KB | Time limit exceeded |
55 | Halted | 0 ms | 0 KB | - |