結果
| 問題 |
No.318 学学学学学
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-12-11 19:12:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,817 bytes |
| コンパイル時間 | 1,484 ms |
| コンパイル使用メモリ | 110,588 KB |
| 実行使用メモリ | 13,756 KB |
| 最終ジャッジ日時 | 2024-09-15 08:16:35 |
| 合計ジャッジ時間 | 7,621 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 1 TLE * 1 -- * 24 |
ソースコード
#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;
}
IL_msta