結果

問題 No.318 学学学学学
ユーザー どららどらら
提出日時 2017-06-27 19:59:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,878 bytes
コンパイル時間 3,652 ms
コンパイル使用メモリ 178,792 KB
実行使用メモリ 16,612 KB
最終ジャッジ日時 2023-09-04 20:45:58
合計ジャッジ時間 5,719 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,436 KB
testcase_01 AC 23 ms
5,668 KB
testcase_02 AC 27 ms
6,044 KB
testcase_03 AC 18 ms
4,952 KB
testcase_04 AC 23 ms
5,804 KB
testcase_05 AC 169 ms
16,612 KB
testcase_06 AC 133 ms
11,060 KB
testcase_07 AC 112 ms
9,168 KB
testcase_08 AC 103 ms
8,308 KB
testcase_09 AC 88 ms
7,504 KB
testcase_10 AC 72 ms
6,440 KB
testcase_11 AC 163 ms
16,480 KB
testcase_12 AC 116 ms
10,996 KB
testcase_13 AC 97 ms
9,340 KB
testcase_14 AC 87 ms
8,132 KB
testcase_15 AC 78 ms
7,024 KB
testcase_16 AC 65 ms
6,132 KB
testcase_17 AC 84 ms
11,004 KB
testcase_18 AC 79 ms
11,024 KB
testcase_19 AC 83 ms
10,880 KB
testcase_20 AC 48 ms
6,192 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 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;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class LazySegmentTree {
  const int NONE = INT_MAX;
  int N;
  vector<int> lazy, dat;

  void setLazy(int k, int v){
    lazy[k] = v;
    dat[k] = v;
  }
  
  void push(int k){
    if(lazy[k] == NONE) return;
    setLazy(2*k+1, lazy[k]);
    setLazy(2*k+2, lazy[k]);
    lazy[k] = NONE;
  }
public:
  LazySegmentTree(int n){
    N = 1;
    while(N<n) N *= 2;
    dat.resize(2*N);
    lazy.resize(2*N);
    for(int i=0; i<2*N; i++){
      dat[i] = INT_MIN;
      lazy[i] = NONE;
    }
  }

  void update(int s, int t, int val){ update(s, t, val, 0, 0, N); }
  void update(int s, int t, int val, int k, int l, int r){
    if(r<=s || t<=l) return;
    if(s<=l && r<=t){
      setLazy(k, val);
      return;
    }
    push(k);
    update(s, t, val, 2*k+1, l, (l+r)/2);
    update(s, t, val, 2*k+2, (l+r)/2, r);
  }

  int query(int s, int t){ return query(s, t, 0, 0, N); }
  int query(int s, int t, int k, int l, int r){
    if(r<=s || t<=l) return INT_MIN;
    if(s<=l && r<=t) return dat[k];
    push(k);
    int vl = query(s, t, 2*k+1, l, (l+r)/2);
    int vr = query(s, t, 2*k+2, (l+r)/2, r);
    return max(vl, vr);
  }
};

int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  map<int,vector<int>> memo;
  rep(i,N){
    memo[v[i]].push_back(i);
  }


  LazySegmentTree lst(N);
  FOR(it,memo){
    int l = (it->second)[0];
    int r = (it->second)[(it->second).size()-1];

    lst.update(l,r+1,it->first);
  }

  rep(i,N){
    if(i>0) cout << " ";
    cout << lst.query(i,i+1);
  }
  cout << endl;
  
  return 0;
}
0