結果

問題 No.610 区間賞(Section Award)
ユーザー finefine
提出日時 2017-12-10 18:35:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 178,324 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-05-07 16:58:24
合計ジャッジ時間 5,633 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 17 ms
5,376 KB
testcase_20 AC 124 ms
8,064 KB
testcase_21 AC 11 ms
5,376 KB
testcase_22 AC 57 ms
6,752 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 18 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 37 ms
5,632 KB
testcase_27 AC 86 ms
8,192 KB
testcase_28 AC 75 ms
7,552 KB
testcase_29 AC 54 ms
6,400 KB
testcase_30 AC 72 ms
7,296 KB
testcase_31 AC 33 ms
5,632 KB
testcase_32 AC 88 ms
7,680 KB
testcase_33 AC 11 ms
5,376 KB
testcase_34 AC 89 ms
8,192 KB
testcase_35 AC 38 ms
5,716 KB
testcase_36 AC 86 ms
7,936 KB
testcase_37 AC 74 ms
7,192 KB
testcase_38 AC 18 ms
5,376 KB
testcase_39 AC 99 ms
8,320 KB
testcase_40 AC 92 ms
8,320 KB
testcase_41 AC 98 ms
8,320 KB
testcase_42 AC 97 ms
8,320 KB
testcase_43 AC 91 ms
8,320 KB
testcase_44 AC 171 ms
7,936 KB
testcase_45 AC 219 ms
8,832 KB
testcase_46 AC 221 ms
8,832 KB
testcase_47 AC 74 ms
7,424 KB
testcase_48 AC 67 ms
7,168 KB
testcase_49 AC 78 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

//1-indexであることに注意
struct BIT {
    int n;
    vector<int> data;

    BIT(int n) : n(n), data(n + 1, 0) {}

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> memo;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        memo[x] = i;
    }
    BIT b(n);
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i == b.sum(memo[x])) ans.push_back(x);
        b.add(memo[x], 1);
    }
    sort(ans.begin(), ans.end());
    for (int x : ans) {
        cout << x << endl;
    }
    return 0;
}
0