結果

問題 No.1282 Display Elements
ユーザー ぷらぷら
提出日時 2021-03-13 01:30:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 172,244 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 15:58:56
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 120 ms
6,940 KB
testcase_16 AC 49 ms
6,940 KB
testcase_17 AC 100 ms
6,940 KB
testcase_18 AC 61 ms
6,940 KB
testcase_19 AC 97 ms
6,944 KB
testcase_20 AC 89 ms
6,944 KB
testcase_21 AC 131 ms
6,940 KB
testcase_22 AC 106 ms
6,940 KB
testcase_23 AC 131 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T>
struct BinaryIndexedTree {
    int N;
    vector<T>bit;
    
    BinaryIndexedTree() {};
    
    BinaryIndexedTree(int x) {
        N = x;
        bit.resize(x+1);
    }
    
    void add(int x,T y) {
        while(x <= N) {
            bit[x] += y;
            x += x&-x;
        }
    }
    
    T sum(int x) {
        T res = 0;
        while(x) {
            res += bit[x];
            x -= x&-x;
        }
        return res;
    }
    
    T sum(int l, int r) {//[l,r]
        return sum(r)-sum(l-1);
    }
};

int main() {
    int N;
    cin >> N;
    vector<int>a(N),b(N),c;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        c.push_back(a[i]);
    }
    for(int i = 0; i < N; i++) {
        cin >> b[i];
        c.push_back(b[i]);
    }
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    c.erase(unique(c.begin(),c.end()),c.end());
    BinaryIndexedTree<int>bit(c.size());
    long long ans = 0;
    for(int i = 0; i < N; i++) {
        int it1 = lower_bound(c.begin(),c.end(),a[i])-c.begin();
        int it2 = lower_bound(c.begin(),c.end(),b[i])-c.begin();
        it1++;
        it2++;
        bit.add(it2,1);
        ans += bit.sum(1,it1-1);
    }
    cout << ans << endl;
}
0