結果

問題 No.694 square1001 and Permutation 3
ユーザー ciel
提出日時 2018-06-10 01:03:20
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 362 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 49,092 KB
最終ジャッジ日時 2024-06-30 13:07:08
合計ジャッジ時間 6,580 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other AC * 5 WA * 2 TLE * 1 -- * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

W=[0]*10**6
def bit(a,n)
	r=0
	i=n-1
	while i>=0
		idx=a[i];(r+=W[idx];idx&=idx-1)while idx>0
		idx=a[i];(W[idx]+=1;idx+=idx&-idx)while idx<n
		i-=1
	end
	r
end
n,*a=$<.map(&:to_i)
z=(1..n).sort{|i,j|a[i-1]!=a[j-1] ? a[i-1]<=>a[j-1] : i<=>j}
x=bit(z,z.size)
b=a.sort
n.times{|i|
	p x
	x-=((0...n).bsearch{|j|a[i]<=b[j]}||n)-n+((0...n).bsearch{|j|a[i]<b[j]}||n)
}
0