結果

問題 No.318 学学学学学
ユーザー kuc_jacksonkuc_jackson
提出日時 2021-09-04 18:30:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,724 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 217,864 KB
実行使用メモリ 13,156 KB
最終ジャッジ日時 2023-08-23 07:52:50
合計ジャッジ時間 7,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,380 KB
testcase_01 AC 27 ms
4,632 KB
testcase_02 AC 34 ms
4,892 KB
testcase_03 AC 22 ms
4,504 KB
testcase_04 AC 29 ms
5,012 KB
testcase_05 AC 200 ms
11,808 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct lazysegtree{
    int size = 1;
    vector<int> dat, lazy;
    lazysegtree(int sz){
        int x = 1;
        while(x < sz)x *= 2;
        size = x;
        dat.resize(2 * x - 1);
        lazy.resize(2 * x - 1, -1);
    }
    void eval(int k){
        if(lazy[k] == -1)return;
        dat[k] = lazy[k];
        if(k < size - 1){
            eval(2 * k + 1); eval(2 * k + 2);
            lazy[2 * k + 1] = lazy[k];
            lazy[2 * k + 2] = lazy[k];
        }
        lazy[k] = -1;
    }
    void build(){
        for(int k = 0; k < size - 1; k++)eval(k);
    }
    void update_(int l, int r, int a, int b, int k, int x){
        eval(k);
        if(b <= l || r <= a)return;
        if(l <= a && b <= r){
            lazy[k] = x;
            return;
        }
        update_(l, r, a, (a + b) / 2, 2 * k + 1, x);
        update_(l, r, (a + b) / 2, b, 2 * k + 2, x);
    }
    void update(int l, int r, int x){
        update_(l, r, 0, size, 0, x);
    }
    int get(int k){
        k += size - 1;
        eval(k);
        return dat[k];
    }
};

int main(){
    const int INF = 1e9;
    int N; cin >> N;
    vector<int> a(N);
    map<int, pii> cnt;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        cnt[a[i]] = {INF, -INF};
    }
    for(int i = 0; i < N; i++){
        cnt[a[i]].first = min(cnt[a[i]].first, i);
        cnt[a[i]].second = max(cnt[a[i]].second, i + 1);
    }
    lazysegtree lt(N);
    for(auto mp: cnt){
        int x, l, r; pii p; tie(x, p) = mp; tie(l, r) = p;
        lt.update(l, r, x);
    }
    lt.build();
    for(int i = 0; i < N; i++)cout << lt.get(i) << " ";
    cout << endl;
}
0