結果

問題 No.2740 Old Maid
ユーザー t98slider
提出日時 2024-04-20 13:35:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 4,550 ms
コンパイル使用メモリ 254,792 KB
最終ジャッジ日時 2025-02-21 06:29:14
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

using S = pair<int,int>;
S op(S lhs, S rhs){
    return min(lhs, rhs);
}
S e(){
    return make_pair(1 << 30, -1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, j = 0;
    cin >> n;
    vector<S> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i].first;
        p[i].second = i;
    }
    atcoder::segtree<S, op, e> seg(p);
    for(int i = 0; i < n; i += 2){
        int p1 = seg.all_prod().second;
        int p2 = seg.max_right(p1 + 1, [&](S v){return v == e();});
        if(p2 == n){
            p1 = seg.prod(0, p1).second;
            p2 = seg.max_right(p1 + 1, [&](S v){return v == e();});
        }
        cout << p[p1].first << ' ' << p[p2].first << (i + 2 == n ? '\n' : ' ');
        seg.set(p1, e());
        seg.set(p2, e());
    }
}
0