QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210089#6303. InversiontherehelloTL 0ms0kbC++201.5kb2023-10-11 00:58:092023-10-11 00:58:09

Judging History

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

  • [2023-10-11 00:58:09]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-11 00:58:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    // vector<int> p(n + 1);
    // for (int i = 1; i <= n; i++) cin >> p[i];

    vector _f(n + 1, vector<int>(n + 1, -1));
    // for (int l = 1; l <= n; l++) {
    //     int cnt = 0;
    //     for (int r = l + 1; r <= n; r++) {
    //         for (int i = l; i < r; i++) cnt += p[i] > p[r];
    //         _f[l][r] = cnt;
    //     }
    // }
    auto f = [&](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;
        return _f[l][r] = x;
    };

    vector<int> a{1};
    for (int i = 2; i <= n; i++) {
        auto pos = lower_bound(a.begin(), a.end(), i, [&](int l, int r) {
            int x = f(l, r) - f(l + 1, r) - f(l, r - 1) + f(l + 1, r - 1);
            x = (x % 2 + 2) % 2;
            return !x;
        });
        a.insert(pos, i);
    }
    vector<int> ans(n + 1);
    for (int i = 0; i < n; i++) ans[a[i]] = i + 1;

    // assert(ans == p);
    cout << "! ";
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) solve();
#ifdef DEBUG
    cout << "\n----------------\n";
    cout << fixed << setprecision(6);
    cout << "Times: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3

output:


result: