QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#333693#6303. InversionautomacWA 79ms5468kbC++202.5kb2024-02-20 12:44:162024-02-20 12:44:17

Judging History

你现在查看的是最新测评结果

  • [2024-02-20 12:44:17]
  • 评测
  • 测评结果:WA
  • 用时:79ms
  • 内存:5468kb
  • [2024-02-20 12:44:16]
  • 提交

answer

#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define fored(i, l, r) for(int i = (int)r; i >= (int)l; --i)
#define all(x) x.begin(), x.end()
#define el '\n'
#define d(x) cerr << #x << ' ' << x << el

#define sz(a) (int) a.size()
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef array<int, 4> a4;
typedef pair<int,int> ii;
typedef tuple<ll,int,int> iii;
const int nax = 3e3;
// const int nax = 2e3;

const ll inf = 1e17;
// void show(vi &v){
//     for(int x : v)cout<<x<<" ";
//     cout<<el;
// }
int qs = 0;
int cur;
int suf[nax];
map<int,int> query[nax];
bool find(int i, int j){
    if(i==j)return 0;
    if(j <= cur) return suf[i];
    if(query[i].find(j) != query[i].end()) return query[i][j];
    ++qs;
    cout<<"? "<<i<<" "<<j<<el;
    cout.flush();
    bool parity;
    cin>>parity;
    assert(qs <= 40000);
    return query[i][j] = parity;
}

bool isGreater(int i, int j){
    if(j-i <= 1) return find(i,j);
    int allRange = find(i, j);
    int excL = find(i+1, j), excR = find(i, j-1);
    int excAll = find(i+1, j-1);
    if(((excL + excR - excAll + 2) % 2) != allRange) return 1;
    return 0;

}
void solve(){
    int n;
    cin>>n;
    if(n == 1){
        cout<<"! 1"<<endl;
        return;
    }
    vi v(n);
    iota(all(v), 1);
    if(isGreater(v[0],v[1])){
        swap(v[0], v[1]);
        suf[1] = 1;
    }
    cur = 1;

    fore(i,2,n-1){
        int lo = -1, hi = i;
        cur = i;
        while(lo + 1 < hi){
            int mid = lo + (hi-lo)/2;
            if(isGreater(v[mid], v[i])){
                hi = mid;
            }else lo = mid;
        }
        assert(v[i] == i+1);
        int par = 0;
        fored(j,1, i){// 1 - indexed
            if(j > hi){
                par ^= 1;
                swap(v[j-1], v[j]); // 0 - indexed
            }
            suf[j] ^= par; // 1 - indexed
        }
    }

    vi ans(n);
    forn(i,n){
        ans[v[i]-1] = i+1;
    }
    cout<<"! ";
    forn(i,n){
        cout<<ans[i];
        if(i!=n-1) cout<<" ";
    }
    cout<<el;
    cout.flush();
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt = 1;
    // cin>>tt;
    while(tt--){
        solve();
    }
}

/**
 * aprendizaje: 
 * Fijar 2 elementos y pensar como ordenarlos. Pensar en reducir la cantidad de consultas
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3672kb

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: 79ms
memory: 5468kb

input:

1993
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
0
0
0
0
1
1
0
0
1
1
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
1
1
0
1
1
0
0
0
1
0
1
0
1
0
1
0
0
0
0
1
1
0
0
0
1
1
1
1
1
1
1
0
0
1
1
0
0
1
0
1
0
0
1
0
0
1
0
0
0
1
1
1
1
0
0
1
1
0
1
0
0
0
0
0
0
1
0
0
1
0
0
1
0
0
1
0
0
1
0
0
1
0
1
1
0
1
0
0
1
0
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
? 1 7
? 2 7
? 3 7
? 4 7
? 7 8
? 3 8
? 4 8
? 5 8
? 7 9
? 8 9
? 6 9
? 1 9
? 2 9
? 7 10
? 8 10
? 3 10
? 4 10
? 9 10
? 7 11
? 8 11
? 10 11
? 9 11
? 2 12
? 3 12
? 11 12
? 8 12
? 9 12
? 4 12
? 5 12
? 2 13
? 3 13
? 11 13
? 12 13
? 4 13...

result:

wrong answer Wa.