結果

問題 No.1282 Display Elements
ユーザー srjywrdnprkt
提出日時 2024-04-04 12:24:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 1,618 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 208,152 KB
最終ジャッジ日時 2025-02-20 20:03:04
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
map<T, T> compress(vector<T> &A){
map<T, T> comp;
int N = A.size(), i=0;
for (int i=0; i<N; i++) comp[A[i]];
for (auto &e : comp){
e.second = i;
i++;
}
return comp;
}
template<class T> struct BIT {
private:
vector<T> bit; int N;
T _sum(int r){
r++; T res = 0;
while(r > 0) res += bit[r-1], r -= r & -r;
return res;
}
public:
BIT (int n){ N = n; bit.resize(N);}
BIT (vector<T> &a) : BIT(a.size()) { for (int i=0; i<N; i++) add(i, a[i]);}
void add(int loc, T val){
loc++;
while(loc <= N) bit[loc-1] += val, loc += loc & -loc;
}
void change(int loc, T val){add(loc, -get(loc)+val);}
T sum(int l, int r) {return _sum(r) - _sum(l-1);}
T get(int l) {return sum(l, l);}
void clear() {for (int i=0; i<N; i++) bit[i] = 0;}
};
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
//
ll N, ans=0;
cin >> N;
vector<ll> a(N), b(N), c;
for (int i=0; i<N; i++) cin >> a[i], c.push_back(a[i]);
for (int i=0; i<N; i++) cin >> b[i], c.push_back(b[i]);
sort(a.begin(), a.end());
map<ll, ll> mp = compress(c);
for (int i=0; i<N; i++){
a[i] = mp[a[i]];
b[i] = mp[b[i]];
}
BIT<ll> bit(N*2);
for (int i=0; i<N; i++){
bit.add(b[i], 1);
ans += bit.sum(0, a[i]-1);
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0