結果

問題 No.318 学学学学学
ユーザー monnu
提出日時 2020-04-06 11:27:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 175,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 23:14:21
合計ジャッジ時間 5,570 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 998244353
#define MAX 2100000
#define INF 1001000000
using Graph=vector<vector<int>>;

void update(vector<int> &tree,int x,int a,int b,int i,int left,int right){
  if(b<=left||right<=a){
    return;
  }
  if(a<=left&&right<=b){
    tree.at(i)=x;
    return;
  }
  if(tree.at(i)!=-1){
    tree.at(2*i+1)=tree.at(i);
    tree.at(2*i+2)=tree.at(i);
    tree.at(i)=-1;
  }
  update(tree,x,a,b,2*i+1,left,(left+right)/2);
  update(tree,x,a,b,2*i+2,(left+right)/2,right);
}


int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i).first;
    a.at(i).second=i;
  }
  int n=1;
  while(n<N){
    n<<=1;
  }
  vector<int> tree(2*n-1,-1);
  for(int i=0;i<N;i++){
    tree.at(n-1+i)=a.at(i).first;
  }

  sort(a.begin(),a.end());
  int left=0,right=0;
  while(left<N){
    while(a.at(left).first==a.at(right).first){
      right++;
      if(right==N){
        break;
      }
    }
    int l=a.at(left).second;
    int r=a.at(right-1).second+1;
    int x=a.at(left).first;
    update(tree,x,l,r,0,0,n);
    left=right;
  }

  for(int i=0;i<n-1;i++){
    if(tree.at(i)!=-1){
      tree.at(2*i+1)=tree.at(i);
      tree.at(2*i+2)=tree.at(i);
    }
  }
  for(int i=0;i<N;i++){
    cout<<tree.at(n-1+i)<<" ";
  }
  cout<<endl;
}
0