結果

問題 No.318 学学学学学
ユーザー koyumeishi
提出日時 2015-12-11 02:13:40
言語 Ruby
(3.4.1)
結果
AC  
実行時間 919 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 29,244 KB
最終ジャッジ日時 2024-06-22 15:15:13
合計ジャッジ時間 16,009 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#coding = utf-8
require "set"

💩 = gets.to_i;
💩💩 = gets.split().map(&:to_i);

💩💩💩💩 = 💩💩.sort().uniq()

👾 = 💩💩💩💩.size;

for 🚽 in 0...💩 do
	👇 = -1;
	👆 = 👾-1;
	while (👆-👇>1) do
		💪 = (👇+👆)/2;
		if 💩💩[🚽] <= 💩💩💩💩[💪] then
			👆 = 💪;
		else
			👇 = 💪;
		end
	end
	💩💩[🚽] = 👆;
end

🐕💩 = Array.new(👾);
🐈💩 = Array.new(👾);

0.upto(💩-1) { |🚽|
	🐕💩[ 💩💩[🚽] ] = 🚽;
}

(💩-1).downto(0) { |🚽|
	🐈💩[ 💩💩[🚽] ] = 🚽;
}

$👉💩 = Array.new(👾+5, 0);
$💩👈 = 👾;
def add(i,x)
	i+=1;
	while(i<=$💩👈) do
		$👉💩[i] += x;
		i += i&-i;
	end
end

def get_sum(i)
	i+=1;
	ret = 0;
	while(i>0) do
		ret += $👉💩[i];
		i -= i&-i;
	end
	return ret;
end

def lower_bound(v)
	if (v<=0) then
		return 0;
	end
	x = 0;
	k = 1;
	while (k<<1) <= $💩👈 do
		k<<=1;
	end
	while k>0 do
		if(x+k<=$💩👈 && $👉💩[x+k] < v) then
			v -= $👉💩[x+k];
			x += k;
		end
		k >>= 1;
	end
	return x+1;
end

🎅 = Array.new(💩, "🎅");
contain_💩 = 0;

0.upto(💩-1) { |🚽|
	if 🐈💩[ 💩💩[🚽] ] == 🚽 then
		add(💩💩[🚽], 1);
		contain_💩 += 1;
	end
	
	🎅[🚽] = 💩💩💩💩[lower_bound(contain_💩)-1];
	
	if 🐕💩[ 💩💩[🚽] ] == 🚽 then
		add(💩💩[🚽], -1);
		contain_💩 -= 1;
	end
}


puts 🎅.join(" ")
0