結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー t98slidert98slider
提出日時 2024-03-04 23:45:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,500 ms
コード長 2,581 bytes
コンパイル時間 3,187 ms
コンパイル使用メモリ 211,848 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-04 23:45:22
合計ジャッジ時間 10,419 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 27 ms
6,676 KB
testcase_03 AC 17 ms
6,676 KB
testcase_04 AC 82 ms
6,676 KB
testcase_05 AC 61 ms
6,676 KB
testcase_06 AC 30 ms
6,676 KB
testcase_07 AC 68 ms
6,676 KB
testcase_08 AC 23 ms
6,676 KB
testcase_09 AC 120 ms
6,676 KB
testcase_10 AC 118 ms
6,676 KB
testcase_11 AC 119 ms
6,676 KB
testcase_12 AC 116 ms
6,676 KB
testcase_13 AC 120 ms
6,676 KB
testcase_14 AC 118 ms
6,676 KB
testcase_15 AC 121 ms
6,676 KB
testcase_16 AC 94 ms
6,676 KB
testcase_17 AC 99 ms
6,676 KB
testcase_18 AC 96 ms
6,676 KB
testcase_19 AC 95 ms
6,676 KB
testcase_20 AC 96 ms
6,676 KB
testcase_21 AC 94 ms
6,676 KB
testcase_22 AC 94 ms
6,676 KB
testcase_23 AC 73 ms
6,676 KB
testcase_24 AC 74 ms
6,676 KB
testcase_25 AC 73 ms
6,676 KB
testcase_26 AC 73 ms
6,676 KB
testcase_27 AC 74 ms
6,676 KB
testcase_28 AC 74 ms
6,676 KB
testcase_29 AC 73 ms
6,676 KB
testcase_30 AC 98 ms
6,676 KB
testcase_31 AC 82 ms
6,676 KB
testcase_32 AC 47 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class S, S (*mapping)(S, S), S (*id)()> struct dual_segtree {
    public:
    dual_segtree() : dual_segtree(0) {}
    dual_segtree(int n) : dual_segtree(std::vector<S>(n, id())) {}
    dual_segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
    }
    const S& operator[](int p) const {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }
    S& operator[](int p) { 
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }
    void apply(int p, S f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
    }
    void apply(int l, int r, S f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;
        l += size;
        r += size;
        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }
        while (l < r) {
            if (l & 1) all_apply(l++, f);
            if (r & 1) all_apply(--r, f);
            l >>= 1;
            r >>= 1;
        }
    }
    private:
    int _n, size, log;
    std::vector<S> d;
    void all_apply(int k, S f) {
        d[k] = mapping(f, d[k]);
    }
    void push(int k) {
        all_apply(2 * k, d[k]);
        all_apply(2 * k + 1, d[k]);
        d[k] = id();
    }
    int ceil_pow2(int n) {
        int x = 0;
        while ((1U << x) < (unsigned int)(n)) x++;
        return x;
    }
};
int op(int lhs, int rhs){return max(lhs, rhs);}
int e(){return -1;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, A, T, l, r;
    cin >> N >> A;
    vector<pair<int,int>> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    cin >> T;
    dual_segtree<int, op, e> seg(N);
    for(int i = 1; i <= T; i++){
        cin >> l >> r;
        l = lower_bound(a.begin(), a.end(), make_pair(l, -1)) - a.begin();
        r = lower_bound(a.begin(), a.end(), make_pair(r + 1, -1)) - a.begin();
        seg.apply(l, r, i);
    }
    vector<int> ans(N);
    for(int i = 0; i < N; i++) ans[a[i].second] = seg[i];
    for(auto v : ans) cout << v << '\n';
}
0