結果

問題 No.1282 Display Elements
ユーザー rogi52rogi52
提出日時 2020-11-07 00:03:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,177 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 178,844 KB
実行使用メモリ 14,932 KB
最終ジャッジ日時 2023-09-29 19:47:26
合計ジャッジ時間 3,833 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 152 ms
13,912 KB
testcase_16 AC 51 ms
7,416 KB
testcase_17 AC 122 ms
12,336 KB
testcase_18 AC 68 ms
8,572 KB
testcase_19 AC 32 ms
4,836 KB
testcase_20 AC 31 ms
4,872 KB
testcase_21 AC 166 ms
14,932 KB
testcase_22 AC 44 ms
4,828 KB
testcase_23 AC 168 ms
14,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    sort(a.begin(), a.end());

    vector<int> b(N);
    rep(i,N) cin >> b[i];

    vector<int> v;
    rep(i,N){
        v.emplace_back(a[i]);
        v.emplace_back(b[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int Vsize = v.size();
    map<int,int> mp;
    rep(i,Vsize) mp[v[i]] = i;
    rep(i,N){
        a[i] = mp[a[i]];
        b[i] = mp[b[i]];
    }

    ll ans = 0;
    binary_indexed_tree<int> BIT(Vsize);
    rep(i,N){
        BIT.add(b[i], 1);
        ans += BIT.sum(a[i]);
    }

    cout << ans << '\n';
}
0