#line 1 "a.cpp" #include #include using namespace std; #line 1 "/home/kotatsugame/library/datastructure/BIT.cpp" //1-indexed #include template struct BIT{ int n; vectorbit; 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]>N; for(int i=0;i>A[i]; C[i]=A[i]; } for(int i=0;i>B[i]; C[N+i]=B[i]; } sort(A,A+N); sort(C,C+2*N); BITP(2*N); long ans=0; for(int i=0;i