#include "xylophone.h"
#include <cmath>
#include <cassert>
#include <unordered_set>
using namespace std;
void solve(int n) {
int a[n + 1];
int l = 1, r = n;
while(r - l > 1) {
int m = (l + r) / 2;
if(query(1, m) >= n - 1) {
r = m;
}
else {
l = m;
}
}
int mxid = r;
a[mxid] = n;
unordered_set<int> free;
for(int i = 1; i < n; ++i) {
free.insert(i);
}
if(mxid > 1) {
a[mxid - 1] = a[mxid] - query(mxid - 1, mxid);
free.erase(a[mxid - 1]);
}
if(mxid + 1 <= n) {
a[mxid + 1] = a[mxid] - query(mxid, mxid + 1);
free.erase(a[mxid + 1]);
}
for(int i = mxid + 2; i <= n; ++i) {
int p = query(i - 1, i);
int val1 = a[i - 1] - p;
int val2 = a[i - 1] + p;
if(!free.count(val1)) {
a[i] = val2;
continue;
}
if(!free.count(val2)) {
a[i] = val1;
continue;
}
int t = query(i - 2, i);
if(abs(a[i - 1] - a[i - 2]) + p == t) {
if(a[i - 2] < a[i - 1]) {
a[i] = val2;
}
else {
a[i] = val1;
}
}
else {
if(a[i - 2] < a[i - 1]) {
a[i] = val1;
}
else {
a[i] = val2;
}
}
free.erase(a[i]);
}
for(int i = mxid - 2; i >= 1; --i) {
int p = query(i, i + 1);
int val1 = a[i + 1] - p;
int val2 = a[i + 1] + p;
if(!free.count(val1)) {
a[i] = val2;
continue;
}
if(!free.count(val2)) {
a[i] = val1;
int val2 = a[i + 1] + p;
if(!free.count(val1)) {
a[i] = val2;
continue;
}
if(!free.count(val2)) {
a[i] = val1;
continue;
int val2 = a[i + 1] + p;
if(!free.count(val1)) {
a[i] = val2;
continue;
}
if(!free.count(val2)) {
a[i] = val1;
continue;
}
int t = query(i, i + 2);
if(abs(a[i + 1] - a[i + 2]) + p == t) {
if(a[i + 1] < a[i + 2]) {
}
int t = query(i, i + 2);
if(abs(a[i + 1] - a[i + 2]) + p == t) {
if(a[i + 1] < a[i + 2]) {
continue;
int val2 = a[i + 1] + p;
if(!free.count(val1)) {
a[i] = val2;
continue;
}
if(!free.count(val2)) {
a[i] = val1;
continue;
}
int t = query(i, i + 2);
if(abs(a[i + 1] - a[i + 2]) + p == t) {
if(a[i + 1] < a[i + 2]) {
}
int t = query(i, i + 2);
if(abs(a[i + 1] - a[i + 2]) + p == t) {
if(a[i + 1] < a[i + 2]) {
a[i] = val1;
}
else {
a[i] = val2;
}
}
else {
if(a[i + 1] < a[i + 2]) {
a[i] = val2;
}
else {
a[i] = val1;
}
}
free.erase(a[i]);
}
for(int i = 1; i <= n; ++i) {
answer(i, a[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:135:1: error: expected '}' at end of input
135 | }
| ^
xylophone.cpp:97:47: note: to match this '{'
97 | if(abs(a[i + 1] - a[i + 2]) + p == t) {
| ^
xylophone.cpp:135:1: error: expected '}' at end of input
135 | }
| ^
xylophone.cpp:93:47: note: to match this '{'
93 | if(abs(a[i + 1] - a[i + 2]) + p == t) {
| ^
xylophone.cpp:135:1: error: expected '}' at end of input
135 | }
| ^
xylophone.cpp:80:31: note: to match this '{'
80 | if(!free.count(val2)) {
| ^
xylophone.cpp:135:1: error: expected '}' at end of input
135 | }
| ^
xylophone.cpp:73:31: note: to match this '{'
73 | if(!free.count(val2)) {
| ^
xylophone.cpp:135:1: error: expected '}' at end of input
135 | }
| ^
xylophone.cpp:65:40: note: to match this '{'
65 | for(int i = mxid - 2; i >= 1; --i) {
| ^
xylophone.cpp:135:1: error: expected '}' at end of input
135 | }
| ^
xylophone.cpp:8:19: note: to match this '{'
8 | void solve(int n) {
| ^