結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー noritakenoritake
提出日時 2020-08-05 22:39:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,235 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 170,640 KB
実行使用メモリ 4,924 KB
最終ジャッジ日時 2023-10-17 18:50:31
合計ジャッジ時間 6,369 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 53 ms
4,632 KB
testcase_04 WA -
testcase_05 AC 53 ms
4,632 KB
testcase_06 AC 49 ms
4,632 KB
testcase_07 WA -
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 34 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 22 ms
4,348 KB
testcase_25 AC 46 ms
4,368 KB
testcase_26 AC 12 ms
4,348 KB
testcase_27 AC 28 ms
4,348 KB
testcase_28 AC 38 ms
4,368 KB
testcase_29 AC 49 ms
4,632 KB
testcase_30 WA -
testcase_31 AC 16 ms
4,348 KB
testcase_32 AC 11 ms
4,348 KB
testcase_33 AC 53 ms
4,632 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

class BIT
{
    private:
        vi node;
        int n;
    public:
        BIT(int n_) {
            n = n_;
            node.resize(n + 1);
        }

        void add(int i, int x) {
            while (i <= n) {
                node[i] += x;
                i += (i & (-i));
            }
        }

        int sum(int i) {
            int sum = 0;
            while (i > 0) {
                sum += node[i];
                i -= (i & (-i));
            }
            return sum;
        }

        int sum(int a, int b) {
            return sum(b) - sum(a - 1);
        }
};

int main() {
    int N;
    cin >> N;
    vi A(N + 1), B(N + 1);
    rep(i, N) {
        cin >> A[i];
    }
    rep(i, N) {
        cin >> B[i];
    }

    vi conv(N + 1);
    rep(i, N) {
        conv[B[i]] = i + 1;
    }
    rep(i, N) {
        A[i] = conv[A[i]];
    }

    int cnt = 0;
    BIT bit(N);
    rep(i, N) {
        bit.add(A[i], 1);
        cnt += (i + 1) - bit.sum(A[i]);
    }

    cout << cnt << endl;
}
0