For problem statement at 1000-1999/1400-1499/1410-1419/1418/problemG.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1410-1419/1418/verifierG.go ends with case 2: runtime error: exit status 2
panic: runtime error: index out of range [3] with length 3
goroutine 1 [running]:
main.main()
/tmp/build-2253525526/solution.go:51 +0x5e0
input:
2
3 1
exit status 1 can you fix the verifier? package main
import (
"io"
"os"
"strconv"
)
type Key struct {
a uint64
b uint64
}
func mix(x uint64) uint64 {
x += 0x9e3779b97f4a7c15
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
x = (x ^ (x >> 27)) * 0x94d049bb133111eb
return x ^ (x >> 31)
}
func nextInt(data []byte, idx *int) int {
n := len(data)
for *idx < n && (data[*idx] < '0' || data[*idx] > '9') {
*idx = *idx + 1
}
v := 0
for *idx < n && data[*idx] >= '0' && data[*idx] <= '9' {
v = v*10 + int(data[*idx]-'0')
*idx = *idx + 1
}
return v
}
func main() {
data, _ := io.ReadAll(os.Stdin)
pos := 0
n := nextInt(data, &pos)
a := make([]int, n+1)
p := make([]Key, n+1)
mod := make([]byte, n+1)
var h1, h2 uint64
const seed2 uint64 = 0x517cc1b727220a95
for i := 1; i <= n; i++ {
x := nextInt(data, &pos)
a[i] = x
r1 := mix(uint64(x))
r2 := mix(uint64(x) + seed2)
switch mod[x] {
case 0:
h1 += r1
h2 += r2
mod[x] = 1
case 1:
h1 += r1
h2 += r2
mod[x] = 2
default:
h1 -= r1 + r1
h2 -= r2 + r2
mod[x] = 0
}
p[i] = Key{h1, h2}
}
cnt := make([]int, n+1)
active := make(map[Key]int, n+1)
l := 1
var ans int64
for r := 1; r <= n; r++ {
active[p[r-1]]++
x := a[r]
cnt[x]++
for cnt[x] > 3 {
active[p[l-1]]--
cnt[a[l]]--
l++
}
ans += int64(active[p[r]])
}
os.Stdout.Write([]byte(strconv.FormatInt(ans, 10)))
}