結果
問題 | No.1558 Derby Live |
ユーザー |
👑 ![]() |
提出日時 | 2021-06-25 21:33:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 1,101 ms |
コンパイル使用メモリ | 94,980 KB |
最終ジャッジ日時 | 2025-01-22 12:04:02 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
#include <iostream>#include <vector>#include <atcoder/segtree>using namespace std;using ll = long long;using ull = unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)struct S {int P[18];};S op(S l, S r) {rep(i,18) l.P[i] = r.P[l.P[i]];return l;}S e() {S res;rep(i,18) res.P[i] = i;return res;}using RQ = atcoder::segtree<S, op, e>;int main(){int N,M,Q;cin >> N >> M >> Q;RQ G(M);while(Q--){int t; cin >> t;if(t == 1){int d; cin >> d; d--;S v = e(); rep(i,N){ cin >> v.P[i]; v.P[i]--; }G.set(d,v);}if(t == 2){int d; cin >> d;S res = G.prod(0,d);int ans[18];rep(i,N) ans[res.P[i]] = i + 1;rep(i,N){if(i != 0) cout << " ";cout << ans[i];}cout << "\n";}if(t == 3){int l,r; cin >> l >> r; l--;S res = G.prod(l,r);int ans = 0;rep(i,N) ans += abs(i-res.P[i]);cout << ans << "\n";}}return 0;}struct ios_do_not_sync{ios_do_not_sync(){ios::sync_with_stdio(false);cin.tie(nullptr);}} ios_do_not_sync_inst;