結果
問題 |
No.1282 Display Elements
|
ユーザー |
|
提出日時 | 2020-11-07 00:03:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 183 ms / 2,000 ms |
コード長 | 1,177 bytes |
コンパイル時間 | 1,911 ms |
コンパイル使用メモリ | 180,180 KB |
実行使用メモリ | 15,224 KB |
最終ジャッジ日時 | 2024-07-22 13:52:41 |
合計ジャッジ時間 | 3,805 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; template <typename T> struct binary_indexed_tree{ int N; vector<T> BIT; binary_indexed_tree(int n){ N = 1; while (N < n){ N *= 2; } BIT = vector<T>(N + 1, 0); } void add(int i, T x){ i++; while (i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i){ T ans = 0; while (i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } }; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector<int> a(N); rep(i,N) cin >> a[i]; sort(a.begin(), a.end()); vector<int> b(N); rep(i,N) cin >> b[i]; vector<int> v; rep(i,N){ v.emplace_back(a[i]); v.emplace_back(b[i]); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); int Vsize = v.size(); map<int,int> mp; rep(i,Vsize) mp[v[i]] = i; rep(i,N){ a[i] = mp[a[i]]; b[i] = mp[b[i]]; } ll ans = 0; binary_indexed_tree<int> BIT(Vsize); rep(i,N){ BIT.add(b[i], 1); ans += BIT.sum(a[i]); } cout << ans << '\n'; }