結果
| 問題 | No.318 学学学学学 |
| コンテスト | |
| ユーザー |
nikutto_
|
| 提出日時 | 2019-05-02 18:21:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 4,644 bytes |
| コンパイル時間 | 1,627 ms |
| コンパイル使用メモリ | 178,356 KB |
| 実行使用メモリ | 18,176 KB |
| 最終ジャッジ日時 | 2024-06-22 18:52:47 |
| 合計ジャッジ時間 | 5,117 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
namespace ProconLib{
// struct MUStructExample{
// struct Monoid{
// using value_t=int;
// static const value_t E = 0;
// static value_t op(value_t lhs,value_t rhs){ return lhs+rhs;}
// };
// struct Update{
// using update_t = int;
// static update_t op(update_t lhs,update_t rhs){ return lhs+rhs;}
// };
// static Monoid::value_t evaluate(Monoid::value_t v,Update::update_t u,int l,int r){ return v+u*(r-l);}
// };
template<class MUStruct>
class LazySegmentTree{
public:
using Monoid=typename MUStruct::Monoid;
using Update=typename MUStruct::Update;
using value_t=typename Monoid::value_t;
using update_t=typename Update::update_t;
private:
int N;
std::vector<value_t> dat;
std::vector<update_t> lazy;
std::vector<int> flag;
int calcN(int n){int res=1; while(res<n) res*=2; return res;};
void propagate(int node,int l,int r);
void applyLazy(int node,update_t x);
void updateImpl(int l,int r,int k,int lb,int ub,update_t f);
value_t queryImpl(int l,int r,int k,int lb,int ub);
value_t getValue(int node,int l,int r){return flag[node] ? MUStruct::evaluate(dat[node],lazy[node],l,r) : dat[node];}
public:
LazySegmentTree(int N);
void update(int l,int r,update_t f);
value_t query(int a,int b);
};
template<class MUStruct>
LazySegmentTree<MUStruct>::LazySegmentTree(int n):N(calcN(n)),dat(N*2-1,Monoid::E()),lazy(N*2-1),flag(N*2-1,false){}
template<class MUStruct>
void LazySegmentTree<MUStruct>::propagate(int node,int l,int r){
if(flag[node]){
flag[node]=false;
applyLazy(node*2+1,lazy[node]);
applyLazy(node*2+2,lazy[node]);
int mid=(l+r)/2;
dat[node]=Monoid::op(getValue(node*2+1,l,mid),getValue(node*2+2,mid,r));
}
}
template<class MUStruct>
void LazySegmentTree<MUStruct>::applyLazy(int node,update_t x){
if(flag[node]){
lazy[node]=Update::op(lazy[node],x);
}
else{
flag[node]=true;
lazy[node]=x;
}
}
template<class MUStruct>
void LazySegmentTree<MUStruct>::updateImpl(int l,int r,int k,int lb,int ub,update_t x){
if(r<=lb || ub<=l) return;
if(l<=lb && ub<=r){
applyLazy(k,x);
return;
}
propagate(k,lb,ub);
int mid=(lb+ub)/2;
updateImpl(l,r,k*2+1,lb,mid,x);
updateImpl(l,r,k*2+2,mid,ub,x);
dat[k]=Monoid::op(getValue(k*2+1,lb,ub),getValue(k*2+2,lb,ub));
}
template<class MUStruct>
typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::queryImpl(int l,int r,int k,int lb,int ub){
if(r<=lb || ub<=l) return Monoid::E();
if(l<=lb && ub<=r){
return getValue(k,lb,ub);
}
propagate(k,lb,ub);
int mid=(lb+ub)/2;
value_t lhs=queryImpl(l,r,k*2+1,lb,mid);
value_t rhs=queryImpl(l,r,k*2+2,mid,ub);
return Monoid::op(lhs,rhs);
}
template<class MUStruct>
void LazySegmentTree<MUStruct>::update(int l,int r,update_t x){
updateImpl(l,r,0,0,N,x);
}
template<class MUStruct>
typename LazySegmentTree<MUStruct>::value_t LazySegmentTree<MUStruct>::query(int l,int r){
return queryImpl(l,r,0,0,N);
}
};
//verify(yukicoder No,318)?
using namespace std;
using namespace ProconLib;
struct MyMUStruct{
struct Monoid{
using value_t = int;
static constexpr value_t E(){return 0;}
static value_t op(value_t x,value_t y){
return max(x,y);
}
};
struct Update{
using update_t = int;
static update_t op(update_t x,update_t y){
return y;
}
};
static typename Monoid::value_t evaluate(Monoid::value_t x,Update::update_t y,int l,int r){
return y;
}
};
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
map<int,vector<int>> mp;
for(int i=0;i<n;i++) mp[a[i]].push_back(i);
LazySegmentTree<MyMUStruct> seg(n);
for(auto &e:mp){
int tar=e.first;
vector<int>& vec=e.second;
if(vec.empty()) continue;
seg.update(vec[0],vec.back()+1,tar);
}
vector<int> b(n);
for(int i=0;i<n;i++) b[i]=seg.query(i,i+1);
for(int i=0;i<n;i++){
cout<<b[i]<<(i+1==n ? "\n" : " ");
}
return 0;
}
nikutto_