QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594216#6303. Inversionshiqiaqiaya#WA 45ms34880kbC++201.8kb2024-09-27 20:20:422024-09-27 20:20:42

Judging History

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

  • [2024-09-27 20:20:42]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:34880kb
  • [2024-09-27 20:20:42]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
mt19937 rnd(time(0));
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;

    vector<int> a;
    a.push_back(1);

    vector vis(n + 1, vector<int> (n + 1, -1));
   	vector<int> f(n + 1);

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


    auto compare = [&](int x, int y) -> bool {
    	int a = ask(x, y - 1);
    	int b = ask(x + 1, y);
    	int c = ask(x, y);
    	int d = ask(x + 1, y - 1);
    	if ((a + b + c - d + 2) % 2 == 0) return false;
    	return true;
    };

    auto cp = [&](int x, int y) -> bool {
    	if ((f[x] + f[y]) & 1) {
    		return f[x] ? true : false;
    	}
    	int a = ask(x, y - 1);
    	int b = ask(x + 1, y);
    	int c = ask(x, y);
    	int d = ask(x + 1, y - 1);
    	if ((a + b + c - d + 2) % 2 == 0) return false;
    	return true;
    };

    int p = rnd() % n + 1;
    // cout << p << "\n";
    for (int i = 1; i <= n; i++) {
    	if (i == p) continue;
    	f[i] = compare(min(p, i), max(p, i)) ^ (i > p);
    }

    for (int i = 2; i <= n; i++) {
    	int L = 0, R = a.size() - 1, res = -1;
    	while (L <= R) {
    		int mid = (L + R) / 2;
    		if (!cp(a[mid], i)) {
    			res = mid;
    			L = mid + 1;
    		} else {
    			R = mid - 1;
    		}
    	}
    	a.insert(a.begin() + res + 1, i);
    }

    vector<int> ans(n + 1);
    for (int i = 0; i < n; i++) {
    	ans[a[i]] = i + 1;
    }

    cout << "! ";
    for (int i = 1; i <= n; i++) {
    	cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 45ms
memory: 34880kb

input:

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

output:

? 1 108
? 2 109
? 1 109
? 2 108
? 3 109
? 3 108
? 4 109
? 4 108
? 5 109
? 5 108
? 6 109
? 6 108
? 7 109
? 7 108
? 8 109
? 8 108
? 9 109
? 9 108
? 10 109
? 10 108
? 11 109
? 11 108
? 12 109
? 12 108
? 13 109
? 13 108
? 14 109
? 14 108
? 15 109
? 15 108
? 16 109
? 16 108
? 17 109
? 17 108
? 18 109
? 1...

result:

wrong output format Unexpected end of file - int32 expected