結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー hamrayhamray
提出日時 2020-07-17 21:55:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 2,153 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 155,336 KB
実行使用メモリ 10,148 KB
最終ジャッジ日時 2023-08-20 00:54:05
合計ジャッジ時間 4,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 77 ms
9,116 KB
testcase_04 AC 91 ms
9,880 KB
testcase_05 AC 76 ms
9,012 KB
testcase_06 AC 72 ms
8,484 KB
testcase_07 AC 95 ms
9,908 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 32 ms
6,896 KB
testcase_10 AC 59 ms
10,132 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 99 ms
10,056 KB
testcase_13 AC 94 ms
10,148 KB
testcase_14 AC 94 ms
10,144 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 28 ms
5,352 KB
testcase_25 AC 66 ms
8,324 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 35 ms
6,100 KB
testcase_28 AC 51 ms
7,188 KB
testcase_29 AC 69 ms
8,528 KB
testcase_30 AC 89 ms
9,540 KB
testcase_31 AC 18 ms
4,652 KB
testcase_32 AC 12 ms
4,444 KB
testcase_33 AC 75 ms
9,128 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集
template<typename T = int> struct BIT{
  vector<T> node;

  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }

  void add(int i, T x){
    i++;
    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }

  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }

  

};
ll GCD(ll a, ll b){
    
    if(b == 0) return a;
    return GCD(b, a%b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n; cin >> n;
  vector<ll> a(n), b(n);

  BIT<ll> bit(n);
  map<int, int> mp;
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i], mp[b[i]] = i;

  ll ans = 0;
  for(int i=0; i<n; i++){
    int t = mp[a[i]];
    ans += i - bit.sum(t);
    bit.add(t, 1);
  }
  cout << ans << endl;
  return 0;
}
0