結果
問題 | No.1705 Mode of long array |
ユーザー | 小野寺健 |
提出日時 | 2021-12-17 11:56:28 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 264 ms / 3,000 ms |
コード長 | 1,419 bytes |
コンパイル時間 | 12,305 ms |
コンパイル使用メモリ | 211,900 KB |
実行使用メモリ | 14,504 KB |
最終ジャッジ日時 | 2023-10-12 13:49:19 |
合計ジャッジ時間 | 24,157 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 3 ms
4,348 KB |
testcase_04 | AC | 3 ms
4,352 KB |
testcase_05 | AC | 4 ms
4,352 KB |
testcase_06 | AC | 10 ms
4,348 KB |
testcase_07 | AC | 12 ms
4,352 KB |
testcase_08 | AC | 11 ms
4,352 KB |
testcase_09 | AC | 10 ms
4,352 KB |
testcase_10 | AC | 10 ms
4,348 KB |
testcase_11 | AC | 11 ms
4,348 KB |
testcase_12 | AC | 10 ms
4,348 KB |
testcase_13 | AC | 203 ms
14,420 KB |
testcase_14 | AC | 148 ms
10,092 KB |
testcase_15 | AC | 127 ms
7,960 KB |
testcase_16 | AC | 153 ms
7,964 KB |
testcase_17 | AC | 110 ms
7,804 KB |
testcase_18 | AC | 87 ms
5,700 KB |
testcase_19 | AC | 171 ms
7,968 KB |
testcase_20 | AC | 111 ms
7,964 KB |
testcase_21 | AC | 158 ms
14,364 KB |
testcase_22 | AC | 228 ms
14,408 KB |
testcase_23 | AC | 124 ms
7,940 KB |
testcase_24 | AC | 124 ms
7,940 KB |
testcase_25 | AC | 123 ms
7,944 KB |
testcase_26 | AC | 124 ms
7,944 KB |
testcase_27 | AC | 123 ms
7,944 KB |
testcase_28 | AC | 123 ms
7,944 KB |
testcase_29 | AC | 124 ms
7,944 KB |
testcase_30 | AC | 124 ms
7,940 KB |
testcase_31 | AC | 124 ms
7,944 KB |
testcase_32 | AC | 125 ms
7,940 KB |
testcase_33 | AC | 261 ms
14,500 KB |
testcase_34 | AC | 263 ms
14,492 KB |
testcase_35 | AC | 263 ms
14,504 KB |
testcase_36 | AC | 262 ms
14,504 KB |
testcase_37 | AC | 261 ms
14,488 KB |
testcase_38 | AC | 259 ms
14,488 KB |
testcase_39 | AC | 260 ms
14,504 KB |
testcase_40 | AC | 264 ms
14,500 KB |
testcase_41 | AC | 260 ms
14,492 KB |
testcase_42 | AC | 259 ms
14,492 KB |
testcase_43 | AC | 203 ms
14,424 KB |
testcase_44 | AC | 203 ms
14,416 KB |
testcase_45 | AC | 202 ms
14,424 KB |
testcase_46 | AC | 203 ms
14,416 KB |
testcase_47 | AC | 204 ms
14,436 KB |
testcase_48 | AC | 204 ms
14,436 KB |
testcase_49 | AC | 253 ms
14,440 KB |
testcase_50 | AC | 253 ms
14,432 KB |
testcase_51 | AC | 255 ms
14,440 KB |
testcase_52 | AC | 253 ms
14,444 KB |
testcase_53 | AC | 254 ms
14,444 KB |
ソースコード
package main import ( "fmt" "bufio" "os" ) type KeyValue struct { key int value int } type SegmentTree struct { n int dat []*KeyValue } func (this *SegmentTree) new(n int) { this.n = 1 for this.n < n { this.n *= 2 } this.dat = make([]*KeyValue, 2*this.n-1) for i := 0; i < 2*this.n-1; i++ { this.dat[i] = &KeyValue{-1, -1} } } func (this *SegmentTree) update(k int, a int) { i := k k += this.n - 1 this.dat[k].key = i this.dat[k].value = a for k > 0 { k = (k - 1) / 2 this.dat[k] = Max(this.dat[k * 2 + 1], this.dat[k * 2 + 2]) } } func (this SegmentTree) max() int { return this.dat[0].key + 1 } func (this SegmentTree) get(i int) int { return this.dat[i + this.n - 1].value } func Max(a *KeyValue, b *KeyValue) *KeyValue{ if a.value > b.value { return a } else if a.value < b.value { return b } else if a.key >= b.key { return a } else { return b } } func main() { r := bufio.NewReader(os.Stdin) w := bufio.NewWriter(os.Stdout) defer w.Flush() var N, M int fmt.Fscan(r, &N, &M) var tree SegmentTree tree.new(M) for i := 0; i < M; i++ { var a int fmt.Fscan(r, &a) tree.update(i, a) } var Q int fmt.Fscan(r, &Q) for i := 0; i < Q; i++ { var t, x, y int fmt.Fscan(r, &t, &x, &y) if t == 1 { tree.update(x-1, tree.get(x-1) + y) } else if t == 2 { tree.update(x-1, tree.get(x-1) - y) } else { fmt.Fprintln(w, tree.max()) } } }