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>
#include "xylophone.h"
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 5e5 + 10, inf = 2e9;
// int n;
// vector <int> a;
// int query(int s, int t) {
// // cout << "plus" << endl;
// s--; t--;
// int mx = a[s], mn = a[s];
// for (int i = s; i <= t; i++) mx = max(mx, a[i]), mn = min(mn, a[i]);
// return mx - mn;
// }
void solve(int n) {
vector <int> b; b.assign(n, 0);
vector <bool> vis(n + 1, false);
int l = 0, r = n - 1, posn = n - 1;
while (l <= r) {
int m = (l + r) / 2;
int tmp = query(1, m + 1);
if (tmp < n - 1) {
l = m + 1;
} else {
posn = min(posn, m);
r = m - 1;
}
}
b[posn] = n; vis[n] = true;
int cnt = 1;
for (int i = posn + 1; i < n; i++) {
int x, y, tmp = query(i, i + 1);
x = b[i - 1] + tmp; y = b[i - 1] - tmp;
if (x > n || vis[x]) {
b[i] = y;
} else if (y < 1 || vis[y]) {
b[i] = x;
} else {
int j = i - 1;
while (b[j] <= x)
j--;
int tmp = query(j + 1, i + 1);
if (tmp == b[j] - x) {
b[i] = x;
} else {
b[i] = y;
}
}
vis[b[i]] = true;
cnt++;
if (cnt == n - 1) {
int t1;
for (int j = 1; j <= n; j++)
if (!vis[j])
t1 = j;
for (int j = 0; j < n; j++)
if (b[j] == 0)
b[j] = t1;
break;
}
}
for (int i = posn - 1; i >= 0; i--) {
int x, y, tmp = query(i + 1, i + 2);
x = b[i + 1] + tmp; y = b[i + 1] - tmp;
if (x > n || vis[x]) {
b[i] = y;
} else if (y < 1 || vis[y]) {
b[i] = x;
} else {
int j = i + 1;
while (b[j] <= x)
j++;
int tmp = query(i + 1, j + 1);
if (tmp == b[j] - x) {
b[i] = x;
} else {
b[i] = y;
}
}
vis[b[i]] = true;
cnt++;
if (cnt == n - 1) {
int t1;
for (int j = 1; j <= n; j++)
if (!vis[j])
t1 = j;
for (int j = 0; j < n; j++)
if (b[j] == 0)
b[j] = t1;
break;
}
}
for (int i = 0; i < n; i++) {
answer(i + 1, b[i]);
// cout << b[i] << " ";
}
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:100:16: warning: 't1' may be used uninitialized in this function [-Wmaybe-uninitialized]
100 | b[j] = t1;
xylophone.cpp:68:16: warning: 't1' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | b[j] = t1;
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |