結果

問題 No.1558 Derby Live
ユーザー abc3abc3
提出日時 2021-06-26 08:57:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,925 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 210,780 KB
実行使用メモリ 6,736 KB
最終ジャッジ日時 2023-09-07 15:17:04
合計ジャッジ時間 11,253 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 330 ms
6,424 KB
testcase_01 AC 201 ms
6,460 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
            }
            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){printf("%d%c",res[j]+1,(j==n-1?'\n':' '));}
            }
            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