結果
問題 | No.984 Inversion |
ユーザー | aru aru |
提出日時 | 2020-11-02 15:54:16 |
言語 | Go (1.22.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,860 bytes |
コンパイル時間 | 13,441 ms |
コンパイル使用メモリ | 219,480 KB |
実行使用メモリ | 810,736 KB |
最終ジャッジ日時 | 2024-07-22 06:19:04 |
合計ジャッジ時間 | 15,713 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | MLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
package mainimport ("bufio""fmt""os""sort""strconv")var sc = bufio.NewScanner(os.Stdin)var wr = bufio.NewWriter(os.Stdout)func out(x ...interface{}) {fmt.Fprintln(wr, x...)}func getI() int {sc.Scan()i, e := strconv.Atoi(sc.Text())if e != nil {panic(e)}return i}func getF() float64 {sc.Scan()i, e := strconv.ParseFloat(sc.Text(), 64)if e != nil {panic(e)}return i}func getInts(N int) []int {ret := make([]int, N)for i := 0; i < N; i++ {ret[i] = getI()}return ret}func getS() string {sc.Scan()return sc.Text()}// min, max, asub, absなど基本関数func max(a, b int) int {if a > b {return a}return b}func min(a, b int) int {if a < b {return a}return b}func asub(a, b int) int {if a > b {return a - b}return b - a}func abs(a int) int {if a >= 0 {return a}return -a}func lowerBound(a []int, x int) int {idx := sort.Search(len(a), func(i int) bool {return a[i] >= x})return idx}func upperBound(a []int, x int) int {idx := sort.Search(len(a), func(i int) bool {return a[i] > x})return idx}func main() {defer wr.Flush()sc.Split(bufio.ScanWords)sc.Buffer([]byte{}, 1000000)// this template is new version.// use getI(), getS(), getInts(), getF()P, N := getI(), getI()a := make([]int, 0)for i := 1; i < P; i++ {a = append(a, N*i%P)}var e = func() int { return 0 }var merger = func(a, b int) int {return a + b}b := make([]int, P)for i := 1; i < P; i++ {b[i] = 1}seg := newSegtree(b, e, merger)cnt := 0for _, e := range a {seg.Set(e, 0)cnt += seg.Prod(0, e)}out(cnt % 2)}type E func() inttype Merger func(a, b int) inttype Compare func(v int) booltype Segtree struct {n intsize intlog intd []inte Emerger Merger}func newSegtree(v []int, e E, m Merger) *Segtree {seg := new(Segtree)seg.n = len(v)seg.log = seg.ceilPow2(seg.n)seg.size = 1 << uint(seg.log)seg.d = make([]int, 2*seg.size)seg.e = eseg.merger = mfor i, _ := range seg.d {seg.d[i] = seg.e()}for i := 0; i < seg.n; i++ {seg.d[seg.size+i] = v[i]}for i := seg.size - 1; i >= 1; i-- {seg.Update(i)}return seg}func (seg *Segtree) Update(k int) {seg.d[k] = seg.merger(seg.d[2*k], seg.d[2*k+1])}func (seg *Segtree) Set(p, x int) {p += seg.sizeseg.d[p] = xfor i := 1; i <= seg.log; i++ {seg.Update(p >> uint(i))}}func (seg *Segtree) Get(p int) int {return seg.d[p+seg.size]}func (seg *Segtree) Prod(l, r int) int {sml, smr := seg.e(), seg.e()l += seg.sizer += seg.sizefor l < r {if (l & 1) == 1 {sml = seg.merger(sml, seg.d[l])l++}if (r & 1) == 1 {r--smr = seg.merger(seg.d[r], smr)}l >>= 1r >>= 1}return seg.merger(sml, smr)}func (seg *Segtree) AllProd() int {return seg.d[1]}func (seg *Segtree) MaxRight(l int, cmp Compare) int {if l == seg.n {return seg.n}l += seg.sizesm := seg.e()for {for l%2 == 0 {l >>= 1}if !cmp(seg.merger(sm, seg.d[l])) {for l < seg.size {l = 2 * lif cmp(seg.merger(sm, seg.d[l])) {sm = seg.merger(sm, seg.d[l])l++}}return l - seg.size}sm = seg.merger(sm, seg.d[l])l++if l&-l == l {break}}return seg.n}func (seg *Segtree) MinLeft(r int, cmp Compare) int {if r == 0 {return 0}r += seg.sizesm := seg.e()for {r--for r > 1 && r%2 != 0 {r >>= 1}if !cmp(seg.merger(seg.d[r], sm)) {for r < seg.size {r = 2*r + 1if cmp(seg.merger(seg.d[r], sm)) {sm = seg.merger(seg.d[r], sm)r--}}return r + 1 - seg.size}sm = seg.merger(seg.d[r], sm)if r&-r == r {break}}return 0}func (seg *Segtree) ceilPow2(n int) int {x := 0for (1 << uint(x)) < n {x++}return x}