結果

問題 No.1338 Giant Class
ユーザー semisagisemisagi
提出日時 2021-01-15 22:19:34
言語 Swift
(5.10.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 3,391 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 185,736 KB
実行使用メモリ 21,816 KB
最終ジャッジ日時 2024-05-05 00:17:26
合計ジャッジ時間 6,476 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
15,488 KB
testcase_01 AC 9 ms
15,744 KB
testcase_02 AC 207 ms
15,744 KB
testcase_03 AC 10 ms
15,616 KB
testcase_04 AC 10 ms
15,744 KB
testcase_05 AC 10 ms
15,488 KB
testcase_06 AC 154 ms
18,696 KB
testcase_07 AC 217 ms
18,444 KB
testcase_08 AC 148 ms
18,644 KB
testcase_09 AC 138 ms
18,444 KB
testcase_10 AC 237 ms
18,572 KB
testcase_11 AC 32 ms
16,256 KB
testcase_12 AC 173 ms
18,444 KB
testcase_13 AC 159 ms
18,444 KB
testcase_14 AC 51 ms
16,516 KB
testcase_15 AC 69 ms
16,264 KB
testcase_16 AC 30 ms
16,000 KB
testcase_17 AC 159 ms
18,440 KB
testcase_18 AC 48 ms
16,264 KB
testcase_19 AC 80 ms
16,900 KB
testcase_20 AC 278 ms
21,556 KB
testcase_21 AC 282 ms
21,816 KB
testcase_22 AC 278 ms
21,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Foundation

struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        defer { index += 1 }
        return peek()
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextInts(_ n: Int) -> [Int] {
        return (0 ..< n).map { _ in nextInt() }
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

let mod = 1000000007

struct Zn: CustomStringConvertible, AdditiveArithmetic {
    let n: Int

    init(_ n: Int) {
        self.n = n
    }

    var description: String {
        String(self.n)
    }

    static var zero = Zn(0)
    static var one = Zn(1)

    static func + (lhs: Self, rhs: Self) -> Self {
        let n = lhs.n + rhs.n
        return Zn(n < mod ? n : n - mod)
    }

    static func + (lhs: Self, rhs: Int) -> Self {
        return lhs + Zn(rhs)
    }

    static func + (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) + rhs
    }

    static func - (lhs: Self, rhs: Self) -> Self {
        let n = lhs.n - rhs.n
        return Zn(n >= 0 ? n : n + mod)
    }

    static func - (lhs: Self, rhs: Int) -> Self {
        return lhs - Zn(rhs)
    }

    static func - (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) - rhs
    }

    static func * (lhs: Self, rhs: Self) -> Self {
        Zn((lhs.n * rhs.n) % mod)
    }

    static func * (lhs: Self, rhs: Int) -> Self {
        return lhs * Zn(rhs)
    }

    static func * (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) * rhs
    }

    static func / (lhs: Zn, rhs: Zn) -> Self {
        return lhs * rhs.inverse
    }

    static func / (lhs: Int, rhs: Zn) -> Self {
        return Zn(lhs) * rhs.inverse
    }

    static func / (lhs: Zn, rhs: Int) -> Self {
        return lhs * Zn(rhs).inverse
    }

    static func += (lhs: inout Self, rhs: Self) {
        lhs = lhs + rhs
    }

    static func += (lhs: inout Self, rhs: Int) {
        lhs = lhs + Zn(rhs)
    }

    static func -= (lhs: inout Self, rhs: Self) {
        lhs = lhs - rhs
    }

    static func -= (lhs: inout Self, rhs: Int) {
        lhs = lhs - Zn(rhs)
    }

    static func *= (lhs: inout Self, rhs: Self) {
        lhs = lhs * rhs
    }

    static func *= (lhs: inout Self, rhs: Int) {
        lhs = lhs * Zn(rhs)
    }

    static func /= (lhs: inout Self, rhs: Self) {
        lhs = lhs / rhs
    }

    static func /= (lhs: inout Self, rhs: Int) {
        lhs = lhs / Zn(rhs)
    }

    func pow(_ n: Int) -> Self {
        if n == 0 {
            return Zn(1)
        } else if n % 2 == 1 {
            return self * self.pow(n - 1)
        } else {
            return (self * self).pow(n / 2)
        }
    }

    var inverse: Self {
        self.pow(mod - 2)
    }
}



var scanner = Scanner()
let H = scanner.nextInt()
let W = scanner.nextInt()
let Q = scanner.nextInt()
var smallest = [Int: Int]()
var answer = H * W

for _ in 0 ..< Q {
    let y = scanner.nextInt()
    let x = scanner.nextInt()
    if y < smallest[x, default: H + 1] {
        answer -= smallest[x, default: H + 1] - y
        smallest[x] = y
    }
    print(answer)
}


0