結果

問題 No.1558 Derby Live
ユーザー abc3abc3
提出日時 2021-06-26 09:28:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 2,954 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 209,880 KB
実行使用メモリ 6,724 KB
最終ジャッジ日時 2023-09-07 15:17:17
合計ジャッジ時間 12,278 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
6,528 KB
testcase_01 AC 210 ms
6,428 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 171 ms
4,380 KB
testcase_04 AC 93 ms
4,380 KB
testcase_05 AC 116 ms
4,376 KB
testcase_06 AC 187 ms
4,384 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 181 ms
4,896 KB
testcase_09 AC 186 ms
5,440 KB
testcase_10 AC 190 ms
5,364 KB
testcase_11 AC 198 ms
5,496 KB
testcase_12 AC 200 ms
5,412 KB
testcase_13 AC 203 ms
5,904 KB
testcase_14 AC 204 ms
6,000 KB
testcase_15 AC 218 ms
5,952 KB
testcase_16 AC 221 ms
5,952 KB
testcase_17 AC 224 ms
6,548 KB
testcase_18 AC 228 ms
6,480 KB
testcase_19 AC 239 ms
6,468 KB
testcase_20 AC 256 ms
6,724 KB
testcase_21 AC 233 ms
6,552 KB
testcase_22 AC 243 ms
6,472 KB
testcase_23 AC 245 ms
6,412 KB
testcase_24 AC 230 ms
6,512 KB
testcase_25 AC 241 ms
6,640 KB
testcase_26 AC 246 ms
6,548 KB
testcase_27 AC 231 ms
6,672 KB
testcase_28 AC 240 ms
6,416 KB
testcase_29 AC 246 ms
6,476 KB
testcase_30 AC 234 ms
6,548 KB
testcase_31 AC 239 ms
6,528 KB
testcase_32 AC 245 ms
6,480 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=INT_MAX;
    const int mod=1e9+7;
    
    struct SegmentTree {
    private:
        int n;
        vector<vector<int>> node;
    
    public:
        vector<int>comp(vector<int>l,vector<int>r){
            int sz=l.size();
            vector<int>s(sz);
            rep(i,sz){s[i]=r[l[i]];}
            return s;
        }
        SegmentTree(int m,int sz) {
            n = 1; while(n < m) n *= 2;
            vector<int>res(sz);
            iota(res.begin(),res.end(),0);
            node.resize(2*n-1,res);
            for(int i=0; i<n; i++) node[i+n-1] = res;
            for(int i=n-2; i>=0; i--) node[i] = comp(node[2*i+1],node[2*i+2]);
        }
    
        void update(int x, vector<int> val) {
            x += (n - 1);
            node[x] = val;
            while(x > 0) {
                x = (x - 1) / 2;
                int sz=val.size();
                node[x] = comp(node[2*x+1],node[2*x+2]);
            }
        }
    
        vector<int> get(int a, int b, int sz,int k=0, int l=0, int r=-1) {
            vector<int>res(sz);
            iota(res.begin(),res.end(),0);
            if(r < 0) r = n;
            if(r <= a || b <= l) return res;
            if(a <= l && r <= b) return node[k];
    
            auto vl = get(a, b,sz, 2*k+1, l, (l+r)/2);
            auto vr= get(a, b,sz, 2*k+2, (l+r)/2, r);
            res=comp(vl,vr);
            return res;
        }
    };

    void solve(){
        int n,m,q;
        cin>>n>>m>>q;
        SegmentTree seg(m,n);
        rep(Q,q){
            int t;
            cin>>t;
            if(t==1){
                int d;
                cin>>d;d--;
                vector<int>p(n);
                rep(j,n){cin>>p[j];p[j]--;}
                seg.update(d,p);
            }
            else if(t==2){
                int s;
                cin>>s;
                vector<int>p=seg.get(0,s,n);
                vector<int>res(n);
                rep(j,n){res[p[j]]=j;}
                rep(j,n){
                  if(j){cout<<" ";}
                  cout<<res[j]+1;
                }cout<<endl;
            }
            else if(t==3){
                int l,r;
                cin>>l>>r;
                vector<int> p=seg.get(l-1,r,n);
                int ans=0;
                rep(j,n){ans+=abs(p[j]-j);}
                cout<<ans<<endl;
            }
        }
    }

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