forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
461C.go
47 lines (43 loc) · 799 Bytes
/
461C.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bufio"
. "fmt"
"io"
)
// github.com/EndlessCheng/codeforces-go
func CF461C(_r io.Reader, _w io.Writer) {
in := bufio.NewReader(_r)
out := bufio.NewWriter(_w)
defer out.Flush()
var n, q, tp, l, r int
Fscan(in, &n, &q)
sum := make([]int, n+1)
for i := range sum {
sum[i] = i
}
for st, ed, rev := 0, n, false; q > 0; q-- {
if Fscan(in, &tp, &l); tp == 1 {
if l > ed-l {
l, rev = ed-l, !rev
}
if rev {
for i := ed - l; i < ed; i++ {
sum[st+(ed-l)*2-i] += n - sum[st+i]
}
} else {
st += l
for i := 0; i < l; i++ {
sum[st+i] -= sum[st-i]
}
}
ed -= l
} else {
Fscan(in, &r)
if rev {
l, r = ed-r, ed-l
}
Fprintln(out, sum[st+r]-sum[st+l])
}
}
}
//func main() { CF461C(os.Stdin, os.Stdout) }