結果

問題 No.1558 Derby Live
ユーザー HaaHaa
提出日時 2021-06-25 22:00:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 2,226 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 175,684 KB
実行使用メモリ 8,984 KB
最終ジャッジ日時 2023-09-07 14:31:21
合計ジャッジ時間 12,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
8,792 KB
testcase_01 AC 291 ms
8,924 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 201 ms
4,376 KB
testcase_04 AC 101 ms
4,408 KB
testcase_05 AC 120 ms
4,376 KB
testcase_06 AC 203 ms
4,632 KB
testcase_07 AC 7 ms
4,968 KB
testcase_08 AC 198 ms
5,888 KB
testcase_09 AC 203 ms
6,064 KB
testcase_10 AC 207 ms
6,412 KB
testcase_11 AC 219 ms
6,436 KB
testcase_12 AC 231 ms
6,676 KB
testcase_13 AC 242 ms
6,676 KB
testcase_14 AC 247 ms
7,344 KB
testcase_15 AC 252 ms
7,268 KB
testcase_16 AC 261 ms
7,792 KB
testcase_17 AC 272 ms
7,816 KB
testcase_18 AC 282 ms
8,292 KB
testcase_19 AC 292 ms
8,344 KB
testcase_20 AC 292 ms
8,788 KB
testcase_21 AC 281 ms
8,456 KB
testcase_22 AC 290 ms
8,384 KB
testcase_23 AC 294 ms
8,936 KB
testcase_24 AC 276 ms
8,304 KB
testcase_25 AC 287 ms
8,392 KB
testcase_26 AC 293 ms
8,884 KB
testcase_27 AC 277 ms
8,344 KB
testcase_28 AC 287 ms
8,440 KB
testcase_29 AC 292 ms
8,788 KB
testcase_30 AC 276 ms
8,320 KB
testcase_31 AC 285 ms
8,260 KB
testcase_32 AC 293 ms
8,984 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

template<typename X>
struct Segtree{
    using F=function<X(X,X)>;
    int n; F f; X ex;
    vector<X> dat;
    Segtree(int n_, F f, X ex)
        :f(f), ex(ex){
        n=1;
        while(n_>n){n*=2;}
        dat.assign(2*n,ex);
    }
    void set(int i, X x){
        dat[i+n-1]=x;
    }
    void build(){
        for(int k=n-2;k>=0;k--) 
            dat[k]=f(dat[2*k+1],dat[2*k+2]);
    }
    void update(int i, X x){
        i+=n-1;
        dat[i]=x;
        while(i>0){
            i=(i-1)/2;
            dat[i]=f(dat[i*2+1],dat[i*2+2]);
        }
    }
    X query(int a, int b){
        return query_sub(a,b,0,0,n);
    }
    X query_sub(int a, int b, int k, int l, int r){
        if(r<=a||b<=l)
            return ex;
        else if(a<=l&&r<=b)
            return dat[k];
        else{
            X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
            X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
            return f(vl,vr);
        }
    }
};

VI f(VI a, VI b){
    int n=a.size();
    VI ret(n);
    REP(i,n){
        ret[i]=b[a[i]];
    }
    return ret;
}

int main(){
    int n, m, q; cin >> n >> m >> q;
    VI e(n); iota(ALL(e),0);
    Segtree<VI> seg(m+1,f,e);
    int t, d, x, s, l, r, sum;
    VI p(n);
    REP(i,q){
        cin >> t;
        if(t==1){
            cin >> d;
            REP(j,n) cin >> p[j], p[j]--;
            seg.update(d,p);
        }
        else if(t==2){
            cin >> s;
            VI ans=seg.query(0,s+1);
            VI ans2(n);
            REP(j,n) ans2[ans[j]]=j;
            REP(j,n) cout << ans2[j]+1 << " ";
            cout << endl;
        }
        else{
            cin >> l >> r;
            VI ans=seg.query(l,r+1);
            sum=0;
            REP(j,n) sum+=abs(j-ans[j]);
            cout << sum << endl;
        }
    }
    return 0;
}
0