For problem statement at 1000-1999/1800-1899/1890-1899/1896/problemD.txt this is a correct solution, but verifier at 1000-1999/1800-1899/1890-1899/1896/verifierD.go ends with all tests passed can you fix the verifier? package main
import (
"bufio"
"bytes"
"io"
"os"
)
type Fenwick struct {
n int
pw int
bit []int
}
func NewFenwick(n int) *Fenwick {
pw := 1
for pw < n {
pw <<= 1
}
return &Fenwick{
n: n,
pw: pw,
bit: make([]int, n+1),
}
}
func (f *Fenwick) Add(i, delta int) {
for i <= f.n {
f.bit[i] += delta
i += i & -i
}
}
func (f *Fenwick) LowerBound(target int) int {
idx := 0
step := f.pw
for step > 0 {
next := idx + step
if next <= f.n && f.bit[next] < target {
idx = next
target -= f.bit[next]
}
step >>= 1
}
return idx + 1
}
func main() {
data, _ := io.ReadAll(os.Stdin)
pos := 0
nextInt := func() int {
for pos < len(data) && (data[pos] < '0' || data[pos] > '9') && data[pos] != '-' {
pos++
}
sign := 1
if data[pos] == '-' {
sign = -1
pos++
}
val := 0
for pos < len(data) && data[pos] >= '0' && data[pos] <= '9' {
val = val*10 + int(data[pos]-'0')
pos++
}
return sign * val
}
t := nextInt()
var out bytes.Buffer
for ; t > 0; t-- {
n := nextInt()
q := nextInt()
a := make([]int, n+1)
ft := NewFenwick(n)
sum := 0
ones := 0
for i := 1; i <= n; i++ {
v := nextInt()
a[i] = v
sum += v
if v == 1 {
ft.Add(i, 1)
ones++
}
}
for ; q > 0; q-- {
op := nextInt()
if op == 1 {
s := nextInt()
if s > sum {
out.WriteString("NO\n")
} else if ((sum-s)&1) == 0 {
out.WriteString("YES\n")
} else if ones == 0 {
out.WriteString("NO\n")
} else {
first := ft.LowerBound(1)
last := ft.LowerBound(ones)
needLeft := 2*first - 1
needRight := 2*(n-last) + 1
need := needLeft
if needRight < need {
need = needRight
}
if sum-s >= need {
out.WriteString("YES\n")
} else {
out.WriteString("NO\n")
}
}
} else {
i := nextInt()
v := nextInt()
if a[i] != v {
if a[i] == 1 {
ft.Add(i, -1)
ones--
sum++
} else {
ft.Add(i, 1)
ones++
sum--
}
a[i] = v
}
}
}
}
w := bufio.NewWriterSize(os.Stdout, 1<<20)
w.Write(out.Bytes())
w.Flush()
}