#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
static int A[5000];
vector<ii> locations;
void findNext2(int N, int top, int bot, int prevLoc, bool gr1);
void findNext1(int N, int top, int bot = 1, int prevLoc = 1, bool gr1 = false, bool exl = false) {
if (top == bot) return;
int mid;
int low = bot, high = top;
int prev = query(low, high);
if (abs(top - bot) != 1) {
while (low != high) {
mid = (low+high)/2;
int res = query(bot, mid);
if (res == prev) high = mid;
else low = mid+1;
}
} else low = top;
locations.push_back({prevLoc+prev*(gr1?-1:1), low});
findNext1(N, top, low, prevLoc+prev*(gr1?-1:1), !gr1, true);
findNext2(N, low, bot + exl, prevLoc+prev*(gr1?-1:1), !gr1);
}
void findNext2(int N, int top, int bot, int prevLoc = 1, bool gr1 = false ) {
if (top == bot) return;
int mid;
int low = bot, high = top;
int prev = query(low, high);
if (abs(top - bot) != 1) {
while (low != high) {
mid = (low+high+1)/2;
int res = query(mid, top);
if (res == prev) low = mid;
else high = mid-1;
}
} else low = bot;
locations.push_back({prevLoc+prev*(gr1?-1:1), low});
findNext1(N, top-1, low, prevLoc+prev*(gr1?-1:1), !gr1, true);
findNext2(N, low, bot, prevLoc+prev*(gr1?-1:1), !gr1);
}
void solve(int N) {
findNext1(N, N);
sort(locations.begin(), locations.end());
bool oppdir = (locations[0].second > locations.back().second);
for (int i = 0; i < N; i++) {
answer(locations[i].second, (oppdir ? N-i : i + 1));
}
}
Compilation message
xylophone.cpp:7:12: warning: 'A' defined but not used [-Wunused-variable]
7 | static int A[5000];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
284 KB |
Output is correct |
5 |
Correct |
6 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
300 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
284 KB |
Output is correct |
5 |
Correct |
6 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
300 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
10 ms |
208 KB |
Output is correct |
18 |
Correct |
8 ms |
304 KB |
Output is correct |
19 |
Correct |
14 ms |
304 KB |
Output is correct |
20 |
Correct |
20 ms |
304 KB |
Output is correct |
21 |
Correct |
15 ms |
304 KB |
Output is correct |
22 |
Correct |
18 ms |
304 KB |
Output is correct |
23 |
Correct |
71 ms |
304 KB |
Output is correct |
24 |
Correct |
72 ms |
300 KB |
Output is correct |
25 |
Correct |
62 ms |
344 KB |
Output is correct |
26 |
Correct |
21 ms |
208 KB |
Output is correct |
27 |
Correct |
21 ms |
304 KB |
Output is correct |
28 |
Correct |
19 ms |
300 KB |
Output is correct |
29 |
Correct |
26 ms |
304 KB |
Output is correct |
30 |
Correct |
24 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
284 KB |
Output is correct |
5 |
Correct |
6 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
5 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
300 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
4 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
10 ms |
208 KB |
Output is correct |
18 |
Correct |
8 ms |
304 KB |
Output is correct |
19 |
Correct |
14 ms |
304 KB |
Output is correct |
20 |
Correct |
20 ms |
304 KB |
Output is correct |
21 |
Correct |
15 ms |
304 KB |
Output is correct |
22 |
Correct |
18 ms |
304 KB |
Output is correct |
23 |
Correct |
71 ms |
304 KB |
Output is correct |
24 |
Correct |
72 ms |
300 KB |
Output is correct |
25 |
Correct |
62 ms |
344 KB |
Output is correct |
26 |
Correct |
21 ms |
208 KB |
Output is correct |
27 |
Correct |
21 ms |
304 KB |
Output is correct |
28 |
Correct |
19 ms |
300 KB |
Output is correct |
29 |
Correct |
26 ms |
304 KB |
Output is correct |
30 |
Correct |
24 ms |
208 KB |
Output is correct |
31 |
Correct |
31 ms |
456 KB |
Output is correct |
32 |
Correct |
62 ms |
316 KB |
Output is correct |
33 |
Incorrect |
62 ms |
300 KB |
Wrong Answer [2] |
34 |
Halted |
0 ms |
0 KB |
- |