結果

問題 No.610 区間賞(Section Award)
ユーザー PachicobuePachicobue
提出日時 2017-12-10 00:29:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 3,595 bytes
コンパイル時間 3,010 ms
コンパイル使用メモリ 211,964 KB
実行使用メモリ 11,656 KB
最終ジャッジ日時 2023-08-20 05:41:40
合計ジャッジ時間 7,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 15 ms
4,588 KB
testcase_20 AC 93 ms
11,004 KB
testcase_21 AC 10 ms
4,448 KB
testcase_22 AC 55 ms
8,084 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 18 ms
4,880 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 36 ms
6,672 KB
testcase_27 AC 91 ms
10,884 KB
testcase_28 AC 79 ms
10,100 KB
testcase_29 AC 50 ms
7,888 KB
testcase_30 AC 70 ms
9,536 KB
testcase_31 AC 32 ms
6,408 KB
testcase_32 AC 84 ms
10,476 KB
testcase_33 AC 10 ms
4,384 KB
testcase_34 AC 94 ms
10,956 KB
testcase_35 AC 37 ms
6,636 KB
testcase_36 AC 86 ms
10,592 KB
testcase_37 AC 70 ms
9,612 KB
testcase_38 AC 16 ms
4,960 KB
testcase_39 AC 93 ms
11,128 KB
testcase_40 AC 96 ms
11,188 KB
testcase_41 AC 91 ms
11,196 KB
testcase_42 AC 93 ms
11,224 KB
testcase_43 AC 97 ms
11,264 KB
testcase_44 AC 176 ms
10,328 KB
testcase_45 AC 217 ms
11,540 KB
testcase_46 AC 217 ms
11,656 KB
testcase_47 AC 75 ms
9,888 KB
testcase_48 AC 68 ms
9,276 KB
testcase_49 AC 75 ms
9,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;


template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= size; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] += value[x];
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    void set(const int a, const T& val)
    {
        const int v = get(a);
        add(a, op(val, op.inv(v)));
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        if (a == 0) {
            return accumulate(a);
        } else {
            return op(op.inv(accumulate(a - 1)), accumulate(a));
        }
    }

    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};
struct Sum {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return a + b;
    }
    T inv(const T& a) const
    {
        return -a;
    }
    static constexpr T identity()
    {
        return 0;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    vector<ll> B(N);
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        B[i]--;
        mp[B[i]] = i;
    }
    vector<ll> v(N);
    for (int i = 0; i < N; i++) {
        v[i] = mp[A[i]];
    }
    vector<int> cand;
    BinaryIndexedTree<Sum> bit(N);
    for (int i = N - 1; i >= 0; i--) {
        if (bit.accumulate(v[i]) == 0) {
            cand.push_back(A[i]);
        }
        bit.add(v[i], 1);
    }
    sort(cand.begin(), cand.end());
    for (const int c : cand) {
        cout << c + 1 << endl;
    }

    return 0;
}
0