結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー 夜
提出日時 2020-07-24 21:43:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 92,312 KB
実行使用メモリ 6,256 KB
最終ジャッジ日時 2023-09-08 03:45:39
合計ジャッジ時間 5,004 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 53 ms
5,984 KB
testcase_04 AC 59 ms
6,192 KB
testcase_05 AC 51 ms
5,616 KB
testcase_06 AC 47 ms
5,708 KB
testcase_07 AC 59 ms
6,212 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 34 ms
5,144 KB
testcase_10 AC 57 ms
6,244 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 60 ms
6,168 KB
testcase_13 AC 62 ms
6,256 KB
testcase_14 AC 60 ms
6,196 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 21 ms
4,572 KB
testcase_25 AC 44 ms
5,716 KB
testcase_26 AC 12 ms
4,392 KB
testcase_27 AC 27 ms
4,828 KB
testcase_28 AC 36 ms
5,196 KB
testcase_29 AC 47 ms
5,708 KB
testcase_30 AC 57 ms
6,012 KB
testcase_31 AC 16 ms
4,388 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 50 ms
5,868 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n;
vector<long long> BIT(100010);
void add(long long i, long long x) {
	while (i <= n) {
		BIT[i] += x;
		i += i & -i;
	}
}
long long csum(long long i) {
	long long count = 0;
	while (i > 0) {
		count += BIT[i];
		i -= i & -i;
	}
	return count;
}
long long sum(long long l, long long r) {
	return csum(r) - csum(l - 1);
}
long long a[100010];
long long b[100010];
long long co[100010];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		co[b[i]] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		b[i + 1] = co[a[i]];
	}
	for (int i = 1; i <= n; i++) {
		add(i, 0);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (i - 1) - sum(0, b[i]);
		add(b[i], 1);
	}
	cout << ans << endl;
	return 0;
}
0