QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#301985 | #6303. Inversion | USTC_fish_touching_team# | TL | 1ms | 3844kb | C++17 | 1.6kb | 2024-01-10 15:06:24 | 2024-01-10 15:06:24 |
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], siz[N << 2];
void build(int id, int l, int r)
{
siz[id] = 0;
if (l == r) return;
int mid = l + r >> 1;
build(id << 1, l, mid), build(id << 1 | 1, mid + 1, r);
}
void modf(int id, int l, int r, int x)
{
siz[x] ^= 1;
if (l == r) return;
int mid = l + r >> 1;
if (x <= mid) build(id << 1, l, mid);
else build(id << 1 | 1, mid + 1, r);
}
inline int que(int id, int l, int r, int x, int y)
{
if (x > y) return 0;
if (x <= l && r <= y) return siz[id];
int mid = l + r >> 1, ans = 0;
if (x <= mid) ans = que(id << 1, l, mid, x, y);
if (y > mid) ans ^= que(id << 1 | 1, mid + 1, r, x, y);
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;
build(1, 1, i);
for (Re j = i; j; --j) g[j] = g[j + 1] ^ que(1, 1, i, 1, p[j] - 1), modf(1, 1, i, 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: 3844kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Time Limit Exceeded
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 0 0 0 0 1 1 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 0 0...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 3 ? 2 4 ? 3 4 ? 3 4 ? 2 5 ? 3 5 ? 3 5 ? 4 5 ? 5 6 ? 5 6 ? 5 6 ? 5 7 ? 6 7 ? 1 7 ? 2 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...