結果

問題 No.2002 Range Swap Query
ユーザー t98slidert98slider
提出日時 2022-07-08 22:23:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 184,048 KB
実行使用メモリ 32,136 KB
最終ジャッジ日時 2023-08-27 22:04:23
合計ジャッジ時間 7,225 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 412 ms
31,784 KB
testcase_13 AC 411 ms
32,136 KB
testcase_14 AC 414 ms
31,856 KB
testcase_15 AC 395 ms
31,412 KB
testcase_16 AC 317 ms
31,272 KB
testcase_17 AC 407 ms
31,784 KB
testcase_18 AC 202 ms
10,960 KB
testcase_19 AC 308 ms
15,564 KB
testcase_20 AC 192 ms
24,040 KB
testcase_21 AC 144 ms
8,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    int N, K, Q, u, v;
    cin >> N >> K >> Q;
    vector<priority_queue<pair<int,int>>> a(N);
    vector<pair<int,int>> b(K);
    vector<int> ans(Q);
    vector<vector<tuple<int,int,int>>> tb(K);
    for(int i = 0; i < K; i++){
        cin >> u >> v;
        b[i] = {--u, --v};
    }
    for(int i = 0, l, r, x; i < Q; i++){
        cin >> l >> r >> x;
        tb[--r].emplace_back(--l, --x, i);
    }
    for(int i = K - 1; i >= 0; i--){
        tie(u, v) = b[i];
        while(!a[u].empty() && a[u].top().first > i){
            ans[a[u].top().second] = u;
            a[u].pop();
        }
        while(!a[v].empty() && a[v].top().first > i){
            ans[a[v].top().second] = v;
            a[v].pop();
        }
        //swap(a[u], a[v]);
        for(auto &&tup:tb[i]){
            int l, x, idx;
            tie(l, x, idx) = tup;
            a[x].emplace(l, idx);
        }
        swap(a[u], a[v]);
    }
    for(int i = 0; i < N; i++){
        while(!a[i].empty()){
            ans[a[i].top().second] = i;
            a[i].pop();
        }
    }
    for(int i = 0; i < Q; i++){
        cout << ans[i] + 1 << '\n';
    }
}
0