#include "xylophone.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#ifdef DEBUG
#include <time.h>
#endif
#define all(a) (a).begin(), (a).end()
#define rev(a) (a).rbegin(), (a).rend()
#define F first
#define S second
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) \
{ \
++recur_depth; \
auto x_ = x; \
--recur_depth; \
cerr << string(recur_depth, '\t') << "\e[91m" << __func__ << ":" \
<< __LINE__ << "\t" << #x << " = " << x_ << "\e[39m" << endl; \
}
#else
#define dbg(x)
#endif
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> ii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> llll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<vii> vvii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pair<ll, ll>> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
template <class type1>
using ordered_set = tree<type1, null_type, less<type1>, rb_tree_tag,
tree_order_statistics_node_update>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
!is_same<T_container, string>::value,
typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;
static int A[5000];
void solve(int N) {
vvi q(N + 1, vi(N + 1, -1));
int cnt = 0;
auto ask = [&](int s, int t) {
if (q[s][t] != -1)
return q[s][t];
cnt++;
return q[s][t] = query(s, t);
};
vi ans(N + 1, -1);
vi at(N + 1, -1);
int tot = N - 1;
int l = 2, r = N, pos_1 = 1;
while (l <= r) {
int mid = (l + r) / 2;
if (ask(mid, N) != tot)
r = mid - 1;
else {
pos_1 = mid;
l = mid + 1;
}
}
auto in_rng = [&](int x) { return 1 <= x && x <= N; };
auto fill_place = [&](int pos, int v) {
ans[v] = pos;
at[pos] = v;
};
fill_place(pos_1, 1);
at[pos_1] = 1;
if (pos_1 < N) {
fill_place(pos_1 + 1, 1 + ask(pos_1, pos_1 + 1));
for (int i = pos_1 + 2; i <= N; i++) {
int ab = ask(i - 2, i - 1), bc = ask(i - 1, i);
if (!in_rng(at[i - 1] + bc) || ans[at[i - 1] + bc] != -1) {
fill_place(i, at[i - 1] - bc);
continue;
}
if (!in_rng(at[i - 1] - bc) || ans[at[i - 1] - bc] != -1) {
fill_place(i, at[i - 1] + bc);
continue;
}
int ac = ask(i - 2, i);
if (ac == ab || ac == bc) {
if (at[i - 2] < at[i - 1])
fill_place(i, at[i - 1] - bc);
else
fill_place(i, at[i - 1] + bc);
} else {
if (at[i - 2] < at[i - 1])
fill_place(i, at[i - 1] + bc);
else
fill_place(i, at[i - 1] - bc);
}
}
}
if (pos_1 > 1) {
fill_place(pos_1 - 1, 1 + ask(pos_1 - 1, pos_1));
for (int i = pos_1 - 2; i >= 1; i--) {
int ab = ask(i, i + 1), bc = ask(i + 1, i + 2);
if (!in_rng(at[i + 1] + ab) || ans[at[i + 1] + ab] != -1) {
fill_place(i, at[i + 1] - ab);
continue;
}
if (!in_rng(at[i + 1] - ab) || ans[at[i + 1] - ab] != -1) {
fill_place(i, at[i + 1] + ab);
continue;
}
int ac = ask(i, i + 2);
if (ac == bc || ac == ab) {
if (at[i + 1] < at[i + 2])
fill_place(i, at[i + 1] + ab);
else
fill_place(i, at[i + 1] - ab);
} else {
if (at[i + 1] < at[i + 2])
fill_place(i, at[i + 1] - ab);
else
fill_place(i, at[i + 1] + ab);
}
}
}
for (int i = 1; i <= N; i++)
answer(i, at[i]);
}
Compilation message
xylophone.cpp:93:12: warning: 'A' defined but not used [-Wunused-variable]
93 | 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 |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
5 ms |
1104 KB |
Output is correct |
18 |
Correct |
8 ms |
2976 KB |
Output is correct |
19 |
Correct |
10 ms |
4256 KB |
Output is correct |
20 |
Correct |
8 ms |
4176 KB |
Output is correct |
21 |
Correct |
12 ms |
4196 KB |
Output is correct |
22 |
Correct |
9 ms |
4176 KB |
Output is correct |
23 |
Correct |
10 ms |
4264 KB |
Output is correct |
24 |
Correct |
11 ms |
4252 KB |
Output is correct |
25 |
Correct |
9 ms |
4264 KB |
Output is correct |
26 |
Correct |
12 ms |
4176 KB |
Output is correct |
27 |
Correct |
11 ms |
4268 KB |
Output is correct |
28 |
Correct |
12 ms |
4300 KB |
Output is correct |
29 |
Correct |
12 ms |
4176 KB |
Output is correct |
30 |
Correct |
10 ms |
4260 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 |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
5 ms |
1104 KB |
Output is correct |
18 |
Correct |
8 ms |
2976 KB |
Output is correct |
19 |
Correct |
10 ms |
4256 KB |
Output is correct |
20 |
Correct |
8 ms |
4176 KB |
Output is correct |
21 |
Correct |
12 ms |
4196 KB |
Output is correct |
22 |
Correct |
9 ms |
4176 KB |
Output is correct |
23 |
Correct |
10 ms |
4264 KB |
Output is correct |
24 |
Correct |
11 ms |
4252 KB |
Output is correct |
25 |
Correct |
9 ms |
4264 KB |
Output is correct |
26 |
Correct |
12 ms |
4176 KB |
Output is correct |
27 |
Correct |
11 ms |
4268 KB |
Output is correct |
28 |
Correct |
12 ms |
4300 KB |
Output is correct |
29 |
Correct |
12 ms |
4176 KB |
Output is correct |
30 |
Correct |
10 ms |
4260 KB |
Output is correct |
31 |
Correct |
23 ms |
18732 KB |
Output is correct |
32 |
Correct |
47 ms |
37704 KB |
Output is correct |
33 |
Correct |
70 ms |
74744 KB |
Output is correct |
34 |
Correct |
82 ms |
98276 KB |
Output is correct |
35 |
Correct |
79 ms |
98340 KB |
Output is correct |
36 |
Correct |
70 ms |
98340 KB |
Output is correct |
37 |
Correct |
71 ms |
98360 KB |
Output is correct |
38 |
Correct |
71 ms |
98300 KB |
Output is correct |
39 |
Correct |
84 ms |
98368 KB |
Output is correct |
40 |
Correct |
80 ms |
98364 KB |
Output is correct |
41 |
Correct |
79 ms |
98360 KB |
Output is correct |
42 |
Correct |
75 ms |
98384 KB |
Output is correct |
43 |
Correct |
72 ms |
98368 KB |
Output is correct |
44 |
Correct |
76 ms |
98476 KB |
Output is correct |
45 |
Correct |
76 ms |
98384 KB |
Output is correct |
46 |
Correct |
78 ms |
98308 KB |
Output is correct |
47 |
Correct |
77 ms |
98408 KB |
Output is correct |
48 |
Correct |
78 ms |
98460 KB |
Output is correct |
49 |
Correct |
86 ms |
98384 KB |
Output is correct |
50 |
Correct |
82 ms |
98380 KB |
Output is correct |
51 |
Correct |
87 ms |
98384 KB |
Output is correct |
52 |
Correct |
56 ms |
98388 KB |
Output is correct |
53 |
Correct |
79 ms |
98388 KB |
Output is correct |
54 |
Correct |
86 ms |
98400 KB |
Output is correct |
55 |
Correct |
81 ms |
98384 KB |
Output is correct |
56 |
Correct |
76 ms |
98392 KB |
Output is correct |
57 |
Correct |
73 ms |
98384 KB |
Output is correct |
58 |
Correct |
56 ms |
98384 KB |
Output is correct |
59 |
Correct |
81 ms |
98336 KB |
Output is correct |
60 |
Correct |
78 ms |
98392 KB |
Output is correct |