結果

問題 No.318 学学学学学
ユーザー IL_mstaIL_msta
提出日時 2017-02-02 22:15:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 3,479 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 136,256 KB
実行使用メモリ 22,212 KB
最終ジャッジ日時 2023-09-04 20:38:34
合計ジャッジ時間 5,856 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,880 KB
testcase_01 AC 28 ms
6,560 KB
testcase_02 AC 34 ms
7,232 KB
testcase_03 AC 23 ms
5,864 KB
testcase_04 AC 30 ms
6,756 KB
testcase_05 AC 229 ms
22,068 KB
testcase_06 AC 171 ms
14,560 KB
testcase_07 AC 143 ms
11,904 KB
testcase_08 AC 120 ms
10,604 KB
testcase_09 AC 99 ms
9,096 KB
testcase_10 AC 71 ms
7,500 KB
testcase_11 AC 227 ms
22,212 KB
testcase_12 AC 144 ms
14,604 KB
testcase_13 AC 117 ms
11,944 KB
testcase_14 AC 94 ms
10,264 KB
testcase_15 AC 74 ms
8,712 KB
testcase_16 AC 51 ms
7,384 KB
testcase_17 AC 113 ms
14,400 KB
testcase_18 AC 99 ms
14,572 KB
testcase_19 AC 110 ms
14,584 KB
testcase_20 AC 52 ms
7,444 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////

class sgement{//range query
	int n;//要素数
	int NUM_MAX;
	int NUM_NULL;
	vector<int> dat;//4*n用意する。
public:
	int getNull(){return NUM_NULL;}
	void init(int N,int val_0,int val_null ){
		NUM_MAX = val_0;
		NUM_NULL = val_null;
		dat = vector<int>((N<<2)+2,NUM_MAX);//開区間
	}
	/*
	flag:false L,true R
	*/
	int find(int t,int L,int R,int P,bool flag){
		if( dat[t] != NUM_NULL ){
			if( dat[t] == P ){
				return flag==false?L:R;
			}else{
				return NUM_NULL;
			}
		}
		int mid = (L+R)/2;
		int res;
		if( flag == false ){
			res = find(t*2+0,L,mid,P,flag);
			if( res != NUM_NULL ){return res;}
			res = find(t*2+1,mid+1,R,P,flag);
			return res;
		}else{
			res = find(t*2+1,mid+1,R,P,flag);
			if( res != NUM_NULL ){return res;}
			res = find(t*2+0,L,mid,P,flag);
			return res;
		}
	}
	void update(int t,int L,int R,int X,int Y,int VAL){
		//親から子へ進んでいく
		if( L == X && R == Y){
			dat[t] = VAL;
		}else{
			int mid = (L+R)/2;
			if( dat[t] != NUM_NULL ){//値の伝播
				dat[t*2+0] = dat[t];
				dat[t*2+1] = dat[t];
				dat[t] = NUM_NULL;
			}
			if( Y <= mid ){
				update(t*2+0,L,mid,X,Y,VAL);
			}else if( X > mid ){
				update(t*2+1,mid+1,R,X,Y,VAL);
			}else{
				update(t*2+0,L,mid,X,mid,VAL);
				update(t*2+1,mid+1,R,mid+1,Y,VAL);
			}
		}
	}
	bool show(int t,int L,int R,bool flag){
		if( dat[t] != NUM_NULL ){
			if( flag == true ){printf(" ");}
			for(int i=L;i<=R;++i){
				printf("%d",dat[t]);
				if( i+1 <= R){printf(" ");}
			}
			return true;
		}else{
			int mid = (L+R)/2;
			bool res;
			res = show(t*2+0,L,mid,flag);
			res = show(t*2+1,mid+1,R,res);
			return res;
		}
	}
};

inline void solve(){
	int n;
	scanf("%d",&n);
	sgement seg,segB;
	seg.init(n,0,-1);
	segB.init(n,0,-1);
	vector<int> s;
	map< int,vector<int> > numMap;
	set< int > numSet;
	int A;
	for(int i=0;i<n;++i){
		scanf("%d",&A);
		s.push_back(A);
		numMap[A].push_back(i);
		numSet.insert( A );
		seg.update(1,0,n-1,i,i,A);
		segB.update(1,0,n-1,i,i,A);
	}
	////////////////////
	sort(s.begin() , s.end());
	
	int size,prev,now;
	
	set<int>::iterator itr,end;
	itr = numSet.begin();
	end = numSet.end();
	
	vector<int> temp;
	for(;itr!=end;++itr){
		now = *itr;
		temp = numMap[now];
		sort(temp.begin(),temp.end());
		size = temp.size();
		segB.update(1,0,n-1,temp[0],temp[size-1],now);
	}
	segB.show(1,0,n-1,false);
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数をいっぱい表示する。16?

	solve();
}
0