QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#694445 | #6303. Inversion | ucup-team2179# | WA | 31ms | 3688kb | C++20 | 1.1kb | 2024-10-31 17:58:05 | 2024-10-31 17:58:05 |
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];
int ask(int l, int r){
if(l == r)
return 0;
cout << "? " << l << " " << r << '\n';
cout.flush();
int x;
cin >> x;
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)){
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))
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: 1ms
memory: 3668kb
input:
3 0 1 0 1
output:
? 1 2 ? 2 3 ? 1 3 ? 2 3 ! 2 3 1
result:
ok OK, guesses=4
Test #2:
score: -100
Wrong Answer
time: 31ms
memory: 3688kb
input:
1993 0 0 0 1 1 0 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 0 1...
output:
? 1 2 ? 2 3 ? 3 4 ? 4 5 ? 2 5 ? 3 5 ? 1 5 ? 2 5 ? 4 6 ? 5 6 ? 6 7 ? 2 7 ? 3 7 ? 1 7 ? 2 7 ? 5 7 ? 6 7 ? 6 8 ? 7 8 ? 2 8 ? 3 8 ? 5 8 ? 6 8 ? 7 8 ? 6 9 ? 7 9 ? 1 9 ? 2 9 ? 8 9 ? 7 9 ? 8 9 ? 6 10 ? 7 10 ? 10 11 ? 11 12 ? 12 13 ? 13 14 ? 3 14 ? 4 14 ? 5 14 ? 6 14 ? 9 14 ? 10 14 ? 7 14 ? 8 14 ? 13 15 ? 1...
result:
wrong answer Wa.