結果

問題 No.1558 Derby Live
ユーザー monnumonnu
提出日時 2021-06-25 23:38:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 1,871 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 173,012 KB
実行使用メモリ 6,756 KB
最終ジャッジ日時 2023-09-07 15:07:54
合計ジャッジ時間 10,266 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 212 ms
6,608 KB
testcase_01 AC 211 ms
6,516 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 157 ms
4,380 KB
testcase_04 AC 68 ms
4,376 KB
testcase_05 AC 78 ms
4,376 KB
testcase_06 AC 145 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 132 ms
4,908 KB
testcase_09 AC 140 ms
5,560 KB
testcase_10 AC 147 ms
5,564 KB
testcase_11 AC 154 ms
5,432 KB
testcase_12 AC 155 ms
5,360 KB
testcase_13 AC 165 ms
5,888 KB
testcase_14 AC 168 ms
6,020 KB
testcase_15 AC 178 ms
6,072 KB
testcase_16 AC 184 ms
5,904 KB
testcase_17 AC 191 ms
6,604 KB
testcase_18 AC 195 ms
6,460 KB
testcase_19 AC 205 ms
6,736 KB
testcase_20 AC 215 ms
6,516 KB
testcase_21 AC 197 ms
6,492 KB
testcase_22 AC 203 ms
6,536 KB
testcase_23 AC 212 ms
6,500 KB
testcase_24 AC 195 ms
6,432 KB
testcase_25 AC 210 ms
6,464 KB
testcase_26 AC 212 ms
6,488 KB
testcase_27 AC 198 ms
6,412 KB
testcase_28 AC 210 ms
6,460 KB
testcase_29 AC 213 ms
6,532 KB
testcase_30 AC 195 ms
6,460 KB
testcase_31 AC 210 ms
6,756 KB
testcase_32 AC 210 ms
6,592 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,pair<int,int>>>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 1000000000

int n=1;
vector<vector<int>> order;
vector<int> order_base;
vector<int> solve(int a,int b,int i,int left,int right){
  if(a<=left&&right<=b){
    return order[i];
  }
  if(b<=left||right<=a){
    return order_base;
  }
  vector<int> vec1=solve(a,b,2*i+1,left,(left+right)/2);
  vector<int> vec2=solve(a,b,2*i+2,(left+right)/2,right);
  int N=order[i].size();
  vector<int> ret(N);
  for(int j=0;j<N;j++){
    ret[j]=vec2[vec1[j]];
  }
  return ret;
}
void update(int d,vector<int> &P){
  d+=n-1;
  for(int j=0;j<P.size();j++){
    order[d][j]=P[j];
  }
  while(d>0){
    d=(d-1)/2;
    for(int j=0;j<P.size();j++){
      order[d][j]=order[2*d+2][order[2*d+1][j]];
    }
  }
}

int main(){
  int N,M,Q;
  cin>>N>>M>>Q;
  while(n<M){
    n<<=1;
  }
  order.resize(2*n-1);
  for(int i=0;i<2*n-1;i++){
    order[i].resize(N);
    for(int j=0;j<N;j++){
      order[i][j]=j;
    }
  }
  order_base.resize(N);
  for(int j=0;j<N;j++){
    order_base[j]=j;
  }

  for(int i=0;i<Q;i++){
    int q;
    cin>>q;
    if(q==1){
      int D;
      vector<int> P(N);
      cin>>D;
      D--;
      for(int j=0;j<N;j++){
        cin>>P[j];
        P[j]--;
      }
      update(D,P);
    }else if(q==2){
      int S;
      cin>>S;
      vector<int> P=solve(0,S,0,0,n);
      for(int j=0;j<N;j++){
        for(int k=0;k<N;k++){
          if(P[k]==j){
            cout<<k+1<<" ";
            break;
          }
        }
      }
      cout<<endl;
    }else{
      int L,R;
      cin>>L>>R;
      L--;
      vector<int> P=solve(L,R,0,0,n);
      int ans=0;
      for(int i=0;i<N;i++){
        ans+=abs(i-P[i]);
      }
      cout<<ans<<endl;
    }
  }
}
0