#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
int v[5005];
void calc(int l, int r, int p, int m){
if(r <= l)return;
int nm = 0;
if(p == 0){
int last = l;
for(int i = l+1; i <= r; i++){
int x = query(l,i);
if(m == 0 && x > nm){//sou min acho max
v[i] = v[l]+x;
nm = x;
calc(last+1,i,1,1);
last = i;
}else if(m == 1 && x > nm){//sou max acho min
v[i] = v[l]-x;
nm = x;
calc(last+1,i,1,0);
last = i;
}
}
if(m == 0)calc(last,r,0,1);
else calc(last,r,0,0);
}else{
int last = r;
for(int i = r-1; i >= l; i--){
int x = query(i,r);
if(m == 0 && x > nm){//sou min acho max
v[i] = v[r]+x;
nm = x;
calc(i,last-1,0,1);
last = i;
}else if(m == 1 && x > nm){//sou max acho min
v[i] = v[r]-x;
nm = x;
calc(i,last-1,0,0);
last = i;
}
}
if(m == 0)calc(l,last,1,1);
else calc(l,last,1,0);
}
}
void solve(int n) {
int l = 1, r = n;
while(l!= r){
int mid = (l+r+1)/2;
if(query(mid,n) == n-1)l = mid;
else r = mid-1;
}
v[l] = 1;
calc(l,n,0,0);
calc(1,l,1,0);
for(int i = 1; i <= n; i++)answer(i,v[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
78 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
62 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
336 KB |
Output is correct |
13 |
Correct |
7 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
336 KB |
Output is correct |
15 |
Correct |
6 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
78 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
62 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
336 KB |
Output is correct |
13 |
Correct |
7 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
336 KB |
Output is correct |
15 |
Correct |
6 ms |
336 KB |
Output is correct |
16 |
Correct |
18 ms |
336 KB |
Output is correct |
17 |
Correct |
45 ms |
336 KB |
Output is correct |
18 |
Correct |
88 ms |
432 KB |
Output is correct |
19 |
Correct |
91 ms |
336 KB |
Output is correct |
20 |
Correct |
84 ms |
436 KB |
Output is correct |
21 |
Correct |
84 ms |
436 KB |
Output is correct |
22 |
Correct |
89 ms |
428 KB |
Output is correct |
23 |
Correct |
17 ms |
592 KB |
Output is correct |
24 |
Incorrect |
177 ms |
504 KB |
Wrong Answer [2] |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
78 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
62 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
336 KB |
Output is correct |
13 |
Correct |
7 ms |
336 KB |
Output is correct |
14 |
Correct |
7 ms |
336 KB |
Output is correct |
15 |
Correct |
6 ms |
336 KB |
Output is correct |
16 |
Correct |
18 ms |
336 KB |
Output is correct |
17 |
Correct |
45 ms |
336 KB |
Output is correct |
18 |
Correct |
88 ms |
432 KB |
Output is correct |
19 |
Correct |
91 ms |
336 KB |
Output is correct |
20 |
Correct |
84 ms |
436 KB |
Output is correct |
21 |
Correct |
84 ms |
436 KB |
Output is correct |
22 |
Correct |
89 ms |
428 KB |
Output is correct |
23 |
Correct |
17 ms |
592 KB |
Output is correct |
24 |
Incorrect |
177 ms |
504 KB |
Wrong Answer [2] |
25 |
Halted |
0 ms |
0 KB |
- |