結果

問題 No.318 学学学学学
ユーザー TawaraTawara
提出日時 2015-12-18 17:24:53
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,627 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 6,528 KB
実行使用メモリ 55,640 KB
最終ジャッジ日時 2023-09-04 18:20:27
合計ジャッジ時間 20,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
10,420 KB
testcase_01 AC 124 ms
12,932 KB
testcase_02 AC 157 ms
13,976 KB
testcase_03 AC 96 ms
11,992 KB
testcase_04 AC 129 ms
13,268 KB
testcase_05 AC 1,627 ms
55,640 KB
testcase_06 AC 1,626 ms
35,636 KB
testcase_07 AC 1,464 ms
32,892 KB
testcase_08 AC 1,303 ms
23,244 KB
testcase_09 AC 1,127 ms
20,908 KB
testcase_10 AC 748 ms
16,980 KB
testcase_11 AC 1,536 ms
55,564 KB
testcase_12 AC 1,152 ms
35,508 KB
testcase_13 AC 1,036 ms
32,984 KB
testcase_14 AC 924 ms
23,304 KB
testcase_15 AC 770 ms
20,864 KB
testcase_16 AC 378 ms
16,880 KB
testcase_17 AC 430 ms
35,164 KB
testcase_18 AC 1,114 ms
35,344 KB
testcase_19 AC 1,399 ms
35,248 KB
testcase_20 AC 917 ms
15,792 KB
testcase_21 AC 11 ms
6,004 KB
testcase_22 AC 11 ms
5,996 KB
testcase_23 AC 12 ms
6,084 KB
testcase_24 AC 12 ms
6,136 KB
testcase_25 AC 12 ms
5,976 KB
testcase_26 AC 11 ms
6,128 KB
testcase_27 AC 11 ms
6,080 KB
testcase_28 AC 12 ms
5,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

bitN = 0; bit = []
def bit_add(a,w):
	while a <= bitN: bit[a] += w; a += a&(-a)
def bit_sum(a):
	ret = 0
	while a > 0: ret += bit[a]; a -= a&(-a)
	return ret
N = input()
a = map(int,raw_input().split())
b = [0]*N; c = {}; dc = {}; pos = {}
for i,v in enumerate(a):
	if v in pos: pos[v][1]=i
	else: pos[v]=[i,i]
tmp = 0 
for v in sorted(a):
	if v > tmp: bitN += 1; tmp = v; c[v] = bitN; dc[bitN] = v
bit = [0]*(bitN+1)
for i,v in enumerate(a):
	bp = bitN-c[v]+1
	if bit_sum(bp-1) == 0: b[i] = v
	else:
		l = 0; r = bp-1
		while r - l > 1:
			mid = (l+r) / 2
			if bit_sum(mid): r = mid
			else: l = mid
		b[i] = dc[bitN-r+1]
	if i == pos[v][0]: bit_add(bp, 1)
	if i == pos[v][1]: bit_add(bp,-1)
print " ".join(map(str,b))
0