QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#371526 | #6303. Inversion | ucup-team956 | WA | 0ms | 3680kb | C++17 | 1.5kb | 2024-03-30 13:42:41 | 2024-03-30 13:42:43 |
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);
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] << " ";
}
详细
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.