QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371487 | #6303. Inversion | ucup-team956 | WA | 72ms | 35000kb | C++17 | 1.4kb | 2024-03-30 13:15:48 | 2024-03-30 13:15:50 |
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;
f[1][1] = 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[i][j] = f[i - 1][j] + 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: 0ms
memory: 3592kb
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: 72ms
memory: 35000kb
input:
1993 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 2 5 ? 3 5 ? 1 5 ? 1 4 ? 2 6 ? 3 6 ? 5 6 ? 1 6 ? 1 7 ? 2 7 ? 5 7 ? 6 7 ? 1 8 ? 2 8 ? 3 8 ? 4 8 ? 3 7 ? 4 7 ? 1 9 ? 2 9 ? 8 9 ? 3 9 ? 9 10 ? 5 10 ? 6 10 ? 5 9 ? 6 9 ? 7 10 ? 8 10 ? 7 9 ? 1 11 ? 2 11 ? 1 10 ? 2 10 ? 8 11 ? 9 11 ? 10 11 ? 11 12 ? 8 12 ? 9 12 ? 10 12 ? 2 1...
result:
wrong output format Unexpected end of file - int32 expected