結果

問題 No.318 学学学学学
ユーザー monnumonnu
提出日時 2020-04-06 11:27:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 173,300 KB
実行使用メモリ 4,956 KB
最終ジャッジ日時 2023-09-20 02:53:56
合計ジャッジ時間 6,454 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 17 ms
4,380 KB
testcase_03 AC 12 ms
4,380 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 79 ms
4,832 KB
testcase_06 AC 80 ms
4,828 KB
testcase_07 AC 73 ms
4,880 KB
testcase_08 AC 68 ms
4,952 KB
testcase_09 AC 64 ms
4,884 KB
testcase_10 AC 61 ms
4,956 KB
testcase_11 AC 79 ms
4,948 KB
testcase_12 AC 71 ms
4,896 KB
testcase_13 AC 67 ms
4,952 KB
testcase_14 AC 63 ms
4,896 KB
testcase_15 AC 61 ms
4,888 KB
testcase_16 AC 55 ms
4,832 KB
testcase_17 AC 62 ms
4,952 KB
testcase_18 AC 51 ms
4,880 KB
testcase_19 AC 62 ms
4,840 KB
testcase_20 AC 41 ms
4,832 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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