結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー sanada_atcodersanada_atcoder
提出日時 2020-07-17 21:38:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 3,752 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 100,752 KB
実行使用メモリ 7,432 KB
最終ジャッジ日時 2023-08-20 00:07:30
合計ジャッジ時間 3,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,784 KB
testcase_01 AC 2 ms
5,524 KB
testcase_02 AC 2 ms
5,424 KB
testcase_03 AC 50 ms
7,116 KB
testcase_04 AC 57 ms
7,180 KB
testcase_05 AC 50 ms
6,928 KB
testcase_06 AC 45 ms
6,816 KB
testcase_07 AC 56 ms
7,164 KB
testcase_08 AC 4 ms
5,580 KB
testcase_09 AC 33 ms
6,772 KB
testcase_10 AC 56 ms
7,240 KB
testcase_11 AC 2 ms
5,452 KB
testcase_12 AC 58 ms
7,196 KB
testcase_13 AC 58 ms
7,432 KB
testcase_14 AC 58 ms
7,296 KB
testcase_15 AC 2 ms
5,600 KB
testcase_16 AC 2 ms
5,472 KB
testcase_17 AC 2 ms
5,408 KB
testcase_18 AC 2 ms
5,428 KB
testcase_19 AC 2 ms
5,360 KB
testcase_20 AC 2 ms
5,348 KB
testcase_21 AC 2 ms
5,352 KB
testcase_22 AC 2 ms
5,388 KB
testcase_23 AC 6 ms
5,564 KB
testcase_24 AC 21 ms
6,208 KB
testcase_25 AC 44 ms
6,876 KB
testcase_26 AC 11 ms
5,912 KB
testcase_27 AC 26 ms
6,424 KB
testcase_28 AC 35 ms
6,616 KB
testcase_29 AC 46 ms
6,972 KB
testcase_30 AC 55 ms
7,076 KB
testcase_31 AC 15 ms
5,952 KB
testcase_32 AC 10 ms
5,804 KB
testcase_33 AC 49 ms
6,972 KB
testcase_34 AC 2 ms
5,412 KB
testcase_35 AC 2 ms
5,356 KB
testcase_36 AC 2 ms
5,352 KB
testcase_37 AC 2 ms
5,352 KB
testcase_38 AC 2 ms
5,468 KB
testcase_39 AC 2 ms
5,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<random>
#include<iomanip>
#include<queue>
#include<stack>
#include<assert.h>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 2330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法(Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int bit[114514];
int n;
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 <= n) {
		bit[i] += x;
		i += i & -i;
	}
}
int a[114514], b[114514];
int memo[114514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n)memo[a[i] - 1] = i + 1;
	rep(i, n)b[i] = memo[b[i] - 1];
	int ans = 0;
	rep(i, n) {
		ans += i - sum(b[i]);
		add(b[i], 1);
	}
	cout << ans << endl;
	ggr
}

0