QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303608 | #6303. Inversion | xuyufeiya | WA | 98ms | 6348kb | C++20 | 1.6kb | 2024-01-12 20:08:01 | 2024-01-12 20:08:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
struct myHash {
size_t operator()(pii p) const {
return ((p.first * 1ll) << 32) + p.second;
}
};
unordered_map<pii, int, myHash> mp;
int getV(int x, int y) {
if(mp.count({x, y})) return mp[{x, y}];
int &ret = mp[{x, y}];
printf("? %d %d\n", x, y);
fflush(stdout);
cin >> ret;
return ret;
}
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;
if(x + 1 == y) {
ret ^= getV(x, y);
} else {
ret ^= getV(x + 1, y);
ret ^= getV(x, y - 1);
ret ^= getV(x, y);
if(x + 1 != y - 1) ret ^= getV(x, y);
}
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: 3780kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 98ms
memory: 6348kb
input:
1993 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 1...
output:
? 1 2 ? 2 3 ? 1 3 ? 2 4 ? 1 4 ? 3 4 ? 3 5 ? 2 5 ? 4 5 ? 3 6 ? 2 6 ? 1 5 ? 1 6 ? 3 7 ? 2 7 ? 4 7 ? 6 7 ? 5 6 ? 5 7 ? 3 8 ? 2 8 ? 1 7 ? 1 8 ? 3 9 ? 2 9 ? 6 9 ? 5 8 ? 5 9 ? 4 9 ? 4 8 ? 3 10 ? 2 10 ? 4 10 ? 9 10 ? 8 11 ? 7 10 ? 7 11 ? 10 11 ? 9 11 ? 8 12 ? 7 12 ? 2 12 ? 1 11 ? 1 12 ? 9 12 ? 8 13 ? 7 13 ...
result:
wrong output format Unexpected end of file - int32 expected