// CF template, version 3.0
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}
// #define int long long int
void solve(int n) {
int l = 1;
int r = n;
while (r - l >= 1) {
int middle = (l + r) / 2;
int range = query(1, middle + 1);
if (range == n - 1) r = middle;
else l = middle + 1;
}
vector<int> ans(n);
vector<bool> used(n + 1, false);
ans[l] = n;
used[n] = true;
for (int i = l - 1; i >= 0; i--) {
int range = query(i + 1, i + 2);
int prev = ans[i + 1];
if (prev + range > n || used[prev + range]) {
ans[i] = prev - range;
} else if (1 > prev - range || used[prev - range]) {
ans[i] = prev + range;
} else {
int larger = query(i + 1, i + 3);
int beforeprev = ans[i + 2];
if (prev + range - min(prev, beforeprev) == larger) {
ans[i] = prev + range;
} else {
ans[i] = prev - range;
}
}
used[ans[i]] = true;
}
for (int i = l + 1; i < n; i++) {
if (i == n - 1) {
forto(n, j) {
if (!used[j + 1]) {
ans[i] = j + 1;
break;
}
}
break;
}
int range = query(i, i + 1);
int prev = ans[i - 1];
if (prev + range > n || used[prev + range]) {
ans[i] = prev - range;
} else if (1 > prev - range || used[prev - range]) {
ans[i] = prev + range;
} else {
int larger = query(i - 1, i + 1);
int beforeprev = ans[i - 2];
if (prev + range - min(prev, beforeprev) == larger) {
ans[i] = prev + range;
} else {
ans[i] = prev - range;
}
}
used[ans[i]] = true;
}
forto(n, i) {
answer(i + 1, ans[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:16:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
| ^
xylophone.cpp:54:13: note: in expansion of macro 'forto'
54 | forto(n, j) {
| ^~~~~
xylophone.cpp:16:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
16 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
| ^
xylophone.cpp:79:5: note: in expansion of macro 'forto'
79 | forto(n, i) {
| ^~~~~
# |
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 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |