QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303601 | #6303. Inversion | xuyufeiya | WA | 96ms | 3764kb | C++20 | 1.7kb | 2024-01-12 19:55:33 | 2024-01-12 19:55:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n;
cin >> n;
auto query = [](auto self, int x, int y) -> int {
if(x > y) return -self(self, y, x);
if(x == 0) return -1;
int ret = 0, a;
if(x + 1 == y) {
printf("? %d %d\n", x, y);
fflush(stdout);
cin >> a;
ret ^= a;
} else {
printf("? %d %d\n", x + 1, y);
fflush(stdout);
cin >> a;
ret ^= a;
printf("? %d %d\n", x, y - 1);
fflush(stdout);
cin >> a;
ret ^= a;
printf("? %d %d\n", x, y);
fflush(stdout);
cin >> a;
ret ^= a;
if(x + 1 != y - 1) {
printf("? %d %d\n", x + 1, y - 1);
fflush(stdout);
cin >> a;
ret ^= a;
}
}
ret = (ret? 1: -1);
return ret;
};
vector<int> pos;
pos.push_back(0);
for(int i = 1; i <= n; i++) {
int lh = 0, rh = pos.size() - 1, ans = -1;
while(lh <= rh) {
int mid = (lh + rh) / 2, tmp;
if((tmp = query(query, i, pos[mid])) > 0) {
ans = mid;
lh = mid + 1;
} else {
rh = mid - 1;
}
}
pos.insert(pos.begin() + ans + 1, i);
}
vector<int> out(n + 1);
for(int i = 1; i <= n; i++) out[pos[i]] = i;
printf("! ");
for(int i = 1; i <= n; i++) printf("%d%c", out[i], i == n? '\n': ' ');
fflush(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
input:
3 0 1 0 0
output:
? 1 2 ? 2 3 ? 1 2 ? 1 3 ! 2 3 1
result:
ok OK, guesses=4
Test #2:
score: -100
Wrong Answer
time: 96ms
memory: 3764kb
input:
1993 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 1 1 1 1...
output:
? 1 2 ? 2 3 ? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 1 3 ? 1 4 ? 2 3 ? 3 4 ? 2 3 ? 2 4 ? 3 4 ? 3 5 ? 2 4 ? 2 5 ? 3 4 ? 2 5 ? 1 4 ? 1 5 ? 2 4 ? 2 6 ? 1 5 ? 1 6 ? 2 5 ? 5 6 ? 2 7 ? 1 6 ? 1 7 ? 2 6 ? 6 7 ? 5 6 ? 5 7 ? 7 8 ? 6 7 ? 6 8 ? 3 8 ? 2 7 ? 2 8 ? 3 7 ? 4 8 ? 3 7 ? 3 8 ? 4 7 ? 2 9 ? 1 8 ? 1 9 ? 2 8 ? 8 9 ? 3 9 ...
result:
wrong output format Unexpected end of file - int32 expected