結果

問題 No.318 学学学学学
ユーザー IL_mstaIL_msta
提出日時 2015-12-11 19:12:17
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,817 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 108,948 KB
実行使用メモリ 8,828 KB
最終ジャッジ日時 2023-10-13 11:16:27
合計ジャッジ時間 7,321 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,192 ms
8,688 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <valarray>

#include<cassert>//assert();
//#include <random>//xAOJ
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
/////////

void solve(){
	int N;
	cin >> N;
	vector<int> data(N);
	for(int i=0;i<N;++i){
		cin >> data[i];
	}
	
	//
	/*
	int N = 100000;
	vector<int> data(N);
	for(int i=0;i<N;++i){
		data[i] = i%50000;
	}*/
	//
	//最大10^5個の要素を得る
	vector<int> uni(N);
	uni = data;
	sort( uni.begin(), uni.end() );
	uni.erase( unique( uni.begin(),uni.end() ), uni.end() );
	//uniに要素が昇順で一個ずつ入っている。
	
	//
	vector<int>::iterator it,endit,start;
	it = uni.begin();
	endit = uni.end();
	vector< vector<int> > list( uni.size() );
	
	int uSize = uni.size();
	int temp;
	int Pos;
	for(int i=0;i<N;++i){
		temp = data[i];
		//tempがi番目にある。
		it = lower_bound( uni.begin(), uni.end(), temp );
		Pos = (it - uni.begin() );
		list[Pos].push_back( i );
	}
	
	int sPos,ePos,ter;
	ter = uni[uSize-1];
	pair<int,int> pTemp,Atemp[2];
	bool Aflag[2];
	pTemp.first  = 0;
	pTemp.second = N-1;
	vector< pair<int,int> > hani;
	hani.push_back( pTemp );
	vector< pair<int,int> >::iterator pIt,pEnd;
	
	for(int i=uSize-1;i>=0; --i){
		ter  = uni[i];
		sPos = *(list[i].begin());
		ePos = *(list[i].end()-1);
		
		pIt  = hani.begin();
		pEnd = hani.end();
		while( sPos <= ePos && pIt != hani.end() ){
			if( ePos < pIt->first ) break;
			if( pIt->second < sPos ){
				++pIt;
				continue;
			}
			int A,B;
			A = max( sPos,pIt->first  );
			B = min( ePos,pIt->second );
			Aflag[0] = false;
			Aflag[1] = false;

			for(int j=A;j<=B;++j){
				data[j] = ter;
			}
			if( pIt->first != A ){
				Atemp[0].first  = pIt->first;
				Atemp[0].second = A-1;
				Aflag[0] = true;
			}
			if( pIt->second != B ){
				Atemp[1].first = B;
				Atemp[1].second = pIt->second;
				Aflag[1] = true;
			}
			sPos = pIt->second + 1;
			hani.erase( pIt );
			for(int j=0;j<2;++j){
				if( Aflag[j] ){
					hani.push_back( Atemp[j] );
				}
			}
			sort( hani.begin(), hani.end() );
			pIt = hani.begin();
		}
	}

	//結果表示
	for(int i=0;i<N;++i){
		if( i != 0 ){
			cout << " ";
		}
		cout << data[i];
	}cout << endl;
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	//cpp
	solve();
	
	return 0;
}
0