結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー umezoumezo
提出日時 2020-07-19 02:29:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,065 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 198,484 KB
実行使用メモリ 8,716 KB
最終ジャッジ日時 2023-08-21 15:35:57
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,568 KB
testcase_01 AC 2 ms
7,464 KB
testcase_02 AC 3 ms
7,472 KB
testcase_03 AC 56 ms
8,548 KB
testcase_04 AC 65 ms
8,620 KB
testcase_05 AC 57 ms
8,420 KB
testcase_06 AC 52 ms
8,532 KB
testcase_07 AC 64 ms
6,864 KB
testcase_08 AC 5 ms
7,516 KB
testcase_09 AC 34 ms
6,396 KB
testcase_10 AC 57 ms
8,452 KB
testcase_11 AC 2 ms
7,456 KB
testcase_12 AC 66 ms
8,548 KB
testcase_13 AC 66 ms
8,716 KB
testcase_14 AC 66 ms
8,480 KB
testcase_15 AC 2 ms
7,572 KB
testcase_16 AC 2 ms
7,752 KB
testcase_17 AC 2 ms
7,420 KB
testcase_18 AC 3 ms
7,412 KB
testcase_19 AC 2 ms
7,456 KB
testcase_20 AC 2 ms
7,744 KB
testcase_21 AC 3 ms
7,452 KB
testcase_22 AC 2 ms
5,704 KB
testcase_23 AC 7 ms
7,548 KB
testcase_24 AC 24 ms
6,248 KB
testcase_25 AC 49 ms
6,700 KB
testcase_26 AC 13 ms
7,612 KB
testcase_27 AC 29 ms
6,000 KB
testcase_28 AC 40 ms
6,348 KB
testcase_29 AC 53 ms
8,300 KB
testcase_30 AC 63 ms
6,852 KB
testcase_31 AC 17 ms
5,792 KB
testcase_32 AC 12 ms
7,752 KB
testcase_33 AC 51 ms
8,488 KB
testcase_34 AC 2 ms
5,700 KB
testcase_35 AC 2 ms
7,524 KB
testcase_36 AC 2 ms
7,416 KB
testcase_37 AC 3 ms
7,468 KB
testcase_38 AC 3 ms
7,408 KB
testcase_39 AC 2 ms
5,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll MAX=500000;
const ll INFTY=1000000010;

ll L[MAX/2+2],R[MAX/2+2];

ll merge(int A[], int left, int mid ,int right){
  int n1=mid-left;
  int n2=right-mid;
  ll cnt=0;
  rep(i,n1) L[i]=A[left+i];
  rep(i,n2) R[i]=A[mid+i];
  L[n1]=INFTY;
  R[n2]=INFTY;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j]) A[k]=L[i++];
    else{
      A[k]=R[j++];
      cnt+=n1-i;
    }
  }
  return cnt;
}

ll mergeSort(int A[],int left,int right){
  int mid;
  ll v1,v2,v3;
  if(left+1<right){
    mid=(left + right)/2;
    v1=mergeSort(A,left,mid);
    v2=mergeSort(A,mid,right);
    v3=merge(A,left,mid,right);
    return v1+v2+v3;
  }else return 0;
}

int main() {
  int n;
  cin>>n;
  
  int A[MAX],B[MAX],C[MAX];
  rep(i,n) cin>>A[i];
  rep(i,n) cin>>B[i];
  rep(i,n) C[B[i]]=i;
  rep(i,n){
    int tmp=C[A[i]];
    A[i]=tmp+1;
  }
  
  ll ans=mergeSort(A,0,n);
  cout<<ans<<endl;
  
  return 0;
}
0