結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー okok
提出日時 2020-07-17 21:49:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 83,184 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-07 08:03:04
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 21 ms
6,944 KB
testcase_04 AC 23 ms
6,940 KB
testcase_05 AC 20 ms
6,944 KB
testcase_06 AC 19 ms
6,940 KB
testcase_07 AC 23 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 13 ms
6,944 KB
testcase_10 AC 21 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 22 ms
6,940 KB
testcase_13 AC 23 ms
6,944 KB
testcase_14 AC 22 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 10 ms
6,940 KB
testcase_25 AC 17 ms
6,944 KB
testcase_26 AC 6 ms
6,944 KB
testcase_27 AC 11 ms
6,944 KB
testcase_28 AC 14 ms
6,940 KB
testcase_29 AC 19 ms
6,944 KB
testcase_30 AC 21 ms
6,944 KB
testcase_31 AC 7 ms
6,940 KB
testcase_32 AC 5 ms
6,940 KB
testcase_33 AC 19 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


class BIT{
	vector<int> bit;
	
public:
	
	BIT(){
	}
	
	BIT(int size){
		init(size);
	}
	
	void init(int size){
		bit.clear();
		bit.resize(size+1);
	}
	
	int sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i , int x){
		while(i < bit.size()){
			bit[i] += x;
			i += i & -i;
		}
	}

	int lower_bound(int w){
		if(w <= 0) return 0;
		int x = 0, t = 1;
		while(t*2 < bit.size()) t *= 2;
		
		for(int k = t; k > 0; k /= 2){
			if(x + k < bit.size() && bit[x + k] < w){
				w -= bit[x + k];
				x += k;
			}
		}
		return x + 1;
	}
};


signed main(){
	cout<<fixed<<setprecision(10);
	
	int n;
	int ans = 0;
	vector<int> a, b, c;
	BIT bit;
	
	cin>>n;
	
	a.resize(n);
	b.resize(n);
	c.resize(n);
	bit.init(n+3);
	
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	
	for(int i = 0; i < n; i++){
		int x;
		
		cin>>x;
		
		b[x-1] = n - (i);
	}
	
	for(int i = 0; i < n; i++){ 
		c[i] = b[a[i]-1];
		// cout<<c[i]<<endl;
	}
	
	
	
	for(int i = 0; i < n; i++){
		ans += bit.sum(c[i]);
		// cout<<"i = "<<c[i]<<" "<<bit.sum(i+1)<<endl;
		bit.add(c[i], 1);
		
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0