結果
問題 | No.2002 Range Swap Query |
ユーザー |
|
提出日時 | 2022-07-08 22:23:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 444 ms / 2,000 ms |
コード長 | 1,299 bytes |
コンパイル時間 | 2,292 ms |
コンパイル使用メモリ | 186,380 KB |
実行使用メモリ | 32,256 KB |
最終ジャッジ日時 | 2024-12-28 06:33:33 |
合計ジャッジ時間 | 7,557 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#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';}}