QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371685 | #6303. Inversion | ucup-team956 | WA | 58ms | 35076kb | C++17 | 1.7kb | 2024-03-30 14:57:46 | 2024-03-30 14:58:16 |
Judging History
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);
// cout << "---- " << pos[mid] << " ";
// cout << ask(pos[mid], i) << " " << ask(pos[mid] + 1, i) << " " << ask(pos[mid], i - 1) << " " << ask(pos[mid] + 1, i - 1) << endl;
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;
// cout << a[i] << "\n";
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: 100
Accepted
time: 1ms
memory: 3532kb
input:
3 0 0 1
output:
? 1 2 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Wrong Answer
time: 58ms
memory: 35076kb
input:
1993 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 1 0 0 0 1 1 0 1 1 0...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 6 7 ? 5 7 ? 6 8 ? 7 8 ? 3 8 ? 4 8 ? 5 8 ? 6 9 ? 7 9 ? 3 9 ? 4 9 ? 5 9 ? 8 9 ? 2 10 ? 3 10 ? 4 10 ? 5 10 ? 9 10 ? 2 11 ? 3 11 ? 10 11 ? 9 11 ? 3 12 ? 4 12 ? 11 12 ? 9 12 ? 10 12 ? 8 12 ? 3 13 ? 4 13 ? 11 13 ? 12 13 ? 8 13 ? 9 1...
result:
wrong answer Wa.