結果

問題 No.318 学学学学学
ユーザー Manuel1024Manuel1024
提出日時 2021-05-29 20:29:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,751 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 85,616 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-25 15:43:04
合計ジャッジ時間 5,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,812 KB
testcase_01 AC 24 ms
6,940 KB
testcase_02 AC 29 ms
6,940 KB
testcase_03 AC 20 ms
6,940 KB
testcase_04 AC 26 ms
6,940 KB
testcase_05 AC 154 ms
11,904 KB
testcase_06 AC 138 ms
8,832 KB
testcase_07 AC 123 ms
7,680 KB
testcase_08 AC 108 ms
7,040 KB
testcase_09 AC 99 ms
6,944 KB
testcase_10 AC 85 ms
6,944 KB
testcase_11 AC 152 ms
11,904 KB
testcase_12 AC 119 ms
8,832 KB
testcase_13 AC 105 ms
7,808 KB
testcase_14 AC 95 ms
7,168 KB
testcase_15 AC 84 ms
6,940 KB
testcase_16 AC 73 ms
6,944 KB
testcase_17 AC 105 ms
8,960 KB
testcase_18 AC 94 ms
8,960 KB
testcase_19 AC 105 ms
9,088 KB
testcase_20 AC 55 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
using namespace std;

template <typename T>
class LazySegTree{
private:
    int n;
    vector<T> arr, lazy;
    const T INF = 0;
public:
    LazySegTree(int _n){
        n = 1;
        while(n < _n) n <<= 1;
        arr = vector<T>(n*2, INF);
        lazy = vector<T>(n*2, INF);
    }

    void eval(int k){
        if(lazy[k] == INF) return;
        if(k < n-1){
            lazy[k*2+1] = lazy[k];
            lazy[k*2+2] = lazy[k];
        }

        arr[k] = lazy[k];
        lazy[k] = INF;
    }

    void update(int a, int b, T x, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = n;
        eval(k);
        if(a <= l && r <= b){
            lazy[k] = x;
            eval(k);
        }else if(a < r && l < b){
            update(a, b, x, k*2+1, l, (l+r)/2);
            update(a, b, x, k*2+2, (l+r)/2, r);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = n;
        eval(k);
        if(r <= a || b <= l) return INF;
        else if(a <= l && r <= b) return arr[k];
        else{
            return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
        }
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &p: a) cin >> p;

    map<int, pair<int, int>> a2;
    for(int i = 0; i < n; i++){
        if(a2.count(a[i]) == 0){
            a2[a[i]] = make_pair(i, i);
        }else{
            a2[a[i]].second = i;
        }
    }

    LazySegTree<int> d(n);
    for(auto &p: a2){
        d.update(p.second.first, p.second.second+1, p.first);
    }

    for(int i = 0; i < n; i++){
        if(i != 0) cout << " ";
        cout << d.query(i, i+1);
    }
    cout << endl;
    return 0;
}
0