結果

問題 No.1282 Display Elements
ユーザー MisterMister
提出日時 2020-11-19 18:40:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 97,664 KB
実行使用メモリ 15,512 KB
最終ジャッジ日時 2023-09-30 16:24:28
合計ジャッジ時間 3,358 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 200 ms
14,464 KB
testcase_16 AC 60 ms
7,600 KB
testcase_17 AC 160 ms
12,440 KB
testcase_18 AC 86 ms
9,092 KB
testcase_19 AC 32 ms
4,548 KB
testcase_20 AC 31 ms
4,548 KB
testcase_21 AC 225 ms
15,512 KB
testcase_22 AC 49 ms
4,600 KB
testcase_23 AC 223 ms
15,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/compress.hpp"

#include <algorithm>
#include <vector>
#include <map>

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < (int)v.size(); ++i) rev[v[i]] = i;
    return rev;
}
#line 2 "main.cpp"
#include <atcoder/fenwicktree>

#include <iostream>
#line 7 "main.cpp"

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n), ys(n);
    for (auto& x : xs) std::cin >> x;
    for (auto& y : ys) std::cin >> y;

    auto zs = xs;
    std::copy(ys.begin(), ys.end(), std::back_inserter(zs));

    auto zrev = compress(zs);
    for (auto& x : xs) x = zrev[x];
    for (auto& y : ys) y = zrev[y];
    int m = zs.size();

    std::sort(xs.begin(), xs.end());

    lint ans = 0;
    atcoder::fenwick_tree<lint> bit(m);
    for (int i = 0; i < n; ++i) {
        bit.add(ys[i], 1);
        ans += bit.sum(0, xs[i]);
    }

    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0