結果

問題 No.1282 Display Elements
ユーザー 夜
提出日時 2020-11-06 22:39:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 106,024 KB
実行使用メモリ 11,184 KB
最終ジャッジ日時 2023-09-29 19:16:59
合計ジャッジ時間 2,947 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 3 ms
4,436 KB
testcase_02 AC 3 ms
4,496 KB
testcase_03 AC 3 ms
4,564 KB
testcase_04 AC 3 ms
4,524 KB
testcase_05 AC 3 ms
4,444 KB
testcase_06 AC 3 ms
4,396 KB
testcase_07 AC 3 ms
4,492 KB
testcase_08 AC 3 ms
4,436 KB
testcase_09 AC 3 ms
4,520 KB
testcase_10 AC 3 ms
4,716 KB
testcase_11 AC 3 ms
4,440 KB
testcase_12 AC 3 ms
4,644 KB
testcase_13 AC 3 ms
4,616 KB
testcase_14 AC 3 ms
4,388 KB
testcase_15 AC 59 ms
10,392 KB
testcase_16 AC 25 ms
7,280 KB
testcase_17 AC 50 ms
10,492 KB
testcase_18 AC 32 ms
7,316 KB
testcase_19 AC 71 ms
10,244 KB
testcase_20 AC 43 ms
11,072 KB
testcase_21 AC 64 ms
11,184 KB
testcase_22 AC 64 ms
10,420 KB
testcase_23 AC 64 ms
9,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 a[100010], b[100010];
long long n;
vector<long long> BIT(200020);
void add(long long i, long long x) {
	while (i <= 200020) {
		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);
}
vector<tuple<long long, int, bool>> vec;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		vec.emplace_back(make_tuple(a[i], i, false));
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		vec.emplace_back(make_tuple(b[i], i, true));
	}
	sort(vec.begin(), vec.end());
	int now = 1;
	for (int i = 0; i < vec.size(); i++) {
		if (i != 0) {
			if (get<0>(vec[i]) != get<0>(vec[i - 1])) {
				now++;
			}
		}
		if (!get<2>(vec[i])) {
			a[get<1>(vec[i])] = now;
		}
		else {
			b[get<1>(vec[i])] = now;
		}
	}
	sort(a, a + n);
	long long ans = 0;
	for (int i = 1; i <= 200000; i++) {
		add(i, 0);
	}
	for (int i = 0; i < n; i++) {
		add(b[i], 1);
		long long co = sum(0, a[i] - 1);
		ans += co;
	}
	cout << ans << endl;
}
0