# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
950976 | 2024-03-21T03:23:14 Z | VinhLuu | Cat Exercise (JOI23_ho_t4) | C++17 | 100 ms | 29264 KB |
#include <bits/stdc++.h> #define int long long #define pb push_back using namespace std; const int N = 2e5 + 5; int n, a[N]; vector<int> p[N]; namespace sub3{ int st[N << 1]; int get(int l,int r){ r++; int ret = 0; for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){ if(l & 1){ if(a[ret] < a[st[l]]) ret = st[l]; l++; } if(r & 1){ --r; if(a[ret] < a[st[r]]) ret = st[r]; } } return ret; } int dq(int l,int r){ if(l > r) return 0; int u = get(l, r); int L = (u == l ? 0 : dq(l, u - 1) + u - get(l, u - 1)); int R = (r == u ? 0 : dq(u + 1, r) + get(u + 1, r) - u); return max(L, R); } void solve(){ for(int i = 1; i <= n; i ++){ st[i + n - 1] = i; } for(int i = n - 1; i >= 1; i --){ if(a[st[i << 1]] > a[st[i << 1|1]]) st[i] = st[i << 1]; else st[i] = st[i << 1|1]; } cout << dq(1, n); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "ce" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n; for(int i = 1; i <= n; i ++){ cin >> a[i]; } bool ff = true; for(int i = 1; i < n; i ++){ int x, y; cin >> x >> y; if(y != x + 1) ff = false; p[x].pb(y); p[y].pb(x); } if(ff) sub3 :: solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 2 ms | 6492 KB | Output is correct |
4 | Correct | 2 ms | 6584 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6616 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 2 ms | 6492 KB | Output is correct |
4 | Correct | 2 ms | 6584 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6616 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 2 ms | 6492 KB | Output is correct |
13 | Correct | 2 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6540 KB | Output is correct |
15 | Correct | 2 ms | 6624 KB | Output is correct |
16 | Correct | 1 ms | 6488 KB | Output is correct |
17 | Correct | 2 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 2 ms | 6492 KB | Output is correct |
4 | Correct | 2 ms | 6584 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6616 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 2 ms | 6492 KB | Output is correct |
13 | Correct | 2 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6540 KB | Output is correct |
15 | Correct | 2 ms | 6624 KB | Output is correct |
16 | Correct | 1 ms | 6488 KB | Output is correct |
17 | Correct | 2 ms | 6492 KB | Output is correct |
18 | Correct | 3 ms | 7004 KB | Output is correct |
19 | Correct | 3 ms | 7004 KB | Output is correct |
20 | Correct | 4 ms | 7000 KB | Output is correct |
21 | Correct | 3 ms | 6744 KB | Output is correct |
22 | Correct | 3 ms | 6748 KB | Output is correct |
23 | Correct | 3 ms | 6748 KB | Output is correct |
24 | Correct | 3 ms | 6748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 2 ms | 6492 KB | Output is correct |
4 | Correct | 2 ms | 6584 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6616 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 2 ms | 6492 KB | Output is correct |
13 | Correct | 2 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6540 KB | Output is correct |
15 | Correct | 2 ms | 6624 KB | Output is correct |
16 | Correct | 1 ms | 6488 KB | Output is correct |
17 | Correct | 2 ms | 6492 KB | Output is correct |
18 | Correct | 3 ms | 7004 KB | Output is correct |
19 | Correct | 3 ms | 7004 KB | Output is correct |
20 | Correct | 4 ms | 7000 KB | Output is correct |
21 | Correct | 3 ms | 6744 KB | Output is correct |
22 | Correct | 3 ms | 6748 KB | Output is correct |
23 | Correct | 3 ms | 6748 KB | Output is correct |
24 | Correct | 3 ms | 6748 KB | Output is correct |
25 | Incorrect | 1 ms | 6488 KB | Output isn't correct |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 2 ms | 6492 KB | Output is correct |
4 | Correct | 2 ms | 6584 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6616 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 2 ms | 6492 KB | Output is correct |
13 | Correct | 2 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6540 KB | Output is correct |
15 | Correct | 2 ms | 6624 KB | Output is correct |
16 | Correct | 1 ms | 6488 KB | Output is correct |
17 | Correct | 2 ms | 6492 KB | Output is correct |
18 | Correct | 3 ms | 7004 KB | Output is correct |
19 | Correct | 3 ms | 7004 KB | Output is correct |
20 | Correct | 4 ms | 7000 KB | Output is correct |
21 | Correct | 3 ms | 6744 KB | Output is correct |
22 | Correct | 3 ms | 6748 KB | Output is correct |
23 | Correct | 3 ms | 6748 KB | Output is correct |
24 | Correct | 3 ms | 6748 KB | Output is correct |
25 | Correct | 100 ms | 29264 KB | Output is correct |
26 | Correct | 87 ms | 28368 KB | Output is correct |
27 | Correct | 87 ms | 28184 KB | Output is correct |
28 | Correct | 65 ms | 19864 KB | Output is correct |
29 | Correct | 59 ms | 19868 KB | Output is correct |
30 | Correct | 60 ms | 19792 KB | Output is correct |
31 | Correct | 59 ms | 19792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 6492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 2 ms | 6492 KB | Output is correct |
4 | Correct | 2 ms | 6584 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6616 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 2 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 2 ms | 6492 KB | Output is correct |
13 | Correct | 2 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6540 KB | Output is correct |
15 | Correct | 2 ms | 6624 KB | Output is correct |
16 | Correct | 1 ms | 6488 KB | Output is correct |
17 | Correct | 2 ms | 6492 KB | Output is correct |
18 | Correct | 3 ms | 7004 KB | Output is correct |
19 | Correct | 3 ms | 7004 KB | Output is correct |
20 | Correct | 4 ms | 7000 KB | Output is correct |
21 | Correct | 3 ms | 6744 KB | Output is correct |
22 | Correct | 3 ms | 6748 KB | Output is correct |
23 | Correct | 3 ms | 6748 KB | Output is correct |
24 | Correct | 3 ms | 6748 KB | Output is correct |
25 | Incorrect | 1 ms | 6488 KB | Output isn't correct |
26 | Halted | 0 ms | 0 KB | - |