結果

問題 No.1558 Derby Live
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-12 23:41:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 2,504 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 122,496 KB
実行使用メモリ 7,592 KB
最終ジャッジ日時 2023-09-02 16:41:25
合計ジャッジ時間 14,037 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
7,288 KB
testcase_01 AC 242 ms
7,592 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 165 ms
4,380 KB
testcase_04 AC 82 ms
4,504 KB
testcase_05 AC 94 ms
4,380 KB
testcase_06 AC 158 ms
4,572 KB
testcase_07 AC 6 ms
4,496 KB
testcase_08 AC 156 ms
5,512 KB
testcase_09 AC 166 ms
6,088 KB
testcase_10 AC 170 ms
6,096 KB
testcase_11 AC 174 ms
6,100 KB
testcase_12 AC 179 ms
6,024 KB
testcase_13 AC 193 ms
6,812 KB
testcase_14 AC 199 ms
6,728 KB
testcase_15 AC 204 ms
6,680 KB
testcase_16 AC 209 ms
6,728 KB
testcase_17 AC 216 ms
7,592 KB
testcase_18 AC 225 ms
7,288 KB
testcase_19 AC 229 ms
7,208 KB
testcase_20 AC 237 ms
7,240 KB
testcase_21 AC 225 ms
7,240 KB
testcase_22 AC 238 ms
7,236 KB
testcase_23 AC 240 ms
7,212 KB
testcase_24 AC 222 ms
7,244 KB
testcase_25 AC 234 ms
7,212 KB
testcase_26 AC 236 ms
7,212 KB
testcase_27 AC 221 ms
7,268 KB
testcase_28 AC 234 ms
7,240 KB
testcase_29 AC 239 ms
7,424 KB
testcase_30 AC 225 ms
7,212 KB
testcase_31 AC 233 ms
7,248 KB
testcase_32 AC 240 ms
7,288 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 identity;

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 identity;
}
//
 
int main(){
 
    int M, q, t, x, y, ans;
    cin >> N >> M >> q;
    identity.resize(N);
    for (int i=0; i<N; i++) identity[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;
}
0