#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"
void solve(int n) {
vector<int> a(n + 1);
for (int i = 1; i <= 10001; ++i) {
query(1, n);
}
int min = 1, max = n;
for (int i = 2; i <= n; ++i) {
if (query(i, n) != n - 1) break;
min = i;
}
for (int i = n - 1; i > 0; --i) {
if (query(1, i) != n - 1) break;
max = i;
}
a[min] = 1, a[max] = n;
int last = min, sum = 0;
bool increasing = true;
for (int i = min - 1; i > 0; --i) {
int diff = query(i, last), add = query(i, i + 1);
if (sum + add != diff) {
last = i + 1, sum = 0;
increasing ^= true;
}
a[i] = a[i + 1] + (increasing ? add : -add);
sum += add;
}
last = min, sum = 0;
increasing = true;
for (int i = min + 1; i < max; ++i) {
int diff = query(last, i), add = query(i - 1, i);
if (sum + add != diff) {
last = i - 1, sum = 0;
increasing ^= true;
}
a[i] = a[i - 1] + (increasing ? add : -add);
sum += add;
}
last = max, sum = 0;
increasing = false;
for (int i = max + 1; i <= n; ++i) {
int diff = query(last, i), add = query(i - 1, i);
if (sum + add != diff) {
last = i - 1, sum = 0;
increasing ^= true;
}
a[i] = a[i - 1] + (increasing ? add : -add);
sum += add;
}
for (int i = 1; i <= n; ++i) {
answer(i, a[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
344 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |