#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
void solve(int n){
int l = 0, r = n - 2;
while(l < r){
int mid = (l + r + 1) / 2;
int q = query(mid + 1, n);
if(q == (n - 1)) l = mid;
else r = mid - 1;
}
vi ans(n, 0), vis(n + 1, 0);
ans[l] = 1;
vis[1] = 1;
if(l > 0){
int qu2 = query(l, l + 1);
ans[l - 1] = qu2 + 1;
vis[ans[l - 1]] = 1;
for(int i = l - 2; i >= 0; i--){
int qu1 = query(i + 1, i + 2);
if(ans[i + 1] + qu1 > n || vis[ans[i + 1] + qu1]){
ans[i] = ans[i + 1] - qu1;
vis[ans[i]] = 1;
continue;
}
if(ans[i + 1] - qu1 < 1 || vis[ans[i + 1] - qu1]){
ans[i] = ans[i + 1] + qu1;
vis[ans[i]] = 1;
continue;
}
vi cur = {ans[i + 1], ans[i + 2], ans[i + 1] + qu1};
sort(all(cur));
int qu = query(i + 1, i + 3);
if(cur[2] - cur[0] == qu) ans[i] = ans[i + 1] + qu1;
else ans[i] = ans[i + 1] - qu1;
vis[ans[i]] = 1;
}
}
if(l < (n - 1)){
int qu2 = query(l + 1, l + 2);
ans[l + 1] = qu2 + 1;
vis[ans[l + 1]] = 1;
for(int i = l + 2; i < n; i++){
int qu1 = query(i, i + 1);
if(ans[i - 1] + qu1 > n || vis[ans[i - 1] + qu1]){
ans[i] = ans[i - 1] - qu1;
vis[ans[i]] = 1;
continue;
}
if(ans[i - 1] - qu1 < 1 || vis[ans[i - 1] - qu1]){
ans[i] = ans[i - 1] + qu1;
vis[ans[i]] = 1;
continue;
}
vi cur = {ans[i - 2], ans[i - 1], ans[i - 1] + qu1};
sort(all(cur));
int qu = query(i - 1, i + 1);
if(cur[2] - cur[0] == qu) ans[i] = ans[i - 1] + qu1;
else ans[i] = ans[i - 1] - qu1;
vis[ans[i]] = 1;
}
}
rep(i, n) answer(i + 1, ans[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
256 KB |
Output is correct |
18 |
Correct |
12 ms |
256 KB |
Output is correct |
19 |
Correct |
11 ms |
256 KB |
Output is correct |
20 |
Correct |
13 ms |
256 KB |
Output is correct |
21 |
Correct |
11 ms |
384 KB |
Output is correct |
22 |
Correct |
9 ms |
256 KB |
Output is correct |
23 |
Correct |
8 ms |
384 KB |
Output is correct |
24 |
Correct |
9 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
256 KB |
Output is correct |
26 |
Correct |
16 ms |
256 KB |
Output is correct |
27 |
Correct |
10 ms |
256 KB |
Output is correct |
28 |
Correct |
15 ms |
376 KB |
Output is correct |
29 |
Correct |
13 ms |
384 KB |
Output is correct |
30 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
256 KB |
Output is correct |
18 |
Correct |
12 ms |
256 KB |
Output is correct |
19 |
Correct |
11 ms |
256 KB |
Output is correct |
20 |
Correct |
13 ms |
256 KB |
Output is correct |
21 |
Correct |
11 ms |
384 KB |
Output is correct |
22 |
Correct |
9 ms |
256 KB |
Output is correct |
23 |
Correct |
8 ms |
384 KB |
Output is correct |
24 |
Correct |
9 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
256 KB |
Output is correct |
26 |
Correct |
16 ms |
256 KB |
Output is correct |
27 |
Correct |
10 ms |
256 KB |
Output is correct |
28 |
Correct |
15 ms |
376 KB |
Output is correct |
29 |
Correct |
13 ms |
384 KB |
Output is correct |
30 |
Correct |
14 ms |
384 KB |
Output is correct |
31 |
Correct |
21 ms |
384 KB |
Output is correct |
32 |
Correct |
49 ms |
392 KB |
Output is correct |
33 |
Correct |
60 ms |
384 KB |
Output is correct |
34 |
Correct |
69 ms |
384 KB |
Output is correct |
35 |
Correct |
66 ms |
384 KB |
Output is correct |
36 |
Correct |
58 ms |
384 KB |
Output is correct |
37 |
Correct |
58 ms |
384 KB |
Output is correct |
38 |
Correct |
44 ms |
384 KB |
Output is correct |
39 |
Correct |
52 ms |
384 KB |
Output is correct |
40 |
Correct |
66 ms |
384 KB |
Output is correct |
41 |
Correct |
56 ms |
384 KB |
Output is correct |
42 |
Correct |
49 ms |
384 KB |
Output is correct |
43 |
Correct |
49 ms |
384 KB |
Output is correct |
44 |
Correct |
46 ms |
384 KB |
Output is correct |
45 |
Correct |
74 ms |
384 KB |
Output is correct |
46 |
Correct |
64 ms |
384 KB |
Output is correct |
47 |
Correct |
69 ms |
384 KB |
Output is correct |
48 |
Correct |
74 ms |
384 KB |
Output is correct |
49 |
Correct |
73 ms |
384 KB |
Output is correct |
50 |
Correct |
65 ms |
384 KB |
Output is correct |
51 |
Correct |
58 ms |
384 KB |
Output is correct |
52 |
Correct |
67 ms |
384 KB |
Output is correct |
53 |
Correct |
57 ms |
384 KB |
Output is correct |
54 |
Correct |
63 ms |
384 KB |
Output is correct |
55 |
Correct |
56 ms |
384 KB |
Output is correct |
56 |
Correct |
56 ms |
384 KB |
Output is correct |
57 |
Correct |
52 ms |
384 KB |
Output is correct |
58 |
Correct |
84 ms |
384 KB |
Output is correct |
59 |
Correct |
83 ms |
384 KB |
Output is correct |
60 |
Correct |
77 ms |
384 KB |
Output is correct |