結果
問題 |
No.1282 Display Elements
|
ユーザー |
![]() |
提出日時 | 2020-11-06 21:43:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 241 ms / 2,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 1,129 ms |
コンパイル使用メモリ | 98,304 KB |
実行使用メモリ | 26,880 KB |
最終ジャッジ日時 | 2024-07-22 12:33:00 |
合計ジャッジ時間 | 2,942 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; template <typename T> struct bit{ int n; vector<T> data; bit(int n_){ n = 1; while(n < n_) n *= 2; data = vector<T>(n+1); for(int i = 0; i <= n; i++) data[i] = 0; } T sum(int i){ T ret = 0; while(i > 0){ ret += data[i]; i -= i&-i; } return ret; } void add(int i, T x){ while(i <= n){ data[i] += x; i += i&-i; } } }; ll n; ll a[100000], b[100000]; map<ll, int> compress; void make_compress(){ set<ll> st; for(int i = 0; i < n; i++){ st.insert(a[i]); st.insert(b[i]); } int cur = 1; for(ll x : st){ compress[x] = cur; cur++; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; make_compress(); sort(a, a+n); int m = compress.size(); bit<ll> bt(m); ll ans = 0; for(int i = 0; i < n; i++){ bt.add(compress[b[i]], 1); ans += bt.sum(compress[a[i]]-1); } cout << ans << endl; }