QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#694860 | #6303. Inversion | ucup-team2179# | RE | 0ms | 3608kb | C++20 | 1.8kb | 2024-10-31 18:49:56 | 2024-10-31 18:49:57 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2999;
int n, pos[N], p[N], cnt, vis[N][N], ans[N][N];
int ask(int l, int r){
if(l == r)
return 0;
if(vis[l][r])
return ans[l][r];
cout << "? " << l << " " << r << '\n';
cout.flush();
cnt++;
assert(cnt <= 40000);
int x;
cin >> x;
ans[l][r] = x;
vis[l][r] = 1;
return x;
}
//int a[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// int ask(int l, int r){
// //cout << l << " " << r << '\n';
// int x = 0;
// for (int i = l; i <= r; i++)
// for (int j = i + 1; j <= r; j++)
// if(a[j] < a[i])
// x ^= 1;
// //cout << x << '\n';
// return x;
// }
int count(int id, int l, int r){
int x = 0;
for (int j = l; j <= r; j++)
if(p[j] < p[id])
x ^= 1;
return x;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
pos[1] = p[1] = 1;
for (int i = 2; i <= n; i++){
if(ask(pos[i-1], i) == ask(pos[i-1] + 1, i) ^ count(pos[i-1], pos[i-1], i-1)){
p[i] = i;
pos[i] = i;
continue;
}
int l = 1, r = i - 1, mid;
while(l < r){
mid = (l + r) >> 1;
if(ask(pos[mid], i) != ask(pos[mid] + 1, i) ^ count(pos[mid], pos[mid], i-1))
r = mid;
else
l = mid + 1;
}
p[i] = l;
pos[l] = i;
for (int j = 1; j < i; j++)
if(p[j] >= l){
p[j]++;
pos[p[j]] = j;
}
}
cout << "! ";
for(int i = 1; i <= n; i++)
cout << p[i] << " \n"[i == n];
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
3 0 1 0
output:
? 1 2 ? 2 3 ? 1 3 ! 2 3 1
result:
ok OK, guesses=3
Test #2:
score: -100
Runtime Error
input:
1993 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1...
output:
? 1 2 ? 2 3 ? 3 4 ? 4 5 ? 2 5 ? 3 5 ? 1 5 ? 4 6 ? 5 6 ? 2 6 ? 3 6 ? 1 6 ? 4 7 ? 5 7 ? 1 7 ? 2 7 ? 6 7 ? 4 8 ? 5 8 ? 1 8 ? 2 8 ? 3 8 ? 4 9 ? 5 9 ? 1 9 ? 2 9 ? 8 9 ? 3 9 ? 4 10 ? 5 10 ? 9 10 ? 6 10 ? 7 10 ? 8 10 ? 4 11 ? 5 11 ? 1 11 ? 2 11 ? 8 11 ? 9 11 ? 3 11 ? 10 11 ? 4 12 ? 5 12 ? 11 12 ? 8 12 ? 9 ...