← Home
For problem statement at 0-999/500-599/580-589/581/problemE.txt this is a correct solution, but verifier at 0-999/500-599/580-589/581/verifierE.go ends with Test 41 failed
Input:301 56 5 4
1 248
2 120
3 270
3 24
1 29
201 181 -30 -190
Expected:53 0
-1 -1
-1 -1
-1 -1
Got:13 0
-1 -1
-1 -1
-1 -1

exit status 1 can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func query_pref(X int64, l, r, pref []int64) int64 {
	if len(l) == 0 {
		return 0
	}
	idx := sort.Search(len(r), func(i int) bool {
		return r[i] > X
	})

	var res int64 = 0
	if idx > 0 {
		res = pref[idx-1]
	}
	if idx < len(l) {
		overlap := X - l[idx]
		if overlap > 0 {
			res += overlap
		}
	}
	return res
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const maxCapacity = 1024 * 1024 * 8
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)

	nextInt := func() int64 {
		scanner.Scan()
		val, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		return val
	}

	if !scanner.Scan() {
		return
	}
	e, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	s := nextInt()
	n := int(nextInt())
	m := int(nextInt())

	type Station struct {
		typ int
		pos int64
	}
	var stations []Station
	for i := 0; i < n; i++ {
		typ := int(nextInt())
		pos := nextInt()
		if pos < e {
			stations = append(stations, Station{typ, pos})
		}
	}

	type Event struct {
		pos int64
		typ int
		val int
	}
	var events []Event
	for _, st := range stations {
		events = append(events, Event{st.pos, st.typ, 1})
		events = append(events, Event{st.pos + s, st.typ, -1})
	}
	sort.Slice(events, func(i, j int) bool {
		return events[i].pos < events[j].pos
	})

	var l1, r1, pref1 []int64
	var l2, r2, pref2 []int64

	count := make([]int, 4)
	if len(events) > 0 {
		prev_pos := events[0].pos
		for i := 0; i < len(events); {
			curr_pos := events[i].pos

			if curr_pos > prev_pos {
				winning := 0
				if count[3] > 0 {
					winning = 3
				} else if count[2] > 0 {
					winning = 2
				} else if count[1] > 0 {
					winning = 1
				}

				if winning == 1 {
					if len(l1) > 0 && r1[len(r1)-1] == prev_pos {
						r1[len(r1)-1] = curr_pos
					} else {
						l1 = append(l1, prev_pos)
						r1 = append(r1, curr_pos)
					}
				} else if winning == 2 {
					if len(l2) > 0 && r2[len(r2)-1] == prev_pos {
						r2[len(r2)-1] = curr_pos
					} else {
						l2 = append(l2, prev_pos)
						r2 = append(r2, curr_pos)
					}
				}
			}

			for i < len(events) && events[i].pos == curr_pos {
				count[events[i].typ] += events[i].val
				i++
			}
			prev_pos = curr_pos
		}
	}

	pref1 = make([]int64, len(l1))
	var cur int64 = 0
	for i := 0; i < len(l1); i++ {
		cur += r1[i] - l1[i]
		pref1[i] = cur
	}

	pref2 = make([]int64, len(l2))
	cur = 0
	for i := 0; i < len(l2); i++ {
		cur += r2[i] - l2[i]
		pref2[i] = cur
	}

	var P []int64
	for _, st := range stations {
		P = append(P, st.pos)
	}
	sort.Slice(P, func(i, j int) bool {
		return P[i] < P[j]
	})
	P = append(P, e)

	k := len(P) - 1
	B := -1
	for j := 0; j < k; j++ {
		if P[j+1]-P[j] > s {
			B = j
		}
	}

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	for i := 0; i < m; i++ {
		f := nextInt()

		m_idx := sort.Search(len(P), func(idx int) bool {
			return P[idx] > f
		})

		possible := true
		if m_idx < len(P) {
			if P[m_idx]-f > s {
				possible = false
			} else if B >= m_idx {
				possible = false
			}
		} else {
			if e-f > s {
				possible = false
			}
		}

		if !possible {
			fmt.Fprint(writer, "-1 -1\n")
		} else {
			L := f + s
			R := e
			var ans1, ans2 int64 = 0, 0
			if L < R {
				ans1 = query_pref(R, l1, r1, pref1) - query_pref(L, l1, r1, pref1)
				ans2 = query_pref(R, l2, r2, pref2) - query_pref(L, l2, r2, pref2)
			}
			fmt.Fprintf(writer, "%d %d\n", ans1, ans2)
		}
	}
}
```