結果

問題 No.318 学学学学学
ユーザー ateate
提出日時 2019-12-20 13:20:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,042 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 184,352 KB
実行使用メモリ 12,144 KB
最終ジャッジ日時 2023-09-22 15:57:19
合計ジャッジ時間 10,418 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In instantiation of ‘T lazy_segment_tree<T>::h(T&, T) [with T = int]’:
main.cpp:61:7:   required from ‘void lazy_segment_tree<T>::update(int, int, T, int, int, int) [with T = int]’
main.cpp:109:15:   required from here
main.cpp:18:3: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   18 |   }
      |   ^
main.cpp: In instantiation of ‘T lazy_segment_tree<T>::g(T&, T) [with T = int]’:
main.cpp:47:7:   required from ‘void lazy_segment_tree<T>::eval(int, int, int) [with T = int]’
main.cpp:58:5:   required from ‘void lazy_segment_tree<T>::update(int, int, T, int, int, int) [with T = int]’
main.cpp:109:15:   required from here
main.cpp:15:3: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   15 |   }
      |   ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

template<class T>
struct lazy_segment_tree{
  int n;
  vector<T> dat,lazy;
  T de,le;

  T f(T a,T b){
    return a+b;
  }
  T g(T& a,T b){
    a = b;
  }
  T h(T& a,T b){
    a = b;
  }

  lazy_segment_tree(){}
  lazy_segment_tree(int sz){
    n = 1;
    while(n<=sz)n<<=1;
    de = 0;
    le = 0;
    dat.resize(2*n-1,de);
    lazy.resize(2*n-1,le);
  }
  lazy_segment_tree(vector<T> const& v){
    int sz = v.size();
    n = 1;
    while(n<=sz)n<<=1;
    de = 0;
    le = 0;
    dat.resize(2*n-1,de);
    lazy.resize(2*n-1,le);
    for(int i=0;i<sz;++i){
      dat[i+n-1] = v[i];
    }
    for(int i=n-2;i>=0;--i){
      dat[i] = f(dat[i*2+1],dat[i*2+2]);
    }
  }

  void eval(int k,int l,int r){
    if(lazy[k]!=le){
      g(dat[k],lazy[k]);
      if(r-l>1){
        h(lazy[2*k+1],lazy[k]);
        h(lazy[2*k+2],lazy[k]);
      }
      lazy[k] = le;
    }
  }

  void update(int a,int b,T x,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k,l,r);
    if(b<=l||r<=a)return;
    if(a<=l&&r<=b){
      h(lazy[k],x);
      eval(k,l,r);
    }else{
      update(a,b,x,2*k+1,l,(r+l)/2);
      update(a,b,x,2*k+2,(r+l)/2,r);
      dat[k] = f(dat[2*k+1],dat[2*k+2]);
    }
  }

  T query(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    if(b<=l||r<=a)return de;
    eval(k,l,r);
    if(a<=l&&r<=b)return dat[k];
    T vl = query(a,b,2*k+1,l,(r+l)/2);
    T vr = query(a,b,2*k+2,(r+l)/2,r);
    return f(vl,vr);
  }

  T operator[](int k){
    return query(k,k+1);
  }

};

void yukico318(){

  int n;cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  struct section{
    int l,r;
    section():r(-1),l((1LL<<28)){}
    void operator()(int k){
      if(l>k)l=k;
      if(r<k)r=k;
    }
  };

  map<int,section> mp;
  for(int i=0;i<n;++i){
    mp[a[i]](i);
  }

  lazy_segment_tree<int> seg(n);

  for(auto const& sec:mp){
    seg.update(sec.second.l,sec.second.r+1,sec.first);
  }

  for(int i=0;i<n;++i){
    cout<<seg[i]<<" ";
  }
  cout<<endl;

}

int main(){
  yukico318();
}
0