結果

問題 No.318 学学学学学
ユーザー climpetclimpet
提出日時 2015-12-11 12:10:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 69,800 KB
実行使用メモリ 5,740 KB
最終ジャッジ日時 2023-09-04 17:28:20
合計ジャッジ時間 4,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 37 ms
5,444 KB
testcase_06 AC 36 ms
5,524 KB
testcase_07 AC 35 ms
5,468 KB
testcase_08 AC 35 ms
5,616 KB
testcase_09 AC 36 ms
5,572 KB
testcase_10 AC 35 ms
5,440 KB
testcase_11 AC 36 ms
5,444 KB
testcase_12 AC 36 ms
5,436 KB
testcase_13 AC 36 ms
5,360 KB
testcase_14 AC 35 ms
5,740 KB
testcase_15 AC 34 ms
5,472 KB
testcase_16 AC 31 ms
5,420 KB
testcase_17 AC 34 ms
5,352 KB
testcase_18 AC 27 ms
5,444 KB
testcase_19 AC 33 ms
5,616 KB
testcase_20 AC 29 ms
5,468 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <climits>
#include <functional>
using namespace std;

#define MAX_N 100010


typedef long long LL;
typedef pair<int,int> pii;


int par[MAX_N];
int nxt[MAX_N];
int find(int x){
	if(par[x] < 0){ return x; }
	return par[x] = find(par[x]);
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y){ return; }
	if(par[x] < par[y]){ swap(x, y); }
	par[y] += par[x];
	par[x] = y;
	if(nxt[y] < nxt[x]){ nxt[y] = nxt[x]; }
}

LL a[MAX_N];
int b[MAX_N];

int main(){
	const int INF = 1010101010;

	int n;
	scanf("%d", &n);
	for(int i = 0; i <= n; ++i){
		par[i] = -1;
		nxt[i] = i + 1;
	}

	for(int i = 1; i <= n; ++i){
		int x;
		scanf("%d", &x);
		a[i] = (LL)(INF - x) << 32 | i;
	}
	sort(a + 1, a + (n + 1));
	a[n + 1] = LLONG_MAX;

	for(int i = 1; i <= n; ){
		int j;
		int val = a[i] >> 32;
		for(j = i + 1; (a[j] >> 32) == val; ++j);
		val = INF - val;
		int l = a[i] & 0x7fffffff, r = a[j - 1] & 0x7fffffff;
		while(1){
			int x = nxt[find(l - 1)];
			if(x > r){ break; }
			b[x] = val;
			unite(l - 1, x);
		}
		i = j;
	}

	for(int i = 1; i <= n; ++i){
		printf("%d%c", b[i], i == n ? '\n' : ' ');
	}
}
0