結果

問題 No.1282 Display Elements
ユーザー nawawannawawan
提出日時 2020-11-06 22:15:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,659 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 98,612 KB
実行使用メモリ 17,112 KB
最終ジャッジ日時 2023-09-29 18:57:02
合計ジャッジ時間 4,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,076 KB
testcase_01 AC 4 ms
5,224 KB
testcase_02 AC 3 ms
5,068 KB
testcase_03 AC 3 ms
5,164 KB
testcase_04 AC 3 ms
5,068 KB
testcase_05 AC 3 ms
5,136 KB
testcase_06 AC 3 ms
5,200 KB
testcase_07 AC 3 ms
5,208 KB
testcase_08 AC 4 ms
5,084 KB
testcase_09 AC 3 ms
5,068 KB
testcase_10 AC 3 ms
5,088 KB
testcase_11 AC 3 ms
5,204 KB
testcase_12 AC 3 ms
5,232 KB
testcase_13 AC 4 ms
5,080 KB
testcase_14 AC 4 ms
5,412 KB
testcase_15 RE -
testcase_16 AC 66 ms
9,456 KB
testcase_17 RE -
testcase_18 WA -
testcase_19 AC 40 ms
7,840 KB
testcase_20 WA -
testcase_21 RE -
testcase_22 WA -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
struct segK{//非再帰
    int n;
    long long MIN;
    int size;
    vector<long long> dat;
    segK(int n_){
        n = 1;
        MIN = 0;
        size = n_;
        while(n < n_) n *= 2;
        dat.resize(2 * n);
        for(int i = 1; i < 2 * n; i++) dat[i] = MIN;
    }
    void update(int k, long long a){
        k += n;
        dat[k] = a;
        while(k > 0){
            k >>= 1;
            dat[k] = dat[k << 1 | 0] + dat[k << 1 | 1];
        }
    }
    long long query(int l, int r){
        long long res = 0;
        l += n;
        r += n;
        while(r > l){
            if(l & 1) res += dat[l++];
            if(r & 1) res += dat[--r];
            l >>= 1;
            r >>= 1;
        }
        return res;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    segK seg(100010);
    vector<long long> a(N), b(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < N; i++) cin >> b[i];
    map<int, int> m;
    vector<int> vec;
    for(int i = 0; i < N; i++){
        vec.push_back(a[i]);
        vec.push_back(b[i]);
    }
    sort(vec.begin(), vec.end());
    int index = 0;
    for(int i = 0; i < 2 * N; i++){
        if(m.count(vec[i])) continue;
        m[vec[i]] = index;
        index++;
    }
    long long cnt = 0;
    sort(a.begin(), a.end());
    for(int i = 0; i < N; i++){
        int ind = m[b[i]];
        seg.update(ind, 1);
        int ind2 = m[a[i]];
        cnt += seg.query(0, ind2);
    }
    cout << cnt << endl;
}
0