結果
問題 | No.318 学学学学学 |
ユーザー |
![]() |
提出日時 | 2017-02-02 22:15:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 248 ms / 2,000 ms |
コード長 | 3,479 bytes |
コンパイル時間 | 2,206 ms |
コンパイル使用メモリ | 135,048 KB |
実行使用メモリ | 22,688 KB |
最終ジャッジ日時 | 2024-06-22 18:09:29 |
合計ジャッジ時間 | 6,246 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
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:138:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 138 | 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 queryint 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();}