結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-08-02 13:10:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,424 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 106,940 KB
実行使用メモリ 9,484 KB
最終ジャッジ日時 2023-09-25 15:07:10
合計ジャッジ時間 7,981 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 112 ms
8,356 KB
testcase_04 AC 146 ms
9,032 KB
testcase_05 AC 111 ms
8,240 KB
testcase_06 AC 100 ms
7,724 KB
testcase_07 AC 127 ms
9,100 KB
testcase_08 AC 5 ms
4,384 KB
testcase_09 AC 50 ms
6,840 KB
testcase_10 AC 90 ms
9,300 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 134 ms
9,296 KB
testcase_13 AC 132 ms
9,356 KB
testcase_14 AC 135 ms
9,484 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 39 ms
5,084 KB
testcase_25 AC 90 ms
7,456 KB
testcase_26 AC 19 ms
4,384 KB
testcase_27 AC 49 ms
5,808 KB
testcase_28 AC 70 ms
7,020 KB
testcase_29 AC 95 ms
7,992 KB
testcase_30 AC 118 ms
8,924 KB
testcase_31 AC 26 ms
4,768 KB
testcase_32 AC 17 ms
4,452 KB
testcase_33 AC 104 ms
8,248 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

template<typename T>
struct BIT{
    private:
    vector<T> array;
    const int length;
    
    public:

    BIT(int _n) : array(_n+1),length(_n){}

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

    T sum(int i,int j){
        T ret1 = sum(i-1);
        T ret2 = sum(j);
        return ret2-ret1;
    }

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


int main(void){
	int n;
	cin>>n;
	vector<int>a(n),b(n);
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		int c;
		cin>>c;
		mp[c]=i+1;
	}
	for(int i=0;i<n;i++){
		b[i]=mp[a[i]];
	}
	BIT<ll>bit = BIT<ll>(n);
	ll ans = 0;
	for(int i=0;i<n;i++){
		ans+=i-bit.sum(b[i]);
		bit.add(b[i],1);
	}
	cout<<ans<<endl;
	return 0;
}
0