- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 59 lines of Go from the credited upstream file 1168C.go.
- The implementation visibly relies on sequence storage.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1package main2 3import (4 "bufio"5 . "fmt"6 "io"7 "math/bits"8)9 1011func CF1168C(_r io.Reader, _w io.Writer) {12 in := bufio.NewReader(_r)13 out := bufio.NewWriter(_w)14 defer out.Flush()15 max := func(a, b int) int {16 if a > b {17 return a18 }19 return b20 }21 const mx = 1922 23 var n, q, l, r int24 Fscan(in, &n, &q)25 a := make([]uint, n+1)26 left := make([][mx]int, n+1) 27 curLeft := [mx]int{}28 for i := 1; i <= n; i++ {29 Fscan(in, &a[i])30 v := a[i]31 for j := 0; j < mx; j++ {32 if v>>j&1 > 0 {33 left[i][j] = i34 } else {35 for s := v; s > 0; s &= s - 1 {36 left[i][j] = max(left[i][j], left[curLeft[bits.TrailingZeros(s)]][j])37 }38 }39 }40 for ; v > 0; v &= v - 1 {41 curLeft[bits.TrailingZeros(v)] = i42 }43 }44 45o:46 for ; q > 0; q-- {47 Fscan(in, &l, &r)48 for s := a[l]; s > 0; s &= s - 1 {49 if left[r][bits.TrailingZeros(s)] >= l {50 Fprintln(out, "Shi")51 continue o52 }53 }54 Fprintln(out, "Fou")55 }56}57 5859