結果

問題 No.1558 Derby Live
ユーザー homer12homer12
提出日時 2021-06-26 20:23:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 2,840 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 209,072 KB
実行使用メモリ 9,580 KB
最終ジャッジ日時 2023-09-07 15:32:24
合計ジャッジ時間 10,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 271 ms
9,580 KB
testcase_01 AC 172 ms
9,068 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 139 ms
4,712 KB
testcase_04 AC 73 ms
5,060 KB
testcase_05 AC 88 ms
4,812 KB
testcase_06 AC 151 ms
5,876 KB
testcase_07 AC 6 ms
6,064 KB
testcase_08 AC 146 ms
6,424 KB
testcase_09 AC 147 ms
6,388 KB
testcase_10 AC 149 ms
7,084 KB
testcase_11 AC 157 ms
6,896 KB
testcase_12 AC 169 ms
7,420 KB
testcase_13 AC 172 ms
7,380 KB
testcase_14 AC 174 ms
7,876 KB
testcase_15 AC 176 ms
7,888 KB
testcase_16 AC 181 ms
8,448 KB
testcase_17 AC 187 ms
8,540 KB
testcase_18 AC 196 ms
8,668 KB
testcase_19 AC 199 ms
8,540 KB
testcase_20 AC 207 ms
9,144 KB
testcase_21 AC 197 ms
8,560 KB
testcase_22 AC 201 ms
8,524 KB
testcase_23 AC 211 ms
9,152 KB
testcase_24 AC 199 ms
8,648 KB
testcase_25 AC 200 ms
8,632 KB
testcase_26 AC 208 ms
9,096 KB
testcase_27 AC 195 ms
8,568 KB
testcase_28 AC 203 ms
8,520 KB
testcase_29 AC 204 ms
9,124 KB
testcase_30 AC 196 ms
8,576 KB
testcase_31 AC 201 ms
8,552 KB
testcase_32 AC 206 ms
9,160 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 2 ms
4,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(ll)(s), i_stop=(ll)(e); i<i_stop; ++i)
#define range(i,s,n) for(ll i=(ll)(s), i_stop=(ll)((s)+(n)); i<i_stop; ++i)
#define foreach(x,container) for(auto &&x:container)
template<typename S, typename T> bool chmax(T& a, S b) {b = (T)b; if(a<b) {a=b;return true;} return false;}
template<typename S, typename T> bool chmin(T& a, S b) {b = (T)b; if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
    for(auto &x:arr) {cout << x << " ";} cout << endl;
}

// =====================================================>

// 排名 0-indexed
#define maxm 10000
lvector tree[4*maxm+10];
lvector E;
ll n,q,m,M; // M是剛好大於等於_m的2的冪. M = 2^(ceil(log(m,2)))

void init(ll _m){
    ll x = 1; while(x < m) x <<= 1;
    M = x;
    range(j, 0, n) E.push_back(j);
    range(i, 0, 2*M-1) tree[i] = E;    
}

lvector merge(lvector a, lvector b) {
    lvector c(n);
    range(i,0,n) c[i] = b[a[i]];
    return c;
}

void update(ll k, lvector p) {
    k = k+M-1;
    tree[k] = p;
    while(k) {
        k = (k-1)/2;
        tree[k] = merge(tree[2*k+1], tree[2*k+2]);
    }
}

lvector _rmq(ll a, ll b, ll k, ll l, ll r) {
    // 1. 無交集
    if(b<=l || r<=a) return E;
    // 2. 這個區間是解區間的一個子集
    if(a<=l && r<=b) return tree[k];
    
    ll mid = l + (r-l)/2;
    lvector v1 = _rmq(a, b, 2*k+1, l, mid);
    lvector v2 = _rmq(a, b, 2*k+2, mid, r);
    return merge(v1, v2);
}
lvector rmq(ll a, ll b) {
    return _rmq(a, b, 0, 0, M);
}

void solve() {
    cin>>n>>m>>q;
    init(m+1);

    while(q--) {
        ll op; cin>>op;
        if(op == 1) {
            ll d; cin>>d;
            lvector tmp(n); range(i,0,n) {cin>>tmp[i]; --tmp[i];}
            update(d, tmp);
        }else if(op == 2) {
            ll s; cin>>s;
            lvector tmp = rmq(0, s+1);
            lvector res(n);
            range(i,0,n) res[tmp[i]] = i+1;
            for(auto x: res) cout<<x<<" "; cout<<"\n";
        }else{
            ll l,r; cin>>l>>r;
            lvector resl = rmq(0, l);
            lvector resr = rmq(0, r+1);
            ll ans = 0;
            range(i, 0, resl.size()) ans += labs(resl[i] - resr[i]);
            cout<<ans<<endl;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
0