結果

問題 No.1282 Display Elements
ユーザー platinum
提出日時 2020-08-22 18:37:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 81,972 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-29 06:11:36
合計ジャッジ時間 3,753 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cassert>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
using LL = long long;
const int Max_N = 1e5;
const int Max_Fac = 1e9;
class FenwickTree {
private:
int bit_size;
vector<LL> bit;
public:
FenwickTree(int siz): bit_size(siz), bit(siz + 1) {}
void add(int num, LL val) {
for(int i = num + 1; i <= bit_size; i += i & -i) {
bit[i] += val;
}
}
LL sum(int end) {
LL res = 0;
for(int i = end + 1; i > 0; i -= i & -i) {
res += bit[i];
}
return res;
}
LL sum(int begin, int end) {
return sum(end - 1) - sum(begin - 1);
}
void init(LL val) {
for(int i = 1; i <= bit_size; i++) {
add(i, val);
}
}
int lower_bound(LL val) {
if(val <= 0) return 0;
int i = 0, n = 1;
while(n * 2 <= bit_size) n *= 2;
for(int k = n; k > 0; k /= 2) {
if(i + k <= bit_size && bit[i + k] < val) {
val -= bit[i + k];
i += k;
}
}
return i + 1;
}
};
int main(){
int N;
cin >> N;
assert(1<=N and N<=Max_N);
vector<int> a(N), b(N);
rep(i,N){
int A;
cin >> A;
assert(1<=A and A<=Max_Fac);
a[i]=A;
}
rep(i,N){
int B;
cin >> B;
assert(1<=B and B<=Max_Fac);
b[i]=B;
}
vector<int> c;
rep(i,N) c.emplace_back(a[i]), c.emplace_back(b[i]);
sort(c.begin(),c.end());
c.erase(unique(c.begin(),c.end()),c.end());
rep(i,N){
a[i]=lower_bound(c.begin(),c.end(),a[i])-c.begin();
b[i]=lower_bound(c.begin(),c.end(),b[i])-c.begin();
}
sort(a.begin(),a.end());
LL ans=0;
FenwickTree ft(2*N);
rep(i,N){
ft.add(b[i],1);
LL res=ft.sum(a[i]-1);
ans+=res;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0