結果
| 問題 | No.1282 Display Elements | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-11-08 00:10:53 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 133 ms / 2,000 ms | 
| コード長 | 962 bytes | 
| コンパイル時間 | 946 ms | 
| コンパイル使用メモリ | 75,716 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-22 14:56:57 | 
| 合計ジャッジ時間 | 2,970 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
コンパイルメッセージ
a.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp"
#include<iostream>
#include<algorithm>
using namespace std;
#line 1 "/home/kotatsugame/library/datastructure/BIT.cpp"
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
#line 5 "a.cpp"
int N;
int A[1<<17],B[1<<17],C[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		C[i]=A[i];
	}
	for(int i=0;i<N;i++)
	{
		cin>>B[i];
		C[N+i]=B[i];
	}
	sort(A,A+N);
	sort(C,C+2*N);
	BIT<int>P(2*N);
	long ans=0;
	for(int i=0;i<N;i++)
	{
		P.add(upper_bound(C,C+2*N,B[i])-C,1);
		ans+=P.sum(lower_bound(C,C+2*N,A[i])-C);
	}
	cout<<ans<<endl;
}
            
            
            
        