結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー FujiyanosukeFujiyanosuke
提出日時 2020-08-11 20:59:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,611 bytes
コンパイル時間 1,788 ms
コンパイル使用メモリ 167,832 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 17:36:27
合計ジャッジ時間 4,136 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 55 ms
6,940 KB
testcase_04 AC 62 ms
6,940 KB
testcase_05 AC 52 ms
6,940 KB
testcase_06 AC 50 ms
6,940 KB
testcase_07 AC 63 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 35 ms
6,944 KB
testcase_10 AC 61 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 63 ms
6,944 KB
testcase_13 AC 62 ms
6,940 KB
testcase_14 AC 61 ms
6,940 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 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 23 ms
6,944 KB
testcase_25 AC 47 ms
6,944 KB
testcase_26 AC 12 ms
6,940 KB
testcase_27 AC 28 ms
6,944 KB
testcase_28 AC 39 ms
6,948 KB
testcase_29 AC 48 ms
6,944 KB
testcase_30 AC 60 ms
6,944 KB
testcase_31 AC 15 ms
6,944 KB
testcase_32 AC 11 ms
6,944 KB
testcase_33 AC 52 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
template<class T>
struct BIT {
	VE<T> d;
	int n;
	BIT(int n = 0) : n(n), d(n + 1, 0) {}
	void add(int i, T x) {
		for (i++; i <= n; i += i & -i) d[i] += x;
	}
	T sum(int i) {
		int tmp = 0;
		for (i++; i; i -= i & -i) tmp += d[i];
		return tmp;
	}
};
int main() {
	int n;
	cin >> n;
	V a(n), b(n);
	V pos(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	rep(i, n) {
		cin >> b[i];
		b[i]--;
		pos[b[i]] = i;
	}
	V c(n);
	rep(i, n) {
		c[i] = pos[a[i]];
	}
	ll ans = 0;
	BIT<ll> BIT(n);
	rep(i, n) {
		ans += i - BIT.sum(c[i]);
		BIT.add(c[i], 1);
	}
	cout << ans << endl;
	return 0;
}
0