結果
| 問題 | No.1282 Display Elements | 
| コンテスト | |
| ユーザー |  Haa | 
| 提出日時 | 2020-11-06 22:14:47 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 290 ms / 2,000 ms | 
| コード長 | 1,028 bytes | 
| コンパイル時間 | 1,960 ms | 
| コンパイル使用メモリ | 188,188 KB | 
| 実行使用メモリ | 25,088 KB | 
| 最終ジャッジ日時 | 2024-07-22 13:00:46 | 
| 合計ジャッジ時間 | 4,442 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
ソースコード
#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;
}
            
            
            
        