結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー nawawannawawan
提出日時 2020-11-13 15:24:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 81,236 KB
実行使用メモリ 4,884 KB
最終ジャッジ日時 2023-09-30 02:06:42
合計ジャッジ時間 5,988 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 51 ms
4,600 KB
testcase_04 AC 58 ms
4,772 KB
testcase_05 AC 50 ms
4,532 KB
testcase_06 AC 46 ms
4,688 KB
testcase_07 AC 58 ms
4,796 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 55 ms
4,828 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 58 ms
4,824 KB
testcase_13 AC 59 ms
4,884 KB
testcase_14 AC 59 ms
4,820 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 22 ms
4,376 KB
testcase_25 AC 44 ms
4,380 KB
testcase_26 AC 11 ms
4,380 KB
testcase_27 AC 26 ms
4,380 KB
testcase_28 AC 36 ms
4,376 KB
testcase_29 AC 47 ms
4,572 KB
testcase_30 AC 56 ms
4,844 KB
testcase_31 AC 15 ms
4,380 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 49 ms
4,628 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
using namespace std;
struct BIT{
    vector<long long> num;
    int N;
    BIT(int n){
        N = n;
        num.resize(N + 1, 0);
    }
    long long sum(int t){
        long long res = 0;
        while(t > 0){
            res += num[t];
            t -= t & -t;
        }
        return res;
    }
    void add(int ind, long long t){
        ind++;
        while(ind <= N){
            num[ind] += t;
            ind += ind & -ind;
        }
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    vector<int> ind(n);
    for(int i = 0; i < n; i++) ind[a[i] - 1] = i;
    BIT bit(n);
    long long cnt = 0;
    for(int i = 0; i < n; i++){
        bit.add(ind[b[i] - 1], 1);
        cnt += bit.sum(n) - bit.sum(ind[b[i] - 1] + 1);
    }
    cout << cnt << endl;
}
0