QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645896#6303. InversionTerac#TL 0ms0kbC++142.8kb2024-10-16 20:24:202024-10-16 20:24:21

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 20:24:21]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-16 20:24:20]
  • 提交

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 = 5;

bool cmp(int x, int y) {
	if(x > y) swap(x, y);
	if(x == y - 1) {
		printf("? %d %d\n", x, y);
		fflush(stdout);
		return read();
	}
	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);
//	cout << l << " " << r << endl;
	int i = l, j = mid + 1, k = i;
	while(i <= mid && j <= r) {
//		cout <<"!:"<<l<<' '<<r<<endl;
		if(cmp(p[i], p[j])) tmp[k++] = p[j++];
		else tmp[k++] = p[i++];
	}
//	cout << i << " " << p[1]<<" " << p[2] << k << " ""sdfsdf\n";
	while(i <= mid) tmp[k++] = p[i++];
	while(j <= r) tmp[k++] = p[j++];
//	cout << tmp[2] << " " << tmp[3] << endl;
//	cout << l << " " << r << " " << tmp[1] << " " << tmp[2] << " " << tmp[3 ]<< endl; 
	for(i = l; i <= r; i++) p[i] = tmp[i];
//	cout << p[1] << " " << p[2] << " " << p[3] << endl;
}
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);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3

output:


result: