結果
| 問題 |
No.318 学学学学学
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2017-02-02 21:40:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,424 bytes |
| コンパイル時間 | 1,832 ms |
| コンパイル使用メモリ | 120,460 KB |
| 実行使用メモリ | 20,808 KB |
| 最終ジャッジ日時 | 2024-12-24 03:58:12 |
| 合計ジャッジ時間 | 49,307 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 13 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:129:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
129 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:136:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
136 | scanf("%d",&A);
| ~~~~~^~~~~~~~~
ソースコード
#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;
int A;
for(int i=0;i<n;++i){
scanf("%d",&A);
s.push_back(A);
seg.update(1,0,n-1,i,i,A);
segB.update(1,0,n-1,i,i,A);
}
sort(s.begin() , s.end());
vector<int>::iterator itr,end;
itr = s.begin();
end = s.end();
int L,R,prev,now;
prev = -1;
for(;itr!=end;++itr){
if( prev == *itr) continue;
prev = now = *itr;
L = seg.find(1,0,n-1,now,false);
if( L == seg.getNull() ) continue;
R = seg.find(1,0,n-1,now,true);
if( R == seg.getNull() ) continue;
segB.update(1,0,n-1,L,R,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();
}
IL_msta