結果

問題 No.865 24時間降水量
ユーザー pekempeypekempey
提出日時 2019-08-16 21:45:16
言語 OCaml
(5.1.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,341 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 19,748 KB
実行使用メモリ 10,548 KB
最終ジャッジ日時 2023-07-30 07:20:50
合計ジャッジ時間 10,337 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 11 ms
5,632 KB
testcase_06 AC 12 ms
5,692 KB
testcase_07 AC 11 ms
5,580 KB
testcase_08 AC 11 ms
5,552 KB
testcase_09 AC 11 ms
5,620 KB
testcase_10 AC 78 ms
5,824 KB
testcase_11 AC 77 ms
5,672 KB
testcase_12 AC 77 ms
5,776 KB
testcase_13 AC 77 ms
5,872 KB
testcase_14 AC 77 ms
5,844 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

open Scanf
open Printf

let readint () = scanf " %d" (fun x -> x)

type rmq = { dat : int array; n : int }
module RMQ = struct
  let make (n : int) : rmq = let rec f x = if x >= n then x else f (x * 2) in { dat = Array.make (2 * f n) min_int; n = f n  }
  let update (rmq : rmq) (k : int) (v : int) =
    let k = ref (k + rmq.n) in
    rmq.dat.(!k) <- v;
    while !k > 1 do
      k := !k lsr 1;
      rmq.dat.(!k) <- max rmq.dat.(!k*2) rmq.dat.(!k*2+1)
    done
  let query (rmq : rmq) (l : int) (r : int) =
    let l = ref (l + rmq.n) in
    let r = ref (r + rmq.n - 1) in
    let ans = ref min_int in
    while !l <= !r do
      if (!l land 1) = 1 then (ans := max !ans rmq.dat.(!l); incr l);
      if (!r land 1) = 0 then (ans := max !ans rmq.dat.(!r); decr r);
      l := !l lsr 1;
      r := !r lsr 1;
    done;
    !ans
end;;

let () =
  let n = readint () in
  let a = Array.init n (fun _ -> readint ()) in
  let q = readint () in
  let rmq = RMQ.make (n - 24 + 1) in
  let calc i = Array.sub a i 24 |> Array.fold_left (+) 0 in
  for i = 0 to n - 24 do
    RMQ.update rmq i (calc i);
  done;
  for _ = 0 to q - 1 do
    let t = readint () - 1 and v = readint () in
    a.(t) <- v;
    for i = min (n - 24) t downto max 0 (t - 23) do
      RMQ.update rmq i (calc i);
    done;
    printf "%d\n" (RMQ.query rmq 0 (n - 24 + 1))
  done;
0