QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398835#6303. Inversiongqf123WA 109ms19216kbC++201.4kb2024-04-25 18:56:182024-04-25 18:56:18

Judging History

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

  • [2024-04-25 18:56:18]
  • 评测
  • 测评结果:WA
  • 用时:109ms
  • 内存:19216kb
  • [2024-04-25 18:56:18]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
#include<random>
using namespace std;
int vis[2001][2001], ans[2001], tree[2001], n;
inline int query(int l, int r) {
	if (l == r)
		return 0;
	if (~vis[l][r])
		return vis[l][r];
	cout << "? " << l << ' ' << r << endl;
	cin >> vis[l][r];
	return vis[l][r];
}
inline int ask(int x, int y) {
	if (x == y)
		return 0;
	if (x + 1 == y)
		return query(x, y);
	return (query(x, y) - query(x + 1, y) - query(x, y - 1) + query(x + 1, y - 1) + 50) % 2;
}
inline int sum(int p) {
	int ans = 0;
	for (; p; p ^= p & -p)
		ans += tree[p];
	return ans;
}
inline void add(int p, int v) {
	for (; p <= n; p += p & -p)
		tree[p] += v;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			vis[i][j] = -1;
	for (int i = 1; i <= n; ++i)
		vis[i][i] = 0;
	vector<int>o;
	for (int i = 1; i <= n; ++i) {
		int l = 0, r = o.size(), mid;
		for (; l < r;) {
			mid = l + r >> 1;
			if (ask(o[mid], i))
				r = mid;
			else
				l = mid + 1;
		}
		o.insert(o.begin() + l, i);
		for (int j = 0; j ^ o.size(); ++j)
			ans[o[j]] = j + 1;
		for (int j = 1; j <= n; ++j) {
			tree[j] = 0;
		}
		add(ans[i], 1);
		for (int j = i - 1; j; --j) {
			vis[j][i] = sum(ans[j]) % 2;
			add(ans[j], 1);
		}
	}
	cout << "! ";
	for (int i = 1; i <= n; ++i)
		cout << ans[i] << ' ';
	cout << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3884kb

input:

3
0
1
0

output:

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

result:

ok OK, guesses=3

Test #2:

score: -100
Wrong Answer
time: 109ms
memory: 19216kb

input:

1993
0
0
0
0
0
1
1
0
0
0
0
0
0
1
0
1
0
0
1
0
0
1
1
0
1
1
0
1
0
1
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
1
1
0
1
0
0
1
1
1
0
0
1
1
1
0
0
0
1
0
0
1
0
0
0
0
0
1
0
0
0
0
1
0
0
0
1
1
1
1
1
0
1
0
1
1
0
0
0
0
1
0
0
0
1
0
0
1
1
0
0
1
0
1
0
0
1
0
1
0
1
1
1
1
0
1
1
1
0
0
0
0
0
0
1
1
1
0
0
1
0
0
0
0
1
0
0
0
0
0
1
0
1...

output:

? 1 2
? 2 3
? 2 4
? 3 4
? 3 5
? 4 5
? 2 5
? 1 5
? 2 6
? 3 6
? 4 6
? 5 6
? 3 7
? 4 7
? 5 7
? 6 7
? 3 8
? 4 8
? 6 8
? 7 8
? 5 8
? 7 9
? 8 9
? 6 9
? 7 10
? 8 10
? 2 10
? 3 10
? 1 10
? 7 11
? 8 11
? 10 11
? 3 11
? 4 11
? 2 11
? 3 12
? 4 12
? 9 12
? 10 12
? 5 12
? 8 12
? 7 13
? 8 13
? 12 13
? 4 13
? 5 13...

result:

wrong answer Wa.