結果

問題 No.318 学学学学学
ユーザー climpetclimpet
提出日時 2015-12-12 02:35:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 68,836 KB
実行使用メモリ 6,600 KB
最終ジャッジ日時 2023-09-04 17:47:42
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 7 ms
4,384 KB
testcase_02 AC 8 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 8 ms
4,384 KB
testcase_05 AC 31 ms
6,320 KB
testcase_06 AC 30 ms
6,380 KB
testcase_07 AC 29 ms
6,392 KB
testcase_08 AC 29 ms
6,280 KB
testcase_09 AC 29 ms
6,368 KB
testcase_10 AC 29 ms
6,332 KB
testcase_11 AC 31 ms
6,320 KB
testcase_12 AC 31 ms
6,272 KB
testcase_13 AC 30 ms
6,508 KB
testcase_14 AC 29 ms
6,388 KB
testcase_15 AC 29 ms
6,600 KB
testcase_16 AC 28 ms
6,432 KB
testcase_17 AC 25 ms
6,336 KB
testcase_18 AC 26 ms
6,368 KB
testcase_19 AC 24 ms
6,316 KB
testcase_20 AC 23 ms
6,336 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <climits>
#include <functional>
#include <cstring>
#include <numeric>
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]; }
}

struct hoge{
	int fst, snd;
};

int main(){
	const int INF = 1010101010;

	hoge a[MAX_N], tmp[MAX_N];
	int b[MAX_N];
	int cnt[32780] = {};

	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){
		scanf("%d", &a[i].fst);
		a[i].snd = i;
	}

	for(int i = 1; i <= n; ++i){
		b[i] = 32767 - (a[i].fst & 32767);
		++cnt[b[i] + 1];
	}
	for(int i = 1; i < 32768; ++i){
		cnt[i] += cnt[i - 1];
	}
	for(int i = 1; i <= n; ++i){
		tmp[++cnt[b[i]]] = a[i];
	}

	memset(cnt, 0, sizeof cnt);
	for(int i = 1; i <= n; ++i){
		b[i] = 32767 - (tmp[i].fst >> 15);
		++cnt[b[i] + 1];
	}
	for(int i = 1; i < 32768; ++i){
		cnt[i] += cnt[i - 1];
	}
	for(int i = 1; i <= n; ++i){
		a[++cnt[b[i]]] = tmp[i];
	}
	
	a[n + 1].fst = INF;

	for(int i = 1; i <= n; ){
		int j;
		int val = a[i].fst;
		for(j = i + 1; a[j].fst == val; ++j);
		int l = a[i].snd - 1, r = a[j - 1].snd;
		while(1){
			int x = nxt[find(l)];
			if(x > r){ break; }
			b[x] = val;
			unite(l, x);
		}
		i = j;
	}

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