QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645931 | #6303. Inversion | Terac# | TL | 0ms | 0kb | C++14 | 2.6kb | 2024-10-16 20:30:02 | 2024-10-16 20:30:03 |
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO {
#if ONLINE_JUDGE
#define getc() (IS == IT && (IT = (IS = ibuf) + fread(ibuf, 1, IL, stdin), IS == IT) ? EOF : *IS++)
#else
#define getc() getchar()
#endif
const int IL = 1 << 21, OL = 1 << 21;
int olen = 0;
char ibuf[IL], *IS = ibuf, *IT = ibuf, obuf[OL];
inline int read() {
register char ch = getc(); register int x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
return x * f;
}
inline double readdb() {
register char ch = getc(); register double x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
if(ch == '.') {
register double b = 0.1;
ch = getc();
while(isdigit(ch)) x += (ch - 48) * b, b *= 0.1, ch = getc();
}
return x * f;
}
inline int readstr(char *s) {
register char ch = getc(); register int len = 0;
while(!isalpha(ch)) ch = getc();
while(isalpha(ch)) s[++len] = ch, ch = getc();
return len;
}
inline void flush() { fwrite(obuf, 1, olen, stdout); olen = 0; }
inline void putc(register char ch) { obuf[olen++] = ch; }
template<class T>
inline void write(register T x) {
if(x < 0) obuf[olen++] = '-', x = -x;
if(x > 9) write(x / 10);
obuf[olen++] = x % 10 + 48;
}
} using namespace IO;
const int N = 2e3 + 10;
int cnt = 0;
bool cmp(int x, int y) {
if(x > y) swap(x, y);
if(x == y - 1) {
cnt++;
printf("? %d %d\n", x, y);
fflush(stdout);
return read();
return 0;
}
cnt+=2;
int res = 0;
// printf("? %d %d\n", x, y);
// fflush(stdout);
// res ^= read();
printf("? %d %d\n", x + 1, y);
fflush(stdout);
res ^= read();
printf("? %d %d\n", x, y - 1);
fflush(stdout);
res ^= read();
// printf("? %d %d\n", x + 1, y - 1);
// fflush(stdout);
// res ^= read();
return res;
}
int p[N], tmp[N];
void solve(int l, int r) {
if(l == r) return;
int mid = l + r >> 1;
solve(l, mid);
solve(mid + 1, r);
int i = l, j = mid + 1, k = i;
while(i <= mid && j <= r) {
if(cmp(p[i], p[j])) tmp[k++] = p[j++];
else tmp[k++] = p[i++];
}
while(i <= mid) tmp[k++] = p[i++];
while(j <= r) tmp[k++] = p[j++];
for(i = l; i <= r; i++) p[i] = tmp[i];
}
int id[N];
int main() {
int n;
n = read();
iota(p + 1, p + 1 + n, 1);
solve(1, n);
for(int i = 1; i <= n; i++)
id[p[i]] = i;
printf("! ");
for(int i = 1; i <= n; i++)
printf("%d ", id[i]);
fflush(stdout);
// cout << cnt << endl;
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3