QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371526#6303. Inversionucup-team956WA 0ms3680kbC++171.5kb2024-03-30 13:42:412024-03-30 13:42:43

Judging History

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

  • [2024-03-30 13:42:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-03-30 13:42:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define time chrono::system_clock::now().time_since_epoch().count()
mt19937_64 rnd(time);
#define maxn 2005
#define int long long

int read() {int x;cin>>x;return x;}

int f[maxn][maxn];

int ask(int l, int r) {
	if(l >= r) return 0;
	if(f[l][r] != -1) return f[l][r];
	cout << "? " << l << " " << r << endl;
	int x;
	cin >> x;
	f[l][r] = x;
	return f[l][r];
}

signed main() {
	// #ifdef ONLINE_JUDGE
		// ios::sync_with_stdio(false);
		// cin.tie(0);cout.tie(0);
	// #else
		// freopen("a.in", "r", stdin);
	// #endif

	int n = read();
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			f[i][j] = -1;
	}
	vector<int> a(n + 1), pos(n + 1);
	a[1] = 1;
	for(int i = 1; i <= n; i++) f[i][i] = 0;
	for(int i = 2; i <= n; i++) {
		int l = 1, r = i - 1;
		auto check = [&](int mid) -> int {
			int val = ask(pos[mid], i) ^ ask(pos[mid] + 1, i) ^ ask(pos[mid], i - 1) ^ ask(pos[mid] + 1, i - 1);
			if(val == 1) return 1; // a[mid] > a[i]
			else return 0; // a[mid] < a[i]
		};
		while(l <= r) {
			int mid = (l + r) >> 1;
			if(check(mid)) r = mid - 1;
			else l = mid + 1;
		}
		a[i] = l;
		for(int j = 1; j < i; j++) if(a[j] >= a[i]) a[j] += 1;
		for(int j = 1; j <= i; j++) pos[a[j]] = j;
		int tot = 0;
		for(int j = i - 1; j >= 1; j--) {
			tot += (a[i] > a[j]);
			f[j][i] = f[j][i - 1] + tot;
		}
	}
	cout << "! ";
	for(int i = 1; i <= n; i++) cout << a[i] << " ";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3680kb

input:

3
0
0
1

output:

? 1 2
? 1 3
? 2 3
! 1 3 2 

result:

wrong answer Wa.