結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー Y17Y17
提出日時 2020-07-17 21:50:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 3,853 ms
コンパイル使用メモリ 165,716 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2023-08-20 00:37:39
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 51 ms
6,540 KB
testcase_04 AC 57 ms
6,952 KB
testcase_05 AC 50 ms
6,508 KB
testcase_06 AC 46 ms
6,124 KB
testcase_07 AC 57 ms
6,968 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 33 ms
5,068 KB
testcase_10 AC 57 ms
6,956 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 58 ms
6,940 KB
testcase_13 AC 58 ms
7,040 KB
testcase_14 AC 59 ms
6,964 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 21 ms
4,408 KB
testcase_25 AC 44 ms
6,024 KB
testcase_26 AC 11 ms
4,380 KB
testcase_27 AC 26 ms
5,144 KB
testcase_28 AC 35 ms
5,364 KB
testcase_29 AC 47 ms
6,148 KB
testcase_30 AC 56 ms
6,656 KB
testcase_31 AC 15 ms
4,380 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 50 ms
6,456 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
5,272 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<class T> struct BinaryIndexTree{
    int n;
    vector<T> bit; 
    vector<T> org;

    BinaryIndexTree(int si): bit(si+1), org(si+1) { n = si; }; 

    void add(int idx, T v){
        org[++idx] += v;
        for(int i = idx;i <= n;i+=i&-i) bit[i] += v;
    }

    void update(int idx, T v){
        T vv = v - org[++idx];
        org[idx] = v;
        for(int i = idx;i <= n;i+=i&-i) bit[i] += vv;
    }

    T sum(int a){
        T ret = 0;
        for(int i = a;i > 0;i-=i&-i) ret += bit[i];
        return ret;
    }

    T sum(int l, int r) { return sum(r)-sum(l); }; 
};


signed main(){
	int n;
	cin >> n;

	int a[100010];
	int b[100010];
	for(int i = 0;i < n;i++) cin >> a[i];

	int tmp[100010];
	for(int i = 0;i < n;i++){
		cin >> b[i];
		tmp[b[i]] = i;
	}
	for(int i = 0;i < n;i++) a[i] = tmp[a[i]];

	BinaryIndexTree<int> bit(n);

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