結果

問題 No.610 区間賞(Section Award)
ユーザー finefine
提出日時 2017-12-10 18:35:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 179,640 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-11-30 11:20:46
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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