結果
問題 |
No.1282 Display Elements
|
ユーザー |
![]() |
提出日時 | 2020-11-21 17:35:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 968 bytes |
コンパイル時間 | 1,945 ms |
コンパイル使用メモリ | 202,484 KB |
最終ジャッジ日時 | 2025-01-16 04:03:53 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), c; for (int i = 0; i < n; i++) { cin >> a.at(i); c.push_back(a.at(i)); } for (int i = 0; i < n; i++) { cin >> b.at(i); c.push_back(b.at(i)); } 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.at(i) = lower_bound(c.begin(), c.end(), a.at(i)) - c.begin() + 1; b.at(i) = lower_bound(c.begin(), c.end(), b.at(i)) - c.begin() + 1; } vector<int> t(2 * n + 1); int64_t ans = 0; for (int i = 0; i < n; i++) { int idx = b.at(i); while (idx <= 2 * n) { t.at(idx)++; idx += idx & -idx; } idx = a.at(i) - 1; while (idx) { ans += t.at(idx); idx -= idx & -idx; } } cout << ans << endl; }