← Home
For problem statement at 0-999/800-899/830-839/837/problemG.txt this is a correct solution, but verifier at 0-999/800-899/830-839/837/verifierG.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"io"
	"os"
)

const MAX_X = 200000

type updateItem struct {
	idx int
	A, B int64
}

type PerSegmentTree struct {
	left  []int32
	right []int32
	sumA  []int64
	sumB  []int64
}

func NewPerSegmentTree(cap int) *PerSegmentTree {
	pst := &PerSegmentTree{}
	pst.left = make([]int32, 1, cap)
	pst.right = make([]int32, 1, cap)
	pst.sumA = make([]int64, 1, cap)
	pst.sumB = make([]int64, 1, cap)
	return pst
}

func (pst *PerSegmentTree) newNode() int32 {
	pst.left = append(pst.left, 0)
	pst.right = append(pst.right, 0)
	pst.sumA = append(pst.sumA, 0)
	pst.sumB = append(pst.sumB, 0)
	return int32(len(pst.left) - 1)
}

func (pst *PerSegmentTree) update(prev int32, l, r int, pos int, valA, valB int64) int32 {
	node := pst.newNode()
	pst.left[node] = pst.left[prev]
	pst.right[node] = pst.right[prev]
	pst.sumA[node] = pst.sumA[prev] + valA
	pst.sumB[node] = pst.sumB[prev] + valB
	if l == r {
		return node
	}
	mid := (l + r) >> 1
	if pos <= mid {
		pst.left[node] = pst.update(pst.left[prev], l, mid, pos, valA, valB)
	} else {
		pst.right[node] = pst.update(pst.right[prev], mid+1, r, pos, valA, valB)
	}
	return node
}

func (pst *PerSegmentTree) query(node int32, l, r int, ql, qr int) (int64, int64) {
	if node == 0 || ql > r || qr < l {
		return 0, 0
	}
	if ql <= l && r <= qr {
		return pst.sumA[node], pst.sumB[node]
	}
	mid := (l + r) >> 1
	a1, b1 := pst.query(pst.left[node], l, mid, ql, qr)
	a2, b2 := pst.query(pst.right[node], mid+1, r, ql, qr)
	return a1 + a2, b1 + b2
}

var inputBytes []byte
var inputPos int

func nextInt() int {
	for inputPos < len(inputBytes) && (inputBytes[inputPos] < '0' || inputBytes[inputPos] > '9') {
		inputPos++
	}
	x := 0
	for inputPos < len(inputBytes) && inputBytes[inputPos] >= '0' && inputBytes[inputPos] <= '9' {
		x = x*10 + int(inputBytes[inputPos]-'0')
		inputPos++
	}
	return x
}

var outBuf []byte

func writeInt(x int64) {
	if x == 0 {
		outBuf = append(outBuf, '0', '\n')
		return
	}
	var tmp [20]byte
	i := len(tmp)
	for x > 0 {
		i--
		tmp[i] = byte(x%10) + '0'
		x /= 10
	}
	outBuf = append(outBuf, tmp[i:]...)
	outBuf = append(outBuf, '\n')
}

func main() {
	var err error
	inputBytes, err = io.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	n := nextInt()
	basePref := make([]int64, n+1)
	maxX := 0

	up1 := make([][]updateItem, MAX_X+1)
	up2 := make([][]updateItem, MAX_X+1)

	for i := 1; i <= n; i++ {
		x1 := nextInt()
		x2 := nextInt()
		y1 := nextInt()
		a := nextInt()
		b := nextInt()
		y2 := nextInt()

		basePref[i] = basePref[i-1] + int64(y1)
		if x2 > maxX {
			maxX = x2
		}
		up1[x1] = append(up1[x1], updateItem{i, int64(a), int64(b) - int64(y1)})
		up2[x2] = append(up2[x2], updateItem{i, int64(a), int64(b) - int64(y2)})
	}

	capacity := 1 + n*18
	pst1 := NewPerSegmentTree(capacity)
	pst2 := NewPerSegmentTree(capacity)

	vers1 := make([]int32, maxX+2)
	vers2 := make([]int32, maxX+2)
	vers1[0] = 0
	vers2[0] = 0

	prev := int32(0)
	for v := 0; v <= maxX; v++ {
		root := prev
		for _, up := range up1[v] {
			root = pst1.update(root, 1, n, up.idx, up.A, up.B)
		}
		vers1[v+1] = root
		prev = root
	}

	prev = int32(0)
	for v := 0; v <= maxX; v++ {
		root := prev
		for _, up := range up2[v] {
			root = pst2.update(root, 1, n, up.idx, up.A, up.B)
		}
		vers2[v+1] = root
		prev = root
	}

	m := nextInt()
	last := int64(0)
	for i := 0; i < m; i++ {
		l := nextInt()
		r := nextInt()
		x := nextInt()
		xi := (int64(x) + last) % 1000000000
		var vIdx int
		if xi > int64(maxX) {
			vIdx = maxX + 1
		} else {
			vIdx = int(xi)
		}
		a1, b1 := pst1.query(vers1[vIdx], 1, n, l, r)
		a2, b2 := pst2.query(vers2[vIdx], 1, n, l, r)
		ans := basePref[r] - basePref[l-1] + xi*(a1-a2) + (b1 - b2)
		last = ans
		writeInt(ans)
	}

	os.Stdout.Write(outBuf)
}
```