← Home
For problem statement at 0-999/600-699/650-659/652/problemC.txt this is a correct solution, but verifier at 0-999/600-699/650-659/652/verifierC.go ends with All tests passed! can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
)

var rd = bufio.NewReaderSize(os.Stdin, 1<<20)

func nextInt() int {
	sign, val := 1, 0
	c, _ := rd.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = rd.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = rd.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int(c-'0')
		c, _ = rd.ReadByte()
	}
	return sign * val
}

func main() {
	n := nextInt()
	m := nextInt()
	pos := make([]int, n+1)
	for i := 1; i <= n; i++ {
		v := nextInt()
		pos[v] = i
	}
	best := make([]int, n+2)
	inf := n + 1
	for i := 1; i <= n+1; i++ {
		best[i] = inf
	}
	for i := 0; i < m; i++ {
		a := nextInt()
		b := nextInt()
		ia := pos[a]
		ib := pos[b]
		if ia > ib {
			ia, ib = ib, ia
		}
		if ia >= 1 && ib <= n && ib < best[ia] {
			best[ia] = ib
		}
	}
	sufMin := inf
	var ans int64 = 0
	for i := n; i >= 1; i-- {
		if best[i] < sufMin {
			sufMin = best[i]
		}
		rlimit := n
		if sufMin != inf {
			rlimit = sufMin - 1
		}
		ans += int64(rlimit - i + 1)
	}
	w := bufio.NewWriterSize(os.Stdout, 1<<20)
	fmt.Fprintln(w, ans)
	w.Flush()
}