結果

問題 No.1282 Display Elements
ユーザー HaaHaa
提出日時 2020-11-06 22:14:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 183,652 KB
実行使用メモリ 24,916 KB
最終ジャッジ日時 2023-09-29 18:56:52
合計ジャッジ時間 4,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 276 ms
23,224 KB
testcase_16 AC 89 ms
11,236 KB
testcase_17 AC 214 ms
19,776 KB
testcase_18 AC 119 ms
13,412 KB
testcase_19 AC 89 ms
6,168 KB
testcase_20 AC 84 ms
6,132 KB
testcase_21 AC 297 ms
24,916 KB
testcase_22 AC 95 ms
6,260 KB
testcase_23 AC 295 ms
24,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()
const ll MOD=1000000007;
const ll INF=1e18;

struct BIT {
	int N;
	VI dat;
	BIT(int N):N(N){
		dat.resize(N+1,0);
	}
	ll sum(int k) {
		ll res=0;
		for(;k>0;k-=k&-k){
			res+=dat[k];
		}
		return res;
	}
	void add(int k, ll x) {
		for(;k<=N;k+=k&-k){
			dat[k]+=x;
		}
	}
	int lowerBound(int w) {
		if (w<=0) return 0;
		int x=0;
		int k=1;
		while(k*2<=N) k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&dat[x+k]<w){
				w-=dat[x+k];
				x+=k;
			}
		}
		return x+1;
	}
};

int main(){
	ll n; cin >> n;
	VI a(n), b(n);
	REP(i,n) cin >> a[i];
	REP(i,n) cin >> b[i];
	sort(ALL(a));
	set<int> st; map<int,int> mp;
	REP(i,n) st.insert(a[i]),st.insert(b[i]);
	int c=2;
	for(auto x:st){
		mp[x]=c;
		c++;
	}
	BIT bt(2*n);
	ll ans=0;
	REP(i,n){
		bt.add(mp[b[i]],1);
		ans+=bt.sum(mp[a[i]]-1);
	}
	cout << ans << endl;
	return 0;
}
0