結果

問題 No.1282 Display Elements
ユーザー zuminzumin
提出日時 2021-03-24 00:40:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 82,820 KB
実行使用メモリ 8,468 KB
最終ジャッジ日時 2023-08-17 11:56:38
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 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,380 KB
testcase_15 AC 117 ms
7,980 KB
testcase_16 AC 46 ms
5,112 KB
testcase_17 AC 96 ms
7,448 KB
testcase_18 AC 60 ms
5,440 KB
testcase_19 AC 93 ms
8,468 KB
testcase_20 AC 91 ms
8,404 KB
testcase_21 AC 127 ms
8,340 KB
testcase_22 AC 106 ms
8,404 KB
testcase_23 AC 129 ms
8,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <atcoder/segtree>

using namespace std;
using namespace atcoder;
using ll=long long;

ll op(ll a,ll b) {return a+b;}
ll e() {return 0LL;}
int main(){
    ll n,ans=0;
    cin>>n;

    vector<ll> a(n),b(n),sortedb(n);
    segtree<ll,op,e> s(n);

    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    copy(b.begin(),b.end(),sortedb.begin());

    sort(a.begin(),a.end());
    sort(sortedb.begin(),sortedb.end());

    for(int i=0;i<n;i++){
        ll ai=a[i],bi=b[i];
        ll inda=lower_bound(sortedb.begin(),sortedb.end(),ai)-sortedb.begin();
        ll indb=lower_bound(sortedb.begin(),sortedb.end(),bi)-sortedb.begin();
        s.set(indb,s.get(indb)+1);
        ans+=s.prod(0,inda);
    }
    cout<<ans<<endl;

    return 0;
}
0