type Residue struct { elems []int count int split int } func NewResidue(n int) *Residue { elems := make([]int, n+n) for i := 0; i < n; i++ { elems[0+i] = i elems[n+i] = i } return &Residue{ elems: elems, count: n, split: n, } } func (r *Residue) Slice() []int { return r.elems[:r.count] } func (r *Residue) Contains(x int) bool { return r.elems[r.split+x] < r.count } func (r *Residue) Remove(x int) bool { at := r.elems[r.split+x] if at >= r.count { return false } if r.count--; at < r.count { y := r.elems[r.count] r.elems[r.count] = x r.elems[at] = y r.elems[r.split+x] = r.count r.elems[r.split+y] = at } return true } func (r *Residue) Undo() bool { if r.count == r.split { return false } r.split++ return true }
To receive a hint, submit unfixed code.