結果
| 問題 | No.3617 Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-06 19:20:34 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| + 7µs | |
| コード長 | 1,295 bytes |
| 記録 | |
| コンパイル時間 | 1,691 ms |
| コンパイル使用メモリ | 225,588 KB |
| 実行使用メモリ | 43,904 KB |
| 最終ジャッジ日時 | 2026-08-06 19:20:50 |
| 合計ジャッジ時間 | 12,018 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サンプル | 0 % | AC * 4 |
| 小課題1 | 5 % | AC * 3 |
| 小課題2 | 5 % | AC * 5 |
| 小課題3 | 15 % | AC * 14 |
| 小課題4 | 20 % | AC * 21 |
| 小課題5 | 25 % | AC * 8 |
| 小課題6 | 10 % | AC * 8 |
| 小課題7 | 20 % | AC * 56 |
| 合計 | 3 * 100% = 300 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,q; cin >> N >> M >> q;
vector<pair<int,int>> LR(M);
vector<int> P(N),Q(N);
iota(P.begin(),P.end(),0),iota(Q.begin(),Q.end(),0);
for(auto &[l,r] : LR){
cin >> l >> r,l--,r--;
int pl = Q.at(l),pr = Q.at(r);
swap(P.at(pl),P.at(pr)),swap(Q.at(l),Q.at(r));
}
vector<vector<int>> To(N,vector<int>(60));
for(int i=0; i<N; i++) To.at(i).at(0) = Q.at(i);
for(int d=1; d<60; d++) for(int i=0; i<N; i++) To.at(i).at(d) = To.at(To.at(i).at(d-1)).at(d-1);
vector<int> answer(q);
vector<vector<tuple<long long,int,int>>> Query(M);
for(int i=0; i<q; i++){
long long t,x; cin >> t >> x,x--;
Query.at(t%M).push_back({t/M,x,i});
}
iota(P.begin(),P.end(),0),iota(Q.begin(),Q.end(),0);
for(int i=0; i<M; i++){
for(auto [t,pos,qpos] : Query.at(i)){
pos = Q.at(pos);
for(int d=0; d<60; d++) if((t>>d)&1) pos = To.at(pos).at(d);
answer.at(qpos) = pos;
}
auto [l,r] = LR.at(i);
int pl = Q.at(l),pr = Q.at(r);
swap(P.at(pl),P.at(pr)),swap(Q.at(l),Q.at(r));
}
for(auto a : answer) cout << a+1 << "\n";
}