結果
| 問題 | 
                            No.1705 Mode of long array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-12-17 11:29:10 | 
| 言語 | Go  (1.23.4)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,534 bytes | 
| コンパイル時間 | 12,138 ms | 
| コンパイル使用メモリ | 236,220 KB | 
| 実行使用メモリ | 7,680 KB | 
| 最終ジャッジ日時 | 2024-09-14 12:12:21 | 
| 合計ジャッジ時間 | 19,916 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 3 | 
| other | WA * 51 | 
ソースコード
package main
import (
	"bufio"
	"os"
	"strconv"
)
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() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	sc.Scan()
	M, _ := strconv.Atoi(sc.Text())	
	var tree SegmentTree
	tree.new(M)
	for i := 0; i < M; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		tree.update(i, a)
	}
	sc.Scan()
	Q, _ := strconv.Atoi(sc.Text())	
	for i := 0; i < Q; i++ {
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		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 {
			println(tree.max())
		}
	}
}