結果

問題 No.318 学学学学学
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-05-24 12:24:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,040 bytes
コンパイル時間 1,965 ms
コンパイル使用メモリ 183,484 KB
実行使用メモリ 22,732 KB
最終ジャッジ日時 2023-10-19 19:56:07
合計ジャッジ時間 6,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
template<class V, int NV> struct LazySegTree { // [L,R)
    #define def 0
    #define ldef -1
    V comp(V l, V r) { return l + r; }
    void setLazy(int i, V v) { lazy[i] = v; }
    void push(int k, int l, int r) {
        if (lazy[k] != ldef) {
            // modify------------------------------
            V sm = lazy[k];
            int kk = k;
            while (kk < NV) {
                kk *= 2;
                sm *= 2;
            }
            dat[k] = sm;
            // ------------------------------------
            if (r - l > 1) { setLazy(k * 2 + 1, lazy[k]); setLazy(k * 2 + 2, lazy[k]); }
            setLazy(k, ldef);
        }
    }


    vector<V> dat, lazy;
    LazySegTree() { dat.resize(NV * 2, def); lazy.resize(NV * 2, ldef); }
    void update(int a, int b, V v, int k, int l, int r) {
        push(k, l, r); if (r <= a || b <= l) return;
        if (a <= l && r <= b) { setLazy(k, v); push(k, l, r); }
        else { update(a, b, v, k * 2 + 1, l, (l + r) / 2);
            update(a, b, v, k * 2 + 2, (l + r) / 2, r); dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]); } }
    V get(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return dat[k]; auto x = get(a, b, k * 2 + 1, l, (l + r) / 2);
        auto y = get(a, b, k * 2 + 2, (l + r) / 2, r); return comp(x, y); }
    void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); }
    V get(int a, int b) { return get(a, b, 0, 0, NV); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N;
int A[101010];
//---------------------------------------------------------------------------------------------------
LazySegTree<ll, 1 << 18> st;
void _main() {
    cin >> N;
    rep(i, 0, N) scanf("%d", &A[i]);

    rep(i, 0, N) st.update(i, i + 1, A[i]);

    map<int, vector<int>> m;
    rep(i, 0, N) m[A[i]].push_back(i);
    for (auto p : m) {
        int i = p.first;
        auto v = p.second;

        int mi, ma;
        mi = ma = v[0];
        for (int j : v) mi = min(mi, j), ma = max(ma, j);

        //printf("[%d %d]\n", mi, ma);
        st.update(mi, ma + 1, i);
    }
    printf("%lld ", st.get(0, 0 + 1) / 2);
    rep(i, 1, N) printf("%lld ", st.get(i, i + 1));
    printf("\n");
}
0