This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#define F first
#define S second
//#define endl '\n'
//#define int long long
using namespace std;
int query(int s, int t);
void answer(int i, int a);
void solve(int N)
{
int f, l = 1, r = N;
while(l <= r)
{
int m = (l + r) / 2;
if (query(m, N) == N - 1) f = m, l = m + 1;
else r = m - 1;
}
vt<int> ans(N + 1), used(N + 1);
used[1] = ans[f] = 1;
for(int i = f - 1, q, a, b; i >= 1; i--)
{
q = query(i, i + 1), a = ans[i + 1] - q, b = ans[i + 1] + q;
if (a < 1 || used[a]) used[b] = 1, ans[i] = b;
else if (b > N || used[b]) used[a] = 1, ans[i] = a;
else
{
int new_q = query(i, i + 2);
if (ans[i + 2] > ans[i + 1])
{
if (new_q == (ans[i + 2] - ans[i + 1])) used[b] = 1, ans[i] = b;
else used[a] = 1, ans[i] = a;
}
else
{
if (new_q == (b - ans[i + 2])) used[b] = 1, ans[i] = b;
else used[a] = 1, ans[i] = a;
}
}
}
for(int i = f + 1, q, a, b; i <= N; i++)
{
q = query(i - 1, i), a = ans[i - 1] - q, b = ans[i - 1] + q;
if (a < 1 || used[a]) used[b] = 1, ans[i] = b;
else if (b > N || used[b]) used[a] = 1, ans[i] = a;
else
{
int new_q = query(i - 2, i);
if (ans[i - 2] > ans[i - 1])
{
if (new_q == (ans[i - 2] - ans[i - 1])) used[b] = 1, ans[i] = b;
else used[a] = 1, ans[i] = a;
}
else
{
if (new_q == (b - ans[i - 2])) used[b] = 1, ans[i] = b;
else used[a] = 1, ans[i] = a;
}
}
}
for(int i = 1; i <= N; i++) answer(i, ans[i]);
//cout << endl;
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:53:13: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | for(int i = f + 1, q, a, b; i <= N; i++)
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |