# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
587030 |
2022-07-01T08:24:53 Z |
8e7 |
Fish 2 (JOI22_fish2) |
C++17 |
|
4000 ms |
4836 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;
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 |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
13 ms |
4284 KB |
Output is correct |
3 |
Correct |
13 ms |
4164 KB |
Output is correct |
4 |
Correct |
13 ms |
4312 KB |
Output is correct |
5 |
Correct |
11 ms |
4060 KB |
Output is correct |
6 |
Correct |
15 ms |
4720 KB |
Output is correct |
7 |
Correct |
9 ms |
4056 KB |
Output is correct |
8 |
Correct |
14 ms |
4760 KB |
Output is correct |
9 |
Correct |
11 ms |
4052 KB |
Output is correct |
10 |
Correct |
12 ms |
4308 KB |
Output is correct |
11 |
Correct |
10 ms |
4060 KB |
Output is correct |
12 |
Correct |
10 ms |
4052 KB |
Output is correct |
13 |
Correct |
10 ms |
4052 KB |
Output is correct |
14 |
Correct |
15 ms |
4692 KB |
Output is correct |
15 |
Correct |
12 ms |
4612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
13 ms |
4284 KB |
Output is correct |
3 |
Correct |
13 ms |
4164 KB |
Output is correct |
4 |
Correct |
13 ms |
4312 KB |
Output is correct |
5 |
Correct |
11 ms |
4060 KB |
Output is correct |
6 |
Correct |
15 ms |
4720 KB |
Output is correct |
7 |
Correct |
9 ms |
4056 KB |
Output is correct |
8 |
Correct |
14 ms |
4760 KB |
Output is correct |
9 |
Correct |
11 ms |
4052 KB |
Output is correct |
10 |
Correct |
12 ms |
4308 KB |
Output is correct |
11 |
Correct |
10 ms |
4060 KB |
Output is correct |
12 |
Correct |
10 ms |
4052 KB |
Output is correct |
13 |
Correct |
10 ms |
4052 KB |
Output is correct |
14 |
Correct |
15 ms |
4692 KB |
Output is correct |
15 |
Correct |
12 ms |
4612 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Execution timed out |
4070 ms |
4456 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
13 ms |
4284 KB |
Output is correct |
3 |
Correct |
13 ms |
4164 KB |
Output is correct |
4 |
Correct |
13 ms |
4312 KB |
Output is correct |
5 |
Correct |
11 ms |
4060 KB |
Output is correct |
6 |
Correct |
15 ms |
4720 KB |
Output is correct |
7 |
Correct |
9 ms |
4056 KB |
Output is correct |
8 |
Correct |
14 ms |
4760 KB |
Output is correct |
9 |
Correct |
11 ms |
4052 KB |
Output is correct |
10 |
Correct |
12 ms |
4308 KB |
Output is correct |
11 |
Correct |
10 ms |
4060 KB |
Output is correct |
12 |
Correct |
10 ms |
4052 KB |
Output is correct |
13 |
Correct |
10 ms |
4052 KB |
Output is correct |
14 |
Correct |
15 ms |
4692 KB |
Output is correct |
15 |
Correct |
12 ms |
4612 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Execution timed out |
4062 ms |
4836 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |