For problem statement at 1000-1999/1600-1699/1610-1619/1614/problemE.txt this is a correct solution, but verifier at 1000-1999/1600-1699/1610-1619/1614/verifierE.go ends with All tests passed can you fix the verifier? package main
import (
"io"
"os"
"strconv"
)
const MAXY int64 = 1000000000
const MOD int64 = MAXY + 1
const MAXNODES = 2500005
var leftChild []int
var rightChild []int
var L []int64
var R []int64
var W []int64
var SUM []int64
var ADD []int64
var PRI []uint32
var nodes int
var seed uint32 = 2463534242
func rnd() uint32 {
seed ^= seed << 13
seed ^= seed >> 17
seed ^= seed << 5
return seed
}
func nodeSum(x int) int64 {
if x == 0 {
return 0
}
return SUM[x]
}
func newNode(l, r, w int64) int {
nodes++
i := nodes
L[i] = l
R[i] = r
W[i] = w
SUM[i] = (r - l + 1) * w
PRI[i] = rnd()
leftChild[i] = 0
rightChild[i] = 0
ADD[i] = 0
return i
}
func pull(i int) {
if i == 0 {
return
}
SUM[i] = nodeSum(leftChild[i]) + nodeSum(rightChild[i]) + (R[i]-L[i]+1)*W[i]
}
func apply(i int, d int64) {
if i == 0 {
return
}
L[i] += d
R[i] += d
ADD[i] += d
}
func push(i int) {
if i == 0 || ADD[i] == 0 {
return
}
d := ADD[i]
if leftChild[i] != 0 {
apply(leftChild[i], d)
}
if rightChild[i] != 0 {
apply(rightChild[i], d)
}
ADD[i] = 0
}
func merge(a, b int) int {
if a == 0 {
return b
}
if b == 0 {
return a
}
if PRI[a] < PRI[b] {
push(a)
rightChild[a] = merge(rightChild[a], b)
pull(a)
return a
}
push(b)
leftChild[b] = merge(a, leftChild[b])
pull(b)
return b
}
func split(root int, x int64) (int, int) {
if root == 0 {
return 0, 0
}
push(root)
if x < L[root] {
a, b := split(leftChild[root], x)
leftChild[root] = b
pull(root)
return a, root
}
if x >= R[root] {
a, b := split(rightChild[root], x)
rightChild[root] = a
pull(root)
return root, b
}
lseg := newNode(L[root], x, W[root])
rseg := newNode(x+1, R[root], W[root])
a := merge(leftChild[root], lseg)
b := merge(rseg, rightChild[root])
return a, b
}
func popRight(root int) (int, int) {
push(root)
if rightChild[root] == 0 {
rest := leftChild[root]
leftChild[root] = 0
pull(root)
return rest, root
}
rest, node := popRight(rightChild[root])
rightChild[root] = rest
pull(root)
return root, node
}
func popLeft(root int) (int, int) {
push(root)
if leftChild[root] == 0 {
rest := rightChild[root]
rightChild[root] = 0
pull(root)
return rest, root
}
rest, node := popLeft(leftChild[root])
leftChild[root] = rest
pull(root)
return root, node
}
func appendTree(a, b int) int {
if a == 0 {
return b
}
if b == 0 {
return a
}
var ra, lb int
a, ra = popRight(a)
b, lb = popLeft(b)
if W[ra] == W[lb] && R[ra]+1 == L[lb] {
R[ra] = R[lb]
pull(ra)
res := merge(a, ra)
res = merge(res, b)
return res
}
res := merge(a, ra)
res = merge(res, lb)
res = merge(res, b)
return res
}
func update(root int, t int64) int {
a, b := split(root, t-2)
c, d := split(b, t-1)
e, f := split(d, t)
g, h := split(f, t+1)
midW := nodeSum(c) + nodeSum(e) + nodeSum(g)
apply(a, 1)
apply(h, -1)
res := 0
if t > 0 {
res = appendTree(res, newNode(0, 0, 0))
}
res = appendTree(res, a)
res = appendTree(res, newNode(t, t, midW))
res = appendTree(res, h)
if t < MAXY {
res = appendTree(res, newNode(MAXY, MAXY, 0))
}
return res
}
func kth(root int, k int64) int64 {
cur := root
for {
push(cur)
ls := nodeSum(leftChild[cur])
if k < ls {
cur = leftChild[cur]
continue
}
k -= ls
if W[cur] != 0 {
length := R[cur] - L[cur] + 1
mass := length * W[cur]
if k < mass {
return L[cur] + k/W[cur]
}
k -= mass
}
cur = rightChild[cur]
}
}
var data []byte
var ptr int
func nextInt() int64 {
for ptr < len(data) && (data[ptr] < '0' || data[ptr] > '9') {
ptr++
}
var v int64
for ptr < len(data) && data[ptr] >= '0' && data[ptr] <= '9' {
v = v*10 + int64(data[ptr]-'0')
ptr++
}
return v
}
func main() {
data, _ = io.ReadAll(os.Stdin)
leftChild = make([]int, MAXNODES)
rightChild = make([]int, MAXNODES)
L = make([]int64, MAXNODES)
R = make([]int64, MAXNODES)
W = make([]int64, MAXNODES)
SUM = make([]int64, MAXNODES)
ADD = make([]int64, MAXNODES)
PRI = make([]uint32, MAXNODES)
root := newNode(0, MAXY, 1)
n := int(nextInt())
lastans := int64(0)
out := make([]byte, 0, 1<<20)
for i := 0; i < n; i++ {
t := nextInt()
root = update(root, t)
k := int(nextInt())
for j := 0; j < k; j++ {
xp := nextInt()
x := xp + lastans
if x >= MOD {
x -= MOD
}
ans := kth(root, x)
lastans = ans
out = strconv.AppendInt(out, ans, 10)
out = append(out, '\n')
}
}
os.Stdout.Write(out)
}