← Home
For problem statement at 1000-1999/1400-1499/1480-1489/1485/problemB.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1480-1489/1485/verifierB.go ends with All tests passed can you fix the verifier? package main

import (
	"os"
)

func main() {
	in := os.Stdin
	out := os.Stdout

	var buf [1 << 20]byte
	var pos, length int
	nextByte := func() byte {
		if pos >= length {
			pos = 0
			length, _ = in.Read(buf[:])
			if length == 0 {
				return 0
			}
		}
		res := buf[pos]
		pos++
		return res
	}

	nextUint := func() int64 {
		var res int64
		b := nextByte()
		for b < '0' || b > '9' {
			if b == 0 {
				return 0
			}
			b = nextByte()
		}
		for '0' <= b && b <= '9' {
			res = res*10 + int64(b-'0')
			b = nextByte()
		}
		return res
	}

	n := nextUint()
	q := nextUint()
	k := nextUint()

	a := make([]int64, n+1)
	for i := int64(1); i <= n; i++ {
		a[i] = nextUint()
	}

	outBuf := make([]byte, 0, 1<<20)

	printInt := func(x int64) {
		if x < 0 {
			outBuf = append(outBuf, '-')
			x = -x
		}
		if x == 0 {
			outBuf = append(outBuf, '0', '\n')
			if len(outBuf) >= 1<<19 {
				out.Write(outBuf)
				outBuf = outBuf[:0]
			}
			return
		}
		var temp [20]byte
		idx := 19
		for x > 0 {
			temp[idx] = byte('0' + x%10)
			x /= 10
			idx--
		}
		outBuf = append(outBuf, temp[idx+1:]...)
		outBuf = append(outBuf, '\n')
		if len(outBuf) >= 1<<19 {
			out.Write(outBuf)
			outBuf = outBuf[:0]
		}
	}

	for i := int64(0); i < q; i++ {
		l := nextUint()
		r := nextUint()
		ans := a[r] - a[l] + k - 2*(r-l) - 1
		printInt(ans)
	}
	if len(outBuf) > 0 {
		out.Write(outBuf)
	}
}