結果

問題 No.318 学学学学学
ユーザー kuc_jacksonkuc_jackson
提出日時 2021-09-04 18:39:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,678 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 215,856 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2023-08-23 08:05:45
合計ジャッジ時間 6,431 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,376 KB
testcase_01 AC 27 ms
4,720 KB
testcase_02 AC 33 ms
4,992 KB
testcase_03 AC 21 ms
4,376 KB
testcase_04 AC 28 ms
4,556 KB
testcase_05 AC 196 ms
11,736 KB
testcase_06 AC 160 ms
8,860 KB
testcase_07 AC 142 ms
7,508 KB
testcase_08 AC 124 ms
6,720 KB
testcase_09 AC 107 ms
6,136 KB
testcase_10 AC 84 ms
5,716 KB
testcase_11 AC 181 ms
12,032 KB
testcase_12 AC 129 ms
8,504 KB
testcase_13 AC 110 ms
7,756 KB
testcase_14 AC 93 ms
6,724 KB
testcase_15 AC 76 ms
6,256 KB
testcase_16 AC 57 ms
5,348 KB
testcase_17 AC 123 ms
8,508 KB
testcase_18 AC 100 ms
8,616 KB
testcase_19 AC 121 ms
8,684 KB
testcase_20 AC 41 ms
5,604 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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){
            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