結果
問題 |
No.1705 Mode of long array
|
ユーザー |
|
提出日時 | 2021-12-17 10:09:42 |
言語 | Go (1.23.4) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,290 bytes |
コンパイル時間 | 13,984 ms |
コンパイル使用メモリ | 234,868 KB |
実行使用メモリ | 16,328 KB |
最終ジャッジ日時 | 2024-09-14 10:31:38 |
合計ジャッジ時間 | 64,571 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 TLE * 16 |
ソースコード
package main import "fmt" type SegmentTree struct { n int dat [][2]int } func (this *SegmentTree) new(n int) { this.n = 1 for this.n < n { this.n *= 2 } this.dat = make([][2]int, 2*this.n-1) for _, d := range this.dat { d[0], d[1] = -1, -1 } } func (this *SegmentTree) update(k int, a int) { i := k k += this.n - 1 this.dat[k][0] = a this.dat[k][1] = i 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][1] + 1 } func (this SegmentTree) get(i int) int { return this.dat[i + this.n - 1][0] } func Max(a [2]int, b [2]int) [2]int{ if a[0] > b[0] { return a } else if a[0] < b[0] { return b } else if a[1] >= b[1] { return a } else { return b } } func main() { var N, M int fmt.Scan(&N, &M) var tree SegmentTree tree.new(M) for i := 0; i < M; i++ { var a int fmt.Scan(&a) tree.update(i, a) } var Q int fmt.Scan(&Q) q := make([][3]int, Q, Q) for i := 0; i < Q; i++ { fmt.Scan(&q[i][0], &q[i][1], &q[i][2]) } for _, a := range q { var ( t, x, y = a[0], a[1], a[2] ) 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.Println(tree.max()) } } }