# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1013048 |
2024-07-03T06:32:58 Z |
12345678 |
Fish 2 (JOI22_fish2) |
C++17 |
|
11 ms |
5212 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll n, q, t, x, y, a[nx], l[nx], r[nx], sm[nx], rt, dp[nx], res;
void dfs(int u)
{
sm[u]=a[u];
if (l[u]) dfs(l[u]), sm[u]+=sm[l[u]];
if (r[u]) dfs(r[u]), sm[u]+=sm[r[u]];
}
void dfs2(int u)
{
if (l[u]&&sm[l[u]]>=a[u]) dp[l[u]]=1, dfs2(l[u]);
if (r[u]&&sm[r[u]]>=a[u]) dp[r[u]]=1, dfs2(r[u]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i];
cin>>q>>t>>x>>y;
stack<ll> s;
for (int i=1; i<=n; i++)
{
while (!s.empty()&&a[s.top()]<a[i]) l[i]=s.top(), s.pop();
if (s.empty()) rt=i;
else r[s.top()]=i;
s.push(i);
}
//cout<<"rt "<<rt<<'\n';
//for (int i=1; i<=n;i ++) cout<<i<<' '<<l[i]<<' '<<r[i]<<'\n';
dfs(rt);
dp[rt]=1;
dfs2(rt);
for (int i=1; i<=n; i++) res+=dp[i];
cout<<res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
4844 KB |
Output is correct |
3 |
Correct |
9 ms |
4444 KB |
Output is correct |
4 |
Correct |
7 ms |
4700 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
6 |
Correct |
11 ms |
5212 KB |
Output is correct |
7 |
Correct |
6 ms |
3644 KB |
Output is correct |
8 |
Correct |
11 ms |
5208 KB |
Output is correct |
9 |
Correct |
6 ms |
3672 KB |
Output is correct |
10 |
Correct |
8 ms |
4956 KB |
Output is correct |
11 |
Correct |
6 ms |
4208 KB |
Output is correct |
12 |
Correct |
7 ms |
3928 KB |
Output is correct |
13 |
Correct |
7 ms |
3932 KB |
Output is correct |
14 |
Correct |
9 ms |
4956 KB |
Output is correct |
15 |
Correct |
9 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
4844 KB |
Output is correct |
3 |
Correct |
9 ms |
4444 KB |
Output is correct |
4 |
Correct |
7 ms |
4700 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
6 |
Correct |
11 ms |
5212 KB |
Output is correct |
7 |
Correct |
6 ms |
3644 KB |
Output is correct |
8 |
Correct |
11 ms |
5208 KB |
Output is correct |
9 |
Correct |
6 ms |
3672 KB |
Output is correct |
10 |
Correct |
8 ms |
4956 KB |
Output is correct |
11 |
Correct |
6 ms |
4208 KB |
Output is correct |
12 |
Correct |
7 ms |
3928 KB |
Output is correct |
13 |
Correct |
7 ms |
3932 KB |
Output is correct |
14 |
Correct |
9 ms |
4956 KB |
Output is correct |
15 |
Correct |
9 ms |
5096 KB |
Output is correct |
16 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
4844 KB |
Output is correct |
3 |
Correct |
9 ms |
4444 KB |
Output is correct |
4 |
Correct |
7 ms |
4700 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
6 |
Correct |
11 ms |
5212 KB |
Output is correct |
7 |
Correct |
6 ms |
3644 KB |
Output is correct |
8 |
Correct |
11 ms |
5208 KB |
Output is correct |
9 |
Correct |
6 ms |
3672 KB |
Output is correct |
10 |
Correct |
8 ms |
4956 KB |
Output is correct |
11 |
Correct |
6 ms |
4208 KB |
Output is correct |
12 |
Correct |
7 ms |
3928 KB |
Output is correct |
13 |
Correct |
7 ms |
3932 KB |
Output is correct |
14 |
Correct |
9 ms |
4956 KB |
Output is correct |
15 |
Correct |
9 ms |
5096 KB |
Output is correct |
16 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |