# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569022 | 2022-05-26T13:35:33 Z | nonsensenonsense1 | Fish 2 (JOI22_fish2) | C++17 | 1626 ms | 32548 KB |
#include <cstdio> #include <vector> #include <cstring> #include <utility> #include <algorithm> const int N = 100005; int n, q, a[N]; struct info { int cnt, need; long long sum; }; struct item { std::vector<info> pref, suf; item() {} item(int x) { pref.push_back({1, x, x}); suf.push_back(pref.back()); } } t[N * 2]; item operator+(item a, item b) { if (a.pref.empty()) return b; if (b.pref.empty()) return a; item res; res.pref = a.pref; res.pref.back().cnt = 0; int i; for (i = 0; i < b.pref.size(); ++i) { if (b.pref[i].need <= res.pref.back().sum) res.pref.back().sum = b.pref[i].sum + a.pref.back().sum; else { res.pref.push_back(b.pref[i]); res.pref.back().sum += a.pref.back().sum; res.pref.back().cnt = 0; } } res.suf = b.suf; res.suf.back().cnt = 0; for (i = 0; i < a.suf.size(); ++i) { if (a.suf[i].need <= res.suf.back().sum) res.suf.back().sum = a.suf[i].sum + b.pref.back().sum; else { res.suf.push_back(a.suf[i]); res.suf.back().sum += b.pref.back().sum; res.suf.back().cnt = 0; } } for (int t = 0; t < 2; ++t) { for (int i = 0;; ++i) { int j, k, amt; long long s; if (t) { if (i == a.suf.size()) break; s = a.suf[i].sum; j = i + 1; k = 0; amt = a.suf[i].cnt; } else { if (i == b.pref.size()) break; s = b.pref[i].sum; j = 0; k = i + 1; amt = b.pref[i].cnt; } while (true) { if (j < a.suf.size() && s >= a.suf[j].need) { s += a.suf[j].sum - (j ? a.suf[j - 1].sum : 0); ++j; } else if (k < b.pref.size() && s >= b.pref[k].need) { s += b.pref[k].sum - (k ? b.pref[k - 1].sum : 0); ++k; } else break; } if (j == a.suf.size()) { if (k == b.pref.size()) { res.pref.back().cnt += amt; res.suf.back().cnt += amt; } else { int l; for (l = 0; res.pref[l].need != b.pref[k].need; ++l); res.pref[l - 1].cnt += amt; } } else if (k == b.pref.size()) { int l; for (l = 0; res.suf[l].need != a.suf[j].need; ++l); res.suf[l - 1].cnt += amt; } } } return res; } void build(int v = 0, int tl = 0, int tr = n) { if (tr - tl == 1) t[v] = item(a[tl]); else { int m = tl + tr >> 1; build(v + 1, tl, m); build(v + (tr - tl & ~1), m, tr); t[v] = t[v + 1] + t[v + (tr - tl & ~1)]; } } void update(int i, int x, int v = 0, int tl = 0, int tr = n) { if (tr - tl == 1) t[v] = item(x); else { int m = tl + tr >> 1; if (i < m) update(i, x, v + 1, tl, m); else update(i, x, v + (tr - tl & ~1), m, tr); t[v] = t[v + 1] + t[v + (tr - tl & ~1)]; } } item query(int l, int r, int v = 0, int tl = 0, int tr = n) { if (tl >= r || tr <= l) return item(); if (tl >= l && tr <= r) return t[v]; int m = tl + tr >> 1; return query(l, r, v + 1, tl, m) + query(l, r, v + (tr - tl & ~1), m, tr); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", a + i); build(); scanf("%d", &q); while (q--) { int type; scanf("%d", &type); if (type == 1) { int i, x; scanf("%d%d", &i, &x); update(i - 1, x); } else { int l, r; scanf("%d%d", &l, &r); printf("%d\n", query(l - 1, r).pref.back().cnt); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9604 KB | Output is correct |
3 | Correct | 5 ms | 9684 KB | Output is correct |
4 | Correct | 5 ms | 9692 KB | Output is correct |
5 | Correct | 9 ms | 9812 KB | Output is correct |
6 | Correct | 7 ms | 9816 KB | Output is correct |
7 | Correct | 8 ms | 9780 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 8 ms | 9684 KB | Output is correct |
11 | Correct | 7 ms | 9776 KB | Output is correct |
12 | Correct | 8 ms | 9700 KB | Output is correct |
13 | Correct | 7 ms | 9684 KB | Output is correct |
14 | Correct | 10 ms | 9812 KB | Output is correct |
15 | Correct | 7 ms | 9696 KB | Output is correct |
16 | Correct | 9 ms | 9684 KB | Output is correct |
17 | Correct | 7 ms | 9684 KB | Output is correct |
18 | Correct | 7 ms | 9684 KB | Output is correct |
19 | Correct | 7 ms | 9696 KB | Output is correct |
20 | Correct | 7 ms | 9684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9684 KB | Output is correct |
2 | Correct | 65 ms | 29656 KB | Output is correct |
3 | Correct | 74 ms | 28776 KB | Output is correct |
4 | Correct | 74 ms | 30176 KB | Output is correct |
5 | Correct | 71 ms | 28940 KB | Output is correct |
6 | Correct | 62 ms | 25624 KB | Output is correct |
7 | Correct | 59 ms | 24992 KB | Output is correct |
8 | Correct | 63 ms | 25516 KB | Output is correct |
9 | Correct | 59 ms | 24964 KB | Output is correct |
10 | Correct | 71 ms | 30376 KB | Output is correct |
11 | Correct | 64 ms | 27716 KB | Output is correct |
12 | Correct | 58 ms | 24692 KB | Output is correct |
13 | Correct | 59 ms | 24684 KB | Output is correct |
14 | Correct | 68 ms | 25912 KB | Output is correct |
15 | Correct | 81 ms | 26204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9604 KB | Output is correct |
3 | Correct | 5 ms | 9684 KB | Output is correct |
4 | Correct | 5 ms | 9692 KB | Output is correct |
5 | Correct | 9 ms | 9812 KB | Output is correct |
6 | Correct | 7 ms | 9816 KB | Output is correct |
7 | Correct | 8 ms | 9780 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 8 ms | 9684 KB | Output is correct |
11 | Correct | 7 ms | 9776 KB | Output is correct |
12 | Correct | 8 ms | 9700 KB | Output is correct |
13 | Correct | 7 ms | 9684 KB | Output is correct |
14 | Correct | 10 ms | 9812 KB | Output is correct |
15 | Correct | 7 ms | 9696 KB | Output is correct |
16 | Correct | 9 ms | 9684 KB | Output is correct |
17 | Correct | 7 ms | 9684 KB | Output is correct |
18 | Correct | 7 ms | 9684 KB | Output is correct |
19 | Correct | 7 ms | 9696 KB | Output is correct |
20 | Correct | 7 ms | 9684 KB | Output is correct |
21 | Correct | 5 ms | 9684 KB | Output is correct |
22 | Correct | 65 ms | 29656 KB | Output is correct |
23 | Correct | 74 ms | 28776 KB | Output is correct |
24 | Correct | 74 ms | 30176 KB | Output is correct |
25 | Correct | 71 ms | 28940 KB | Output is correct |
26 | Correct | 62 ms | 25624 KB | Output is correct |
27 | Correct | 59 ms | 24992 KB | Output is correct |
28 | Correct | 63 ms | 25516 KB | Output is correct |
29 | Correct | 59 ms | 24964 KB | Output is correct |
30 | Correct | 71 ms | 30376 KB | Output is correct |
31 | Correct | 64 ms | 27716 KB | Output is correct |
32 | Correct | 58 ms | 24692 KB | Output is correct |
33 | Correct | 59 ms | 24684 KB | Output is correct |
34 | Correct | 68 ms | 25912 KB | Output is correct |
35 | Correct | 81 ms | 26204 KB | Output is correct |
36 | Correct | 83 ms | 30284 KB | Output is correct |
37 | Correct | 90 ms | 28952 KB | Output is correct |
38 | Correct | 85 ms | 28876 KB | Output is correct |
39 | Correct | 84 ms | 30308 KB | Output is correct |
40 | Correct | 80 ms | 28892 KB | Output is correct |
41 | Correct | 69 ms | 25588 KB | Output is correct |
42 | Correct | 73 ms | 25576 KB | Output is correct |
43 | Correct | 68 ms | 25100 KB | Output is correct |
44 | Correct | 74 ms | 24964 KB | Output is correct |
45 | Correct | 97 ms | 30540 KB | Output is correct |
46 | Correct | 98 ms | 30560 KB | Output is correct |
47 | Correct | 78 ms | 27260 KB | Output is correct |
48 | Correct | 75 ms | 24912 KB | Output is correct |
49 | Correct | 67 ms | 24780 KB | Output is correct |
50 | Correct | 70 ms | 25908 KB | Output is correct |
51 | Correct | 73 ms | 26232 KB | Output is correct |
52 | Correct | 69 ms | 25880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9684 KB | Output is correct |
2 | Correct | 65 ms | 29656 KB | Output is correct |
3 | Correct | 74 ms | 28776 KB | Output is correct |
4 | Correct | 74 ms | 30176 KB | Output is correct |
5 | Correct | 71 ms | 28940 KB | Output is correct |
6 | Correct | 62 ms | 25624 KB | Output is correct |
7 | Correct | 59 ms | 24992 KB | Output is correct |
8 | Correct | 63 ms | 25516 KB | Output is correct |
9 | Correct | 59 ms | 24964 KB | Output is correct |
10 | Correct | 71 ms | 30376 KB | Output is correct |
11 | Correct | 64 ms | 27716 KB | Output is correct |
12 | Correct | 58 ms | 24692 KB | Output is correct |
13 | Correct | 59 ms | 24684 KB | Output is correct |
14 | Correct | 68 ms | 25912 KB | Output is correct |
15 | Correct | 81 ms | 26204 KB | Output is correct |
16 | Correct | 5 ms | 9588 KB | Output is correct |
17 | Correct | 1224 ms | 30672 KB | Output is correct |
18 | Correct | 924 ms | 32080 KB | Output is correct |
19 | Correct | 1127 ms | 30740 KB | Output is correct |
20 | Correct | 1207 ms | 30776 KB | Output is correct |
21 | Correct | 1252 ms | 30764 KB | Output is correct |
22 | Correct | 1008 ms | 32144 KB | Output is correct |
23 | Correct | 1213 ms | 30616 KB | Output is correct |
24 | Correct | 1105 ms | 30560 KB | Output is correct |
25 | Correct | 1134 ms | 30652 KB | Output is correct |
26 | Correct | 1180 ms | 30616 KB | Output is correct |
27 | Correct | 654 ms | 27456 KB | Output is correct |
28 | Correct | 655 ms | 27392 KB | Output is correct |
29 | Correct | 653 ms | 27540 KB | Output is correct |
30 | Correct | 883 ms | 26592 KB | Output is correct |
31 | Correct | 942 ms | 26472 KB | Output is correct |
32 | Correct | 1294 ms | 29296 KB | Output is correct |
33 | Correct | 1405 ms | 32548 KB | Output is correct |
34 | Correct | 1239 ms | 29092 KB | Output is correct |
35 | Correct | 1336 ms | 28700 KB | Output is correct |
36 | Correct | 1361 ms | 32324 KB | Output is correct |
37 | Correct | 576 ms | 26260 KB | Output is correct |
38 | Correct | 625 ms | 26232 KB | Output is correct |
39 | Correct | 636 ms | 27680 KB | Output is correct |
40 | Correct | 736 ms | 27976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9684 KB | Output is correct |
2 | Correct | 65 ms | 29656 KB | Output is correct |
3 | Correct | 74 ms | 28776 KB | Output is correct |
4 | Correct | 74 ms | 30176 KB | Output is correct |
5 | Correct | 71 ms | 28940 KB | Output is correct |
6 | Correct | 62 ms | 25624 KB | Output is correct |
7 | Correct | 59 ms | 24992 KB | Output is correct |
8 | Correct | 63 ms | 25516 KB | Output is correct |
9 | Correct | 59 ms | 24964 KB | Output is correct |
10 | Correct | 71 ms | 30376 KB | Output is correct |
11 | Correct | 64 ms | 27716 KB | Output is correct |
12 | Correct | 58 ms | 24692 KB | Output is correct |
13 | Correct | 59 ms | 24684 KB | Output is correct |
14 | Correct | 68 ms | 25912 KB | Output is correct |
15 | Correct | 81 ms | 26204 KB | Output is correct |
16 | Correct | 6 ms | 9684 KB | Output is correct |
17 | Correct | 1269 ms | 31320 KB | Output is correct |
18 | Correct | 923 ms | 30872 KB | Output is correct |
19 | Correct | 1002 ms | 30160 KB | Output is correct |
20 | Correct | 737 ms | 30832 KB | Output is correct |
21 | Correct | 1252 ms | 31344 KB | Output is correct |
22 | Correct | 939 ms | 30796 KB | Output is correct |
23 | Correct | 1158 ms | 30192 KB | Output is correct |
24 | Correct | 945 ms | 30892 KB | Output is correct |
25 | Correct | 1059 ms | 30148 KB | Output is correct |
26 | Correct | 633 ms | 27340 KB | Output is correct |
27 | Correct | 805 ms | 27384 KB | Output is correct |
28 | Correct | 660 ms | 27960 KB | Output is correct |
29 | Correct | 668 ms | 27512 KB | Output is correct |
30 | Correct | 850 ms | 27236 KB | Output is correct |
31 | Correct | 770 ms | 28028 KB | Output is correct |
32 | Correct | 1008 ms | 29704 KB | Output is correct |
33 | Correct | 1237 ms | 29020 KB | Output is correct |
34 | Correct | 967 ms | 32160 KB | Output is correct |
35 | Correct | 1221 ms | 31996 KB | Output is correct |
36 | Correct | 832 ms | 29324 KB | Output is correct |
37 | Correct | 809 ms | 28088 KB | Output is correct |
38 | Correct | 517 ms | 27968 KB | Output is correct |
39 | Correct | 646 ms | 27980 KB | Output is correct |
40 | Correct | 299 ms | 27992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9604 KB | Output is correct |
3 | Correct | 5 ms | 9684 KB | Output is correct |
4 | Correct | 5 ms | 9692 KB | Output is correct |
5 | Correct | 9 ms | 9812 KB | Output is correct |
6 | Correct | 7 ms | 9816 KB | Output is correct |
7 | Correct | 8 ms | 9780 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 8 ms | 9684 KB | Output is correct |
11 | Correct | 7 ms | 9776 KB | Output is correct |
12 | Correct | 8 ms | 9700 KB | Output is correct |
13 | Correct | 7 ms | 9684 KB | Output is correct |
14 | Correct | 10 ms | 9812 KB | Output is correct |
15 | Correct | 7 ms | 9696 KB | Output is correct |
16 | Correct | 9 ms | 9684 KB | Output is correct |
17 | Correct | 7 ms | 9684 KB | Output is correct |
18 | Correct | 7 ms | 9684 KB | Output is correct |
19 | Correct | 7 ms | 9696 KB | Output is correct |
20 | Correct | 7 ms | 9684 KB | Output is correct |
21 | Correct | 5 ms | 9684 KB | Output is correct |
22 | Correct | 65 ms | 29656 KB | Output is correct |
23 | Correct | 74 ms | 28776 KB | Output is correct |
24 | Correct | 74 ms | 30176 KB | Output is correct |
25 | Correct | 71 ms | 28940 KB | Output is correct |
26 | Correct | 62 ms | 25624 KB | Output is correct |
27 | Correct | 59 ms | 24992 KB | Output is correct |
28 | Correct | 63 ms | 25516 KB | Output is correct |
29 | Correct | 59 ms | 24964 KB | Output is correct |
30 | Correct | 71 ms | 30376 KB | Output is correct |
31 | Correct | 64 ms | 27716 KB | Output is correct |
32 | Correct | 58 ms | 24692 KB | Output is correct |
33 | Correct | 59 ms | 24684 KB | Output is correct |
34 | Correct | 68 ms | 25912 KB | Output is correct |
35 | Correct | 81 ms | 26204 KB | Output is correct |
36 | Correct | 83 ms | 30284 KB | Output is correct |
37 | Correct | 90 ms | 28952 KB | Output is correct |
38 | Correct | 85 ms | 28876 KB | Output is correct |
39 | Correct | 84 ms | 30308 KB | Output is correct |
40 | Correct | 80 ms | 28892 KB | Output is correct |
41 | Correct | 69 ms | 25588 KB | Output is correct |
42 | Correct | 73 ms | 25576 KB | Output is correct |
43 | Correct | 68 ms | 25100 KB | Output is correct |
44 | Correct | 74 ms | 24964 KB | Output is correct |
45 | Correct | 97 ms | 30540 KB | Output is correct |
46 | Correct | 98 ms | 30560 KB | Output is correct |
47 | Correct | 78 ms | 27260 KB | Output is correct |
48 | Correct | 75 ms | 24912 KB | Output is correct |
49 | Correct | 67 ms | 24780 KB | Output is correct |
50 | Correct | 70 ms | 25908 KB | Output is correct |
51 | Correct | 73 ms | 26232 KB | Output is correct |
52 | Correct | 69 ms | 25880 KB | Output is correct |
53 | Correct | 5 ms | 9588 KB | Output is correct |
54 | Correct | 1224 ms | 30672 KB | Output is correct |
55 | Correct | 924 ms | 32080 KB | Output is correct |
56 | Correct | 1127 ms | 30740 KB | Output is correct |
57 | Correct | 1207 ms | 30776 KB | Output is correct |
58 | Correct | 1252 ms | 30764 KB | Output is correct |
59 | Correct | 1008 ms | 32144 KB | Output is correct |
60 | Correct | 1213 ms | 30616 KB | Output is correct |
61 | Correct | 1105 ms | 30560 KB | Output is correct |
62 | Correct | 1134 ms | 30652 KB | Output is correct |
63 | Correct | 1180 ms | 30616 KB | Output is correct |
64 | Correct | 654 ms | 27456 KB | Output is correct |
65 | Correct | 655 ms | 27392 KB | Output is correct |
66 | Correct | 653 ms | 27540 KB | Output is correct |
67 | Correct | 883 ms | 26592 KB | Output is correct |
68 | Correct | 942 ms | 26472 KB | Output is correct |
69 | Correct | 1294 ms | 29296 KB | Output is correct |
70 | Correct | 1405 ms | 32548 KB | Output is correct |
71 | Correct | 1239 ms | 29092 KB | Output is correct |
72 | Correct | 1336 ms | 28700 KB | Output is correct |
73 | Correct | 1361 ms | 32324 KB | Output is correct |
74 | Correct | 576 ms | 26260 KB | Output is correct |
75 | Correct | 625 ms | 26232 KB | Output is correct |
76 | Correct | 636 ms | 27680 KB | Output is correct |
77 | Correct | 736 ms | 27976 KB | Output is correct |
78 | Correct | 6 ms | 9684 KB | Output is correct |
79 | Correct | 1269 ms | 31320 KB | Output is correct |
80 | Correct | 923 ms | 30872 KB | Output is correct |
81 | Correct | 1002 ms | 30160 KB | Output is correct |
82 | Correct | 737 ms | 30832 KB | Output is correct |
83 | Correct | 1252 ms | 31344 KB | Output is correct |
84 | Correct | 939 ms | 30796 KB | Output is correct |
85 | Correct | 1158 ms | 30192 KB | Output is correct |
86 | Correct | 945 ms | 30892 KB | Output is correct |
87 | Correct | 1059 ms | 30148 KB | Output is correct |
88 | Correct | 633 ms | 27340 KB | Output is correct |
89 | Correct | 805 ms | 27384 KB | Output is correct |
90 | Correct | 660 ms | 27960 KB | Output is correct |
91 | Correct | 668 ms | 27512 KB | Output is correct |
92 | Correct | 850 ms | 27236 KB | Output is correct |
93 | Correct | 770 ms | 28028 KB | Output is correct |
94 | Correct | 1008 ms | 29704 KB | Output is correct |
95 | Correct | 1237 ms | 29020 KB | Output is correct |
96 | Correct | 967 ms | 32160 KB | Output is correct |
97 | Correct | 1221 ms | 31996 KB | Output is correct |
98 | Correct | 832 ms | 29324 KB | Output is correct |
99 | Correct | 809 ms | 28088 KB | Output is correct |
100 | Correct | 517 ms | 27968 KB | Output is correct |
101 | Correct | 646 ms | 27980 KB | Output is correct |
102 | Correct | 299 ms | 27992 KB | Output is correct |
103 | Correct | 1401 ms | 30060 KB | Output is correct |
104 | Correct | 1008 ms | 32020 KB | Output is correct |
105 | Correct | 1368 ms | 30772 KB | Output is correct |
106 | Correct | 951 ms | 30760 KB | Output is correct |
107 | Correct | 1531 ms | 30340 KB | Output is correct |
108 | Correct | 1118 ms | 31948 KB | Output is correct |
109 | Correct | 1286 ms | 30492 KB | Output is correct |
110 | Correct | 1070 ms | 31092 KB | Output is correct |
111 | Correct | 1281 ms | 30684 KB | Output is correct |
112 | Correct | 988 ms | 30700 KB | Output is correct |
113 | Correct | 791 ms | 27428 KB | Output is correct |
114 | Correct | 667 ms | 27456 KB | Output is correct |
115 | Correct | 927 ms | 28048 KB | Output is correct |
116 | Correct | 1002 ms | 27996 KB | Output is correct |
117 | Correct | 658 ms | 27504 KB | Output is correct |
118 | Correct | 835 ms | 27848 KB | Output is correct |
119 | Correct | 841 ms | 27512 KB | Output is correct |
120 | Correct | 913 ms | 28072 KB | Output is correct |
121 | Correct | 857 ms | 27964 KB | Output is correct |
122 | Correct | 1052 ms | 29728 KB | Output is correct |
123 | Correct | 1626 ms | 29180 KB | Output is correct |
124 | Correct | 940 ms | 28776 KB | Output is correct |
125 | Correct | 1301 ms | 26816 KB | Output is correct |
126 | Correct | 964 ms | 27216 KB | Output is correct |
127 | Correct | 930 ms | 26692 KB | Output is correct |
128 | Correct | 662 ms | 27396 KB | Output is correct |
129 | Correct | 867 ms | 28148 KB | Output is correct |
130 | Correct | 792 ms | 28156 KB | Output is correct |