# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
587031 |
2022-07-01T08:28:38 Z |
8e7 |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4888 KB |
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int a[maxn], b[maxn], lef[maxn], rig[maxn];
int lc[maxn], rc[maxn], cnt[maxn];
ll pref[maxn];
void dfs(int n, int par) {
if (lc[n] != -1) dfs(lc[n], n);
if (rc[n] != -1) dfs(rc[n], n);
ll sum = pref[rig[n]] - (lef[n] ? pref[lef[n]-1] : 0);
if (sum >= b[par]) cnt[n] = 1 + cnt[lc[n]] + cnt[rc[n]];
else cnt[n] = 0;
}
int main() {
io
int n, q;
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int x, y;
cin >> x >> y;
a[x] = y;
} else {
int l, r;
cin >> l >> r;
int s = r - l + 1;
for (int i = l;i <= r;i++) b[i-l] = a[i];
for (int i = 0;i < s;i++) {
pref[i] = b[i] + (i ? pref[i-1] : 0);
cnt[i] = 0;
rig[i] = s-1;
lef[i] = 0;
lc[i] = rc[i] = -1;
}
stack<int> stk;
for (int i = 0;i < s;i++) {
while (stk.size() && b[i] >= b[stk.top()]) {
lc[i] = stk.top();
rig[stk.top()] = i-1;
stk.pop();
}
if (stk.size()) {
rc[stk.top()] = i;
lef[i] = stk.top()+1;
}
stk.push(i);
}
while (stk.size() > 1) stk.pop();
int root = stk.top();
dfs(root, root);
cout << cnt[root] << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
3844 KB |
Output is correct |
3 |
Correct |
11 ms |
3928 KB |
Output is correct |
4 |
Correct |
12 ms |
3784 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
14 ms |
3796 KB |
Output is correct |
7 |
Correct |
9 ms |
3796 KB |
Output is correct |
8 |
Correct |
17 ms |
3848 KB |
Output is correct |
9 |
Correct |
9 ms |
3796 KB |
Output is correct |
10 |
Correct |
12 ms |
3740 KB |
Output is correct |
11 |
Correct |
12 ms |
3720 KB |
Output is correct |
12 |
Correct |
11 ms |
3840 KB |
Output is correct |
13 |
Correct |
11 ms |
3796 KB |
Output is correct |
14 |
Correct |
13 ms |
4052 KB |
Output is correct |
15 |
Correct |
14 ms |
4052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
12 ms |
3844 KB |
Output is correct |
23 |
Correct |
11 ms |
3928 KB |
Output is correct |
24 |
Correct |
12 ms |
3784 KB |
Output is correct |
25 |
Correct |
9 ms |
3796 KB |
Output is correct |
26 |
Correct |
14 ms |
3796 KB |
Output is correct |
27 |
Correct |
9 ms |
3796 KB |
Output is correct |
28 |
Correct |
17 ms |
3848 KB |
Output is correct |
29 |
Correct |
9 ms |
3796 KB |
Output is correct |
30 |
Correct |
12 ms |
3740 KB |
Output is correct |
31 |
Correct |
12 ms |
3720 KB |
Output is correct |
32 |
Correct |
11 ms |
3840 KB |
Output is correct |
33 |
Correct |
11 ms |
3796 KB |
Output is correct |
34 |
Correct |
13 ms |
4052 KB |
Output is correct |
35 |
Correct |
14 ms |
4052 KB |
Output is correct |
36 |
Correct |
344 ms |
4468 KB |
Output is correct |
37 |
Correct |
540 ms |
3948 KB |
Output is correct |
38 |
Correct |
633 ms |
3980 KB |
Output is correct |
39 |
Correct |
144 ms |
4232 KB |
Output is correct |
40 |
Correct |
721 ms |
4080 KB |
Output is correct |
41 |
Correct |
782 ms |
4740 KB |
Output is correct |
42 |
Correct |
968 ms |
4820 KB |
Output is correct |
43 |
Correct |
775 ms |
3868 KB |
Output is correct |
44 |
Correct |
916 ms |
3936 KB |
Output is correct |
45 |
Correct |
400 ms |
4388 KB |
Output is correct |
46 |
Correct |
556 ms |
4364 KB |
Output is correct |
47 |
Correct |
771 ms |
4128 KB |
Output is correct |
48 |
Correct |
307 ms |
4004 KB |
Output is correct |
49 |
Correct |
993 ms |
4144 KB |
Output is correct |
50 |
Correct |
459 ms |
4608 KB |
Output is correct |
51 |
Correct |
2075 ms |
4888 KB |
Output is correct |
52 |
Correct |
2283 ms |
4680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
3844 KB |
Output is correct |
3 |
Correct |
11 ms |
3928 KB |
Output is correct |
4 |
Correct |
12 ms |
3784 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
14 ms |
3796 KB |
Output is correct |
7 |
Correct |
9 ms |
3796 KB |
Output is correct |
8 |
Correct |
17 ms |
3848 KB |
Output is correct |
9 |
Correct |
9 ms |
3796 KB |
Output is correct |
10 |
Correct |
12 ms |
3740 KB |
Output is correct |
11 |
Correct |
12 ms |
3720 KB |
Output is correct |
12 |
Correct |
11 ms |
3840 KB |
Output is correct |
13 |
Correct |
11 ms |
3796 KB |
Output is correct |
14 |
Correct |
13 ms |
4052 KB |
Output is correct |
15 |
Correct |
14 ms |
4052 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Execution timed out |
4065 ms |
3852 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
12 ms |
3844 KB |
Output is correct |
3 |
Correct |
11 ms |
3928 KB |
Output is correct |
4 |
Correct |
12 ms |
3784 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
14 ms |
3796 KB |
Output is correct |
7 |
Correct |
9 ms |
3796 KB |
Output is correct |
8 |
Correct |
17 ms |
3848 KB |
Output is correct |
9 |
Correct |
9 ms |
3796 KB |
Output is correct |
10 |
Correct |
12 ms |
3740 KB |
Output is correct |
11 |
Correct |
12 ms |
3720 KB |
Output is correct |
12 |
Correct |
11 ms |
3840 KB |
Output is correct |
13 |
Correct |
11 ms |
3796 KB |
Output is correct |
14 |
Correct |
13 ms |
4052 KB |
Output is correct |
15 |
Correct |
14 ms |
4052 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Execution timed out |
4075 ms |
3828 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
12 ms |
3844 KB |
Output is correct |
23 |
Correct |
11 ms |
3928 KB |
Output is correct |
24 |
Correct |
12 ms |
3784 KB |
Output is correct |
25 |
Correct |
9 ms |
3796 KB |
Output is correct |
26 |
Correct |
14 ms |
3796 KB |
Output is correct |
27 |
Correct |
9 ms |
3796 KB |
Output is correct |
28 |
Correct |
17 ms |
3848 KB |
Output is correct |
29 |
Correct |
9 ms |
3796 KB |
Output is correct |
30 |
Correct |
12 ms |
3740 KB |
Output is correct |
31 |
Correct |
12 ms |
3720 KB |
Output is correct |
32 |
Correct |
11 ms |
3840 KB |
Output is correct |
33 |
Correct |
11 ms |
3796 KB |
Output is correct |
34 |
Correct |
13 ms |
4052 KB |
Output is correct |
35 |
Correct |
14 ms |
4052 KB |
Output is correct |
36 |
Correct |
344 ms |
4468 KB |
Output is correct |
37 |
Correct |
540 ms |
3948 KB |
Output is correct |
38 |
Correct |
633 ms |
3980 KB |
Output is correct |
39 |
Correct |
144 ms |
4232 KB |
Output is correct |
40 |
Correct |
721 ms |
4080 KB |
Output is correct |
41 |
Correct |
782 ms |
4740 KB |
Output is correct |
42 |
Correct |
968 ms |
4820 KB |
Output is correct |
43 |
Correct |
775 ms |
3868 KB |
Output is correct |
44 |
Correct |
916 ms |
3936 KB |
Output is correct |
45 |
Correct |
400 ms |
4388 KB |
Output is correct |
46 |
Correct |
556 ms |
4364 KB |
Output is correct |
47 |
Correct |
771 ms |
4128 KB |
Output is correct |
48 |
Correct |
307 ms |
4004 KB |
Output is correct |
49 |
Correct |
993 ms |
4144 KB |
Output is correct |
50 |
Correct |
459 ms |
4608 KB |
Output is correct |
51 |
Correct |
2075 ms |
4888 KB |
Output is correct |
52 |
Correct |
2283 ms |
4680 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Execution timed out |
4065 ms |
3852 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |