結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー tomeruntomerun
提出日時 2024-02-23 23:05:05
言語 Crystal
(1.11.2)
結果
AC  
実行時間 474 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 12,927 ms
コンパイル使用メモリ 294,396 KB
実行使用メモリ 35,228 KB
最終ジャッジ日時 2024-02-23 23:06:00
合計ジャッジ時間 48,223 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 417 ms
6,676 KB
testcase_02 AC 406 ms
6,676 KB
testcase_03 AC 390 ms
6,676 KB
testcase_04 AC 367 ms
6,676 KB
testcase_05 AC 371 ms
6,676 KB
testcase_06 AC 385 ms
6,676 KB
testcase_07 AC 393 ms
13,440 KB
testcase_08 AC 388 ms
11,264 KB
testcase_09 AC 428 ms
14,208 KB
testcase_10 AC 383 ms
13,184 KB
testcase_11 AC 399 ms
11,648 KB
testcase_12 AC 407 ms
14,080 KB
testcase_13 AC 411 ms
22,980 KB
testcase_14 AC 446 ms
26,648 KB
testcase_15 AC 400 ms
19,628 KB
testcase_16 AC 388 ms
15,296 KB
testcase_17 AC 432 ms
15,692 KB
testcase_18 AC 397 ms
19,616 KB
testcase_19 AC 398 ms
20,576 KB
testcase_20 AC 438 ms
27,104 KB
testcase_21 AC 412 ms
27,360 KB
testcase_22 AC 415 ms
27,360 KB
testcase_23 AC 411 ms
27,360 KB
testcase_24 AC 438 ms
27,360 KB
testcase_25 AC 415 ms
27,360 KB
testcase_26 AC 441 ms
27,360 KB
testcase_27 AC 412 ms
27,360 KB
testcase_28 AC 410 ms
27,360 KB
testcase_29 AC 445 ms
26,364 KB
testcase_30 AC 428 ms
27,360 KB
testcase_31 AC 437 ms
27,360 KB
testcase_32 AC 446 ms
27,360 KB
testcase_33 AC 416 ms
27,360 KB
testcase_34 AC 437 ms
27,360 KB
testcase_35 AC 423 ms
27,360 KB
testcase_36 AC 435 ms
27,360 KB
testcase_37 AC 413 ms
27,360 KB
testcase_38 AC 413 ms
27,360 KB
testcase_39 AC 474 ms
27,360 KB
testcase_40 AC 436 ms
35,228 KB
testcase_41 AC 418 ms
27,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353i64

read_line.to_i.times do
  solve()
end

def solve
  n, l = read_line.split.map(&.to_i)
  xys = Array.new(n) { read_line.split.map(&.to_i) }
  mo = Mo.new(l, (l + 1 + 499) // 500)
  xys.each do |xy|
    mo.add_query(xy[0], xy[1])
  end
  mo.build
  puts n
  mo.each do |x, y, _|
    puts "#{x} #{y}"
  end
end

class Mo
  include Enumerable(Tuple(Int32, Int32, Int32))

  def initialize(@n : Int32, @bucket_size : Int32)
    @bucket = Array(Array(Int32)).new((@n + @bucket_size - 1) // @bucket_size) { [] of Int32 }
    @qs = Array(Tuple(Int32, Int32)).new
  end

  def add_query(l : Int32, r : Int32)
    @bucket[l // @bucket_size] << @qs.size
    @qs << {l, r}
  end

  def build
    @bucket.size.times do |i|
      @bucket[i].sort_by! { |qi| @qs[qi][1] }
      if i % 2 != 0
        @bucket[i].reverse!
      end
    end
  end

  def each
    @bucket.each do |b|
      b.each do |qi|
        yield ({@qs[qi][0], @qs[qi][1], qi})
      end
    end
  end
end
0