結果

問題 No.318 学学学学学
ユーザー NekosyndromeNekosyndrome
提出日時 2015-12-11 00:09:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 2,720 ms
コンパイル使用メモリ 150,764 KB
実行使用メモリ 6,052 KB
最終ジャッジ日時 2023-09-04 16:11:23
合計ジャッジ時間 5,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,272 KB
testcase_01 AC 11 ms
5,248 KB
testcase_02 AC 12 ms
5,548 KB
testcase_03 AC 10 ms
5,440 KB
testcase_04 AC 11 ms
5,360 KB
testcase_05 AC 48 ms
6,052 KB
testcase_06 AC 51 ms
5,904 KB
testcase_07 AC 46 ms
6,044 KB
testcase_08 AC 43 ms
5,880 KB
testcase_09 AC 41 ms
6,044 KB
testcase_10 AC 38 ms
6,032 KB
testcase_11 AC 48 ms
5,824 KB
testcase_12 AC 44 ms
6,040 KB
testcase_13 AC 41 ms
6,048 KB
testcase_14 AC 39 ms
5,904 KB
testcase_15 AC 38 ms
5,908 KB
testcase_16 AC 33 ms
6,028 KB
testcase_17 AC 43 ms
5,844 KB
testcase_18 AC 32 ms
6,020 KB
testcase_19 AC 42 ms
5,848 KB
testcase_20 AC 32 ms
5,904 KB
testcase_21 AC 3 ms
5,112 KB
testcase_22 AC 3 ms
5,192 KB
testcase_23 AC 3 ms
5,140 KB
testcase_24 AC 3 ms
5,172 KB
testcase_25 AC 3 ms
5,060 KB
testcase_26 AC 3 ms
5,060 KB
testcase_27 AC 3 ms
5,180 KB
testcase_28 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define L (cur*2)
#define R (L+1)
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
int n,ans[M
];
int tree[M*4];
vector<P> in;

void upd(int cur,int ll,int rr,int l,int r,int val)
{
	if(ll==l && rr==r)
	{
		tree[cur] = max(tree[cur], val);
		return;
	}

	int mid=(ll+rr)/2;
	if(r<=mid) upd(L,ll,mid,l,r,val);
	else if(l>mid) upd(R,mid+1,rr,l,r,val);
	else
	{
		upd(L,ll,mid,l,mid,val);
		upd(R,mid+1,rr,mid+1,r,val);
	}
}
void calc(int cur,int ll,int rr,int mxv)
{
	mxv = max(mxv, tree[cur]);
	if(ll==rr)
	{
		ans[ll] = mxv;
		return;
	}
	int mid=(ll+rr)/2;
	calc(L,ll,mid,mxv);
	calc(R,mid+1,rr,mxv);
}
int main()
{
	int x;
	while(~scanf("%d",&n))
	{
		MSET(tree,0);
		in.clear();
		REP(i,1,n)
		{
			RI(x);
			in.PB( MP(x,i) );
		}
		sort(in.begin(), in.end());

		int l=0;
		while(l<n)
		{
			int r=l;
			while(r+1<n && in[r+1].F==in[r].F) r++;
			upd(1,1,n,in[l].S,in[r].S,in[l].F);
			l=r+1;
		}

		calc(1,1,n,-1);
		REP(i,1,n)
		{
			if(i!=1)putchar(' ');
			printf("%d",ans[i]);
		}
		puts("");
	}
	return 0;
}
0