結果
| 問題 | No.1558 Derby Live |
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2025-12-26 17:08:09 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,461 bytes |
| 記録 | |
| コンパイル時間 | 1,836 ms |
| コンパイル使用メモリ | 144,308 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-26 17:08:18 |
| 合計ジャッジ時間 | 7,939 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 33 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
using namespace std;
using ll = long long;
template<class S, S (*op)(S, S), S (*e)()>struct SegTree {
vector<S> seg;
int N = 1;
SegTree (ll n) : SegTree(vector<S>(n, e())) {}
SegTree (const vector<S> &v){
ll n = v.size();
while (N < n) N *= 2;
seg.resize(N*2-1, e());
for (ll i=0; i<n; i++) seg[i+N-1] = v[i];
for (ll i=N-2; i>=0; i--){
seg[i] = op(seg[i*2+1], seg[i*2+2]);
}
}
void set(int loc, S val){
loc += N-1;
seg[loc] = val;
while (loc != 0){
loc = (loc-1)/2;
seg[loc] = op(seg[loc*2+1], seg[loc*2+2]);
}
}
//op(a[l], ..., a[r])
S prod (int l, int r) const{
return _prod(l, r, 0, 0, N-1);
}
S all_prod() const{
return seg[0];
}
S _prod (int l, int r, int idx, int bitl, int bitr) const{
if (r < bitl || l > bitr) return e();
if (l <= bitl && bitr <= r) return seg[idx];
ll bitm = (bitl+bitr)/2;
return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr));
}
S get (int i) const{
return seg[i+N-1];
}
void show() const{
for (int i=N-1; i<N*2-1; i++) cout << seg[i] << " ";
cout << endl;
}
};
//RMQ
int N;
using S = vector<int>;
S id;
S op(S a, S b){
S c(N);
for (int i=0; i<N; i++) c[i] = b[a[i]];
return c;
}
S e(){
return id;
}
//
int main(){
int M, q, t, x, y, ans;
cin >> N >> M >> q;
for (int i=0; i<N; i++) id[i] = i;
SegTree<S, op, e> tree(M+1);
S P(N), Q(N);
while(q){
q--;
cin >> t;
if (t == 1){
cin >> x;
for (int i=0; i<N; i++){
cin >> P[i]; P[i]--;
}
tree.set(x, P);
}
else if (t == 2){
cin >> x;
P = tree.prod(0, x);
for (int i=0; i<N; i++) Q[P[i]] = i+1;
for (int i=0; i<N; i++) cout << Q[i] << " ";
cout << endl;
}
else{
cin >> x >> y;
ans = 0;
P = tree.prod(x, y);
for (int i=0; i<N; i++) ans += abs(P[i]-i);
cout << ans << endl;
}
}
return 0;
}
srjywrdnprkt