結果
| 問題 |
No.1282 Display Elements
|
| コンテスト | |
| ユーザー |
oevl
|
| 提出日時 | 2020-11-06 23:09:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 165 ms / 2,000 ms |
| コード長 | 1,239 bytes |
| コンパイル時間 | 3,153 ms |
| コンパイル使用メモリ | 202,168 KB |
| 最終ジャッジ日時 | 2025-01-15 21:14:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<class T> class Fenwick {
private:
vector<T> dat;
int n;
public:
Fenwick(int _n) : dat(_n + 1), n(_n) {}
// sum of [1, i]
T sum(int i) {
T s = 0;
while(i > 0) s += dat[i], i -= i & -i;
return s;
}
// sum of [l, r]
T sum(int l, int r) {
return l > r ? 0 : sum(r) - sum(l - 1);
}
void add(int i, T x) {
while(i <= n) dat[i] += x, i += i & -i;
}
};
const int m = 5e5;
int main() {
int n; cin >> n;
vector<int> a(n), b(n);
vector<int> c;
for(auto &e : a) {
cin >> e;
c.push_back(e);
}
for(auto &e : b) {
cin >> e;
c.push_back(e);
}
sort(a.begin(), a.end());
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
for(int i = 0; i < n; ++i) {
a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin() + 2;
}
for(int i = 0; i < n; ++i) {
b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin() + 2;
}
long long ans = 0;
Fenwick<int> f(m);
for(int i = 0; i < n; ++i) {
f.add(b[i], 1);
ans += f.sum(a[i] - 1);
}
cout << ans << '\n';
return 0;
}
oevl