結果

問題 No.1282 Display Elements
ユーザー trineutrontrineutron
提出日時 2020-11-21 17:35:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 204,852 KB
実行使用メモリ 5,532 KB
最終ジャッジ日時 2023-09-30 22:08:07
合計ジャッジ時間 4,562 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 115 ms
5,264 KB
testcase_16 AC 46 ms
4,376 KB
testcase_17 AC 95 ms
4,888 KB
testcase_18 AC 59 ms
4,376 KB
testcase_19 AC 91 ms
5,456 KB
testcase_20 AC 85 ms
5,460 KB
testcase_21 AC 126 ms
5,532 KB
testcase_22 AC 100 ms
5,332 KB
testcase_23 AC 126 ms
5,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0