結果

問題 No.694 square1001 and Permutation 3
ユーザー cielciel
提出日時 2018-12-04 01:40:47
言語 Crystal
(1.11.2)
結果
TLE  
実行時間 -
コード長 325 bytes
コンパイル時間 18,780 ms
コンパイル使用メモリ 261,400 KB
実行使用メモリ 15,224 KB
最終ジャッジ日時 2023-09-13 09:53:20
合計ジャッジ時間 27,374 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

W=[0]*9**6
a=ARGF.gets_to_end.split.map &.to_i
i=n=a.shift
z=(0...n).to_a.sort{|i,j|a[i]!=a[j] ? a[i]<=>a[j]: i<=>j}
r=0_i64
b=a.sort
while 0<=(i-=1)
k=z[i];while k>0;r+=W[k];k-=k&-k end
k=z[i]+1;while k<=n;W[k]+=1;k+=k&-k end
end
n.times{|i|puts r;r-=((0...n).bsearch{|j|a[i]<=b[j]}||n)-n+((0...n).bsearch{|j|a[i]<b[j]}||n)}
0