QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#301996 | #6303. Inversion | USTC_fish_touching_team# | WA | 57ms | 3896kb | C++17 | 1.1kb | 2024-01-10 15:11:59 | 2024-01-10 15:12:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define Re register int
const int N = 2005;
int n, p[N], d[N], g[N], f[N];
inline void modf(int x)
{
while (x <= n) f[x] ^= 1, x += x & -x;
}
inline int que(int x)
{
int ans = 0;
while (x) ans ^= f[x], x -= x & -x;
return ans;
}
int main()
{
scanf("%d", &n);
p[1] = d[1] = 1;
for (Re i = 2; i <= n; ++i)
{
int l = 1, r = i - 1, s = i, u, v;
while (l <= r)
{
int mid = l + r >> 1;
printf("? %d %d\n", d[mid], i);
fflush(stdout);
scanf("%d", &u);
if (d[mid] + 1 == i)
{
if (u) s = mid, r = mid - 1;
else l = mid + 1;
}
else
{
printf("? %d %d\n", d[mid] + 1, i);
fflush(stdout);
scanf("%d", &v);
if (u ^ v ^ g[d[mid] + 1] ^ g[d[mid]]) s = mid, r = mid - 1;
else l = mid + 1;
}
}
for (Re j = 1; j < i; ++j)
if (p[j] >= s) d[++p[j]] = i;
d[p[i] = s] = i;
for (Re j = 0; j <= n; ++j) f[j] = 0;
for (Re j = i; j; --j) g[j] = g[j + 1] ^ que(p[j] - 1), modf(p[j]);
}
putchar('!');
for (Re i = 1; i <= n; ++i) printf(" %d", p[i]);
putchar('\n');
fflush(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3824kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 57ms
memory: 3896kb
input:
1993 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 3 ? 2 4 ? 3 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 2 5 ? 5 6 ? 5 6 ? 5 6 ? 5 7 ? 6 7 ? 5 7 ? 6 7 ? 7 8 ? 7 8 ? 7 8 ? 7 9 ? 8 9 ? 7 9 ? 8 9 ? 7 9 ? 8 9 ? 8 9 ? 7 10 ? 8 10 ? 7 10 ? 8 10 ? 9 10 ? 7 11 ? 8 11 ? 10 11 ? 10 11 ? 10 11 ? 7 12 ? 8 12 ? 10 12 ? 11 12 ? 10 12 ? 11 12 ? 11 12 ? 7 1...
result:
wrong answer Wa.