結果

問題 No.1282 Display Elements
ユーザー chocoruskchocorusk
提出日時 2020-11-10 23:16:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 135,488 KB
実行使用メモリ 7,132 KB
最終ジャッジ日時 2023-09-30 00:14:54
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 103 ms
6,872 KB
testcase_16 AC 39 ms
4,752 KB
testcase_17 AC 83 ms
5,924 KB
testcase_18 AC 56 ms
4,872 KB
testcase_19 AC 77 ms
6,336 KB
testcase_20 AC 74 ms
6,336 KB
testcase_21 AC 111 ms
7,132 KB
testcase_22 AC 86 ms
6,232 KB
testcase_23 AC 112 ms
6,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)-sum(l);
    }
    void add(int i, T x){
        i++;
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
    int n; cin>>n;
    ll a[100010];
    ll b[100010];
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<n; i++) cin>>b[i];
    sort(a, a+n);
    vector<ll> v(2*n);
    for(int i=0; i<n; i++){
        v[i]=b[i];
        v[i+n]=a[i];
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for(int i=0; i<n; i++){
        a[i]=lower_bound(v.begin(), v.end(), a[i])-v.begin();
        b[i]=lower_bound(v.begin(), v.end(), b[i])-v.begin();
    }
    int m=v.size();
    BIT<int> bit(m);
    ll ans=0;
    for(int i=0; i<n; i++){
        bit.add(b[i], 1);
        ans+=bit.sum(a[i]);
    }
    cout<<ans<<endl;
    return 0;
}
0