結果

問題 No.318 学学学学学
ユーザー seoul_ajaeseoul_ajae
提出日時 2020-07-26 18:27:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,036 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 177,532 KB
実行使用メモリ 7,892 KB
最終ジャッジ日時 2023-09-11 04:50:44
合計ジャッジ時間 5,759 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 16 ms
4,388 KB
testcase_02 AC 18 ms
4,380 KB
testcase_03 AC 13 ms
4,376 KB
testcase_04 AC 17 ms
4,384 KB
testcase_05 AC 88 ms
7,820 KB
testcase_06 AC 104 ms
7,756 KB
testcase_07 AC 109 ms
7,692 KB
testcase_08 AC 110 ms
7,700 KB
testcase_09 AC 110 ms
7,756 KB
testcase_10 AC 107 ms
7,700 KB
testcase_11 AC 88 ms
7,760 KB
testcase_12 AC 90 ms
7,752 KB
testcase_13 AC 89 ms
7,688 KB
testcase_14 AC 88 ms
7,880 KB
testcase_15 AC 86 ms
7,748 KB
testcase_16 AC 80 ms
7,884 KB
testcase_17 AC 79 ms
7,892 KB
testcase_18 AC 68 ms
7,744 KB
testcase_19 AC 80 ms
7,876 KB
testcase_20 AC 67 ms
7,756 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;

struct lst
{
    int n;
    vector<int> node;
    vector<int> lazy;
    vector<int> lflg;
    lst(int sz) 
    {
        n=1; while(n<sz) n*=2;
        node.resize(2*n, 0);
        lazy.resize(2*n, 0);
        lflg.resize(2*n, false);
    }

    void lazy2node(int k, int l, int r)
    {
        if(lflg[k])
        {
            node[k]=lazy[k];
            prop(lazy[k], k, l, r);
            lazy[k]=0;
            lflg[k]=false;
        }
    }

    void prop(int v, int k, int l, int r)
    {
        if(r-l>0)
        {
            lazy[2*k]=v;
            lazy[2*k+1]=v;
            lflg[2*k]=lflg[2*k+1]=true;
        }
    }

    void update(int qa, int qb, int v, int k=1, int l=1, int r=-1)
    {
        if(r<0) r=n;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return;
        if(qa<=l && r<=qb)
        {
            node[k]=v;
            prop(v, k, l, r);
        }
        else
        {
            int m=(l+r)/2;
            update(qa, qb, v, 2*k, l, m);
            update(qa, qb, v, 2*k+1, m+1, r);
        }
    }
        
    int get(int p, int k=1, int l=1, int r=-1)
    {
        if(r<0) r=n;
        lazy2node(k, l, r);
        if(r==l) return node[k];
        else
        {
            int m=(l+r)/2;
            if (p<=m) return get(p, 2*k, l, m);
            else return get(p, 2*k+1, m+1, r);
        }
    }
};

int main()
{
    int n;
    cin >> n;

    vector<pll> qr;
    for(int i=1; i<=n; i++)
    {
        ll s;
        cin >> s;
        qr.push_back(make_pair(s, i));
    }
    sort(qr.begin(), qr.end());
    lst tree=lst(n);
    for(int i=0; i<qr.size();i++)
    {
        if(i+1<qr.size() && qr[i].first == qr[i+1].first)
        {
            tree.update(qr[i].second, qr[i+1].second, qr[i].first);

        }
        else
            tree.update(qr[i].second, qr[i].second, qr[i].first);
    }

    for(int i=1; i<=n; i++) printf("%d ", tree.get(i));
    printf("\n");
    return 0;
}
0