結果

問題 No.3590 I Love Inversions
コンテスト
ユーザー otoshigo
提出日時 2026-07-17 21:47:26
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2,158 ms / 5,000 ms
+ 33µs
コード長 1,644 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,124 ms
コンパイル使用メモリ 345,424 KB
実行使用メモリ 6,656 KB
平均クエリ数 12103.46
最終ジャッジ日時 2026-07-17 21:48:04
合計ジャッジ時間 25,168 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }

template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_heap = priority_queue<T>;

#include <atcoder/fenwicktree>

void solve() {
    int N;
    cin >> N;
    vector<ll> inv(N);
    rep(r, 1, N) {
        cout << "? " << 1 << " " << r + 1 << endl;
        cin >> inv[r];
    }
    vector<int> ans(N);
    atcoder::fenwick_tree<int> fw(N);
    rep(i, 0, N) fw.add(i, 1);
    set<int> se;
    rep(i, 0, N) se.insert(i);
    rrep(r, 1, N) {
        int diff = inv[r] - inv[r - 1];
        int ok = N - 1, ng = -1;
        while (ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if (fw.sum(mid + 1, N) <= diff) ok = mid;
            else ng = mid;
        }
        ans[r] = ok;
        fw.add(ok, -1);
        se.erase(ok);
    }
    ans[0] = *se.begin();
    cout << "! ";
    rep(i, 0, N) cout << ans[i] + 1 << " ";
    cout << endl;
}

int main() {
    // cin.tie(0)->sync_with_stdio(0);
    // cout << fixed << setprecision(15);
    srand(time(NULL));

    int T;
    // cin >> T;
    T = 1;
    while (T--) solve();
}
0