結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー motmot
提出日時 2020-08-03 14:16:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 90,260 KB
実行使用メモリ 9,772 KB
最終ジャッジ日時 2023-09-30 18:01:59
合計ジャッジ時間 6,107 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,500 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 102 ms
8,896 KB
testcase_04 AC 123 ms
9,560 KB
testcase_05 AC 103 ms
8,776 KB
testcase_06 AC 96 ms
8,412 KB
testcase_07 AC 120 ms
9,540 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 51 ms
6,980 KB
testcase_10 AC 91 ms
9,772 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 122 ms
9,636 KB
testcase_13 AC 125 ms
9,584 KB
testcase_14 AC 124 ms
9,572 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 38 ms
5,656 KB
testcase_25 AC 86 ms
8,048 KB
testcase_26 AC 18 ms
4,492 KB
testcase_27 AC 48 ms
6,056 KB
testcase_28 AC 68 ms
7,204 KB
testcase_29 AC 94 ms
8,548 KB
testcase_30 AC 119 ms
9,248 KB
testcase_31 AC 26 ms
4,840 KB
testcase_32 AC 16 ms
4,420 KB
testcase_33 AC 103 ms
8,884 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int N;
ll bit[100005];

void add(int x) {
  while(x<=N) {
    bit[x]++;
    x += x & -x;
  }
}

ll sum(int x) {
  ll ans = 0;
  while(x>0) {
    ans += bit[x];
    x -= x & -x;
  }
  return ans;
}

int main() {
  cin>>N;
  int a[N], b[N];
  for(int i=0;i<N;++i) cin>>a[i];
  for(int i=0;i<N;++i) cin>>b[i];
  map<int, int> amap;
  for(int i=0;i<N;++i) {
    amap[a[i]] = i+1;
  }
  for(int i=0;i<N;++i) {
    b[i] = amap[b[i]];
  }
  ll ans = 0;
  for(ll i=0;i<N;++i) {
    ans += i - sum(b[i]);
    add(b[i]);
  }
  cout<<ans<<endl;
}
0