結果

問題 No.230 Splarraay スプラレェーイ
ユーザー pekempeypekempey
提出日時 2017-01-27 21:04:11
言語 F#
(F# 4.0)
結果
AC  
実行時間 412 ms / 5,000 ms
コード長 2,246 bytes
コンパイル時間 4,521 ms
コンパイル使用メモリ 165,592 KB
実行使用メモリ 34,680 KB
最終ジャッジ日時 2023-08-25 03:44:51
合計ジャッジ時間 10,095 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
27,088 KB
testcase_01 AC 87 ms
24,972 KB
testcase_02 AC 86 ms
24,972 KB
testcase_03 AC 86 ms
24,944 KB
testcase_04 AC 88 ms
25,016 KB
testcase_05 AC 91 ms
27,076 KB
testcase_06 AC 105 ms
25,028 KB
testcase_07 AC 89 ms
25,148 KB
testcase_08 AC 92 ms
24,964 KB
testcase_09 AC 239 ms
29,892 KB
testcase_10 AC 286 ms
29,072 KB
testcase_11 AC 175 ms
29,620 KB
testcase_12 AC 236 ms
29,856 KB
testcase_13 AC 113 ms
27,276 KB
testcase_14 AC 247 ms
29,076 KB
testcase_15 AC 323 ms
27,076 KB
testcase_16 AC 360 ms
29,820 KB
testcase_17 AC 412 ms
32,736 KB
testcase_18 AC 294 ms
32,720 KB
testcase_19 AC 276 ms
34,680 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

type Segtree() =
    let n = 1 <<< 17
    let dat = Array.zeroCreate (n * 2)
    let lz = Array.create (n * 2) -1

    member this.N with get() = n
    member this.Dat with get() = dat
    member this.Lazy with get() = lz

    member this.SetLazy k v s =
        this.Dat.[k] <- v * s
        this.Lazy.[k] <- v

    member this.Push k s =
        if this.Lazy.[k] <> -1 then
            this.SetLazy (k * 2 + 0) this.Lazy.[k] (s / 2)
            this.SetLazy (k * 2 + 1) this.Lazy.[k] (s / 2)
            this.Lazy.[k] <- -1

    member this.RecFill ql qr v k nl nr =
        if ql <= nl && nr <= qr then
            this.SetLazy k v (nr - nl)
        else
            let nm = (nl + nr) / 2
            this.Push k (nr - nl)
            if ql < nm then
                this.RecFill ql qr v (k * 2 + 0) nl nm
            if qr > nm then
                this.RecFill ql qr v (k * 2 + 1) nm nr
            this.Dat.[k] <- this.Dat.[k * 2] + this.Dat.[k * 2 + 1]

    member this.Fill ql qr v = this.RecFill ql qr v 1 0 this.N

    member this.RecSum ql qr k nl nr = 
        if ql <= nl && nr <= qr then
            this.Dat.[k]
        elif nr <= ql || qr <= nl then
            0
        else
            this.Push k (nr - nl)
            let nm = (nl + nr) / 2
            let vl = this.RecSum ql qr (k * 2 + 0) nl nm
            let vr = this.RecSum ql qr (k * 2 + 1) nm nr
            vl + vr

    member this.Sum ql qr = this.RecSum ql qr 1 0 this.N

let N = System.Console.ReadLine() |> int
let Q = System.Console.ReadLine() |> int

let segA = new Segtree()
let segB = new Segtree()

let mutable scoreA : int64 = 0L
let mutable scoreB : int64 = 0L

for _ in 1 .. Q do
    let x, l, r = System.Console.ReadLine().Split() |> Array.map int |> fun a -> a.[0], a.[1], a.[2]

    if x = 0 then
        let a = segA.Sum l (r + 1)
        let b = segB.Sum l (r + 1)
        if a > b then
            scoreA <- scoreA + int64(a)
        if a < b then
            scoreB <- scoreB + int64(b)
    elif x = 1 then
        segA.Fill l (r + 1) 1
        segB.Fill l (r + 1) 0
    else
        segA.Fill l (r + 1) 0
        segB.Fill l (r + 1) 1

scoreA <- scoreA + int64(segA.Sum 0 N)
scoreB <- scoreB + int64(segB.Sum 0 N)

printfn "%d %d" scoreA scoreB
0