結果

問題 No.2092 Conjugation
ユーザー t98slidert98slider
提出日時 2022-10-07 22:33:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,582 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 168,580 KB
実行使用メモリ 4,592 KB
最終ジャッジ日時 2023-09-03 13:50:51
合計ジャッジ時間 3,527 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 11 ms
4,432 KB
testcase_08 AC 25 ms
4,380 KB
testcase_09 AC 17 ms
4,384 KB
testcase_10 AC 19 ms
4,460 KB
testcase_11 AC 19 ms
4,516 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 13 ms
4,404 KB
testcase_14 AC 13 ms
4,388 KB
testcase_15 AC 17 ms
4,540 KB
testcase_16 AC 31 ms
4,388 KB
testcase_17 AC 29 ms
4,592 KB
testcase_18 AC 34 ms
4,388 KB
testcase_19 AC 6 ms
4,380 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;
            }
        }
        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;
        }
};
using S = int;
//xにfを作用させた時の値の変化
S op(S f, S x){return x + f;}
//作用させても変化させないもの
S id(){return 0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, v, sz;
    cin >> n;
    cin >> v;
    sz = v;
    dual_segtree<int, op, id> seg(vector<int>(v, 1));
    for(int i = 1; i < n; i++){
        cin >> v;
        seg.apply(0, v, 1);
    }
    for(int i = 0; i < sz; i++){
        cout << seg[i] << (i + 1 == sz ? '\n' : ' ');
    }
}
0