QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295708#4831. Eager Sortingucup-team2307#0 0ms0kbC++201.7kb2023-12-31 19:38:272023-12-31 19:38:28

Judging History

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

  • [2023-12-31 19:38:28]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-12-31 19:38:27]
  • 提交

answer

#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using ll = long long;
using namespace std;

const int local = 0;
vector<int> hidden;

int ask(int l, int r) {
    cout << "? " << l << " " << r << endl;
    if(!local) {
        cin >> l;
        if(l == -1) exit(0);
    } else {
        l--, r--;
        if(l > r) swap(l, r);
        if(hidden[l] > hidden[r]) {
            swap(hidden[l], hidden[r]);
            return 1;
        }
        return 0;
    }
    return l;
}

vector<int> merge_sort(int l, int r) {
    if(l == r) return { l };
    int m = (l + r) / 2;
    auto L = merge_sort(l, m);
    auto R = merge_sort(m + 1, r);
    vector<int> ord;

    int x = 0, y = 0;
    while(x < L.size() && y < R.size()) {
        int t = ask(L[x], R[y]);
        ord.push_back(min(L[x], R[y]));
        if(t) swap(L[x], R[y]);
        if(L[x] < R[y]) x++;
        else y++;
    }
    ord.insert(ord.end(), x + all(L));
    ord.insert(ord.end(), y + all(R));
    return ord;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    if(local) {
        mt19937 rng(123);
        hidden.resize(n);
        iota(all(hidden), 1);
        shuffle(all(hidden), rng);
    }
    auto ord = merge_sort(1, n);
    vector<int> a(n + 1);
    // for(auto i : ord) cout << i << " "; cout << endl;
    for(int i = 0; i < n; i++)
        a[ord[i]] = i + 1;
    for(int i = 1; i <= n; i++) {
        int p = find(all(a), i) - a.begin();
        if(p != i) {
            ask(i, p);
        }
        swap(a[i], a[p]);
    }
    // for(auto i : a) cout << i << " "; cout << endl;

    cout << "-1 -1" << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Instance #1 Time Limit Exceeded

Interactor to First Run

5

First Run to Interactor

? 1 2

Interactor to Second Run


Second Run to Interactor


Manager to Checker

WA
Invalid Operation 778886360 22085

result: