結果

問題 No.1282 Display Elements
ユーザー SSRSSSRS
提出日時 2020-11-06 21:34:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 1,853 ms
コンパイル使用メモリ 178,612 KB
実行使用メモリ 14,880 KB
最終ジャッジ日時 2023-09-29 18:19:29
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 181 ms
14,028 KB
testcase_16 AC 64 ms
7,448 KB
testcase_17 AC 145 ms
12,232 KB
testcase_18 AC 84 ms
8,664 KB
testcase_19 AC 81 ms
4,896 KB
testcase_20 AC 80 ms
4,820 KB
testcase_21 AC 206 ms
14,864 KB
testcase_22 AC 91 ms
4,832 KB
testcase_23 AC 206 ms
14,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct binary_indexed_tree{
	int N;
	vector<T> BIT;
	binary_indexed_tree(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		BIT = vector<T>(N + 1, 0);
	}
	void add(int i, T x){
		i++;
		while (i <= N){
			BIT[i] += x;
			i += i & -i;
		}
	}
	T sum(int i){
		T ans = 0;
		while (i > 0){
			ans += BIT[i];
			i -= i & -i;
		}
		return ans;
	}
};
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b[i];
  }
  vector<int> x;
  for (int i = 0; i < N; i++){
    x.push_back(a[i]);
    x.push_back(b[i]);
  }
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  int cnt = x.size();
  map<int, int> mp;
  for (int i = 0; i < cnt; i++){
    mp[x[i]] = i;
  }
  for (int i = 0; i < N; i++){
    a[i] = mp[a[i]];
    b[i] = mp[b[i]];
  }
  long long ans = 0;
  binary_indexed_tree<int> BIT(cnt);
  for (int i = 0; i < N; i++){
    BIT.add(b[i], 1);
    ans += BIT.sum(a[i]);
  }
  cout << ans << endl;
}
0