結果

問題 No.2930 Larger Mex
ユーザー kemunikukemuniku
提出日時 2024-10-12 16:07:12
言語 Nim
(2.0.2)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 9,361 bytes
コンパイル時間 3,495 ms
コンパイル使用メモリ 75,804 KB
実行使用メモリ 18,240 KB
最終ジャッジ日時 2024-10-12 16:07:24
合計ジャッジ時間 8,645 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 3 ms
6,816 KB
testcase_05 AC 2 ms
6,820 KB
testcase_06 AC 2 ms
6,816 KB
testcase_07 AC 3 ms
6,816 KB
testcase_08 AC 47 ms
15,232 KB
testcase_09 AC 43 ms
14,352 KB
testcase_10 AC 47 ms
15,744 KB
testcase_11 AC 41 ms
13,440 KB
testcase_12 AC 53 ms
16,868 KB
testcase_13 AC 50 ms
16,344 KB
testcase_14 AC 54 ms
17,280 KB
testcase_15 AC 44 ms
15,340 KB
testcase_16 AC 40 ms
14,064 KB
testcase_17 AC 50 ms
18,240 KB
testcase_18 AC 41 ms
15,776 KB
testcase_19 AC 49 ms
16,336 KB
testcase_20 AC 50 ms
16,708 KB
testcase_21 AC 54 ms
16,768 KB
testcase_22 AC 53 ms
16,768 KB
testcase_23 AC 44 ms
14,492 KB
testcase_24 AC 47 ms
16,256 KB
testcase_25 AC 51 ms
17,152 KB
testcase_26 AC 43 ms
16,252 KB
testcase_27 AC 36 ms
13,568 KB
testcase_28 AC 38 ms
15,100 KB
testcase_29 AC 40 ms
14,976 KB
testcase_30 AC 42 ms
13,952 KB
testcase_31 AC 36 ms
12,544 KB
testcase_32 AC 44 ms
14,976 KB
testcase_33 AC 46 ms
14,848 KB
testcase_34 AC 50 ms
17,860 KB
testcase_35 AC 35 ms
11,392 KB
testcase_36 AC 48 ms
17,476 KB
testcase_37 AC 46 ms
15,488 KB
testcase_38 AC 47 ms
16,648 KB
testcase_39 AC 48 ms
16,128 KB
testcase_40 AC 46 ms
16,640 KB
testcase_41 AC 44 ms
14,824 KB
testcase_42 AC 42 ms
15,104 KB
testcase_43 AC 42 ms
14,592 KB
testcase_44 AC 43 ms
15,360 KB
testcase_45 AC 41 ms
15,176 KB
testcase_46 AC 23 ms
13,044 KB
testcase_47 AC 24 ms
13,012 KB
testcase_48 AC 17 ms
10,240 KB
testcase_49 AC 24 ms
13,568 KB
testcase_50 AC 51 ms
16,640 KB
testcase_51 AC 54 ms
16,716 KB
testcase_52 AC 54 ms
17,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import macros;macro ImportExpand(s:untyped):untyped = parseStmt($s[2])
ImportExpand "cplib/tmpl/sheep.nim" <=== "when not declared CPLIB_TMPL_SHEEP:\n const CPLIB_TMPL_SHEEP* = 1\n {.warning[UnusedImport]: off.}\n
     {.hint[XDeclaredButNotUsed]: off.}\n import algorithm\n import sequtils\n import tables\n import macros\n import math\n import
    sets\n import strutils\n import strformat\n import sugar\n import heapqueue\n import streams\n import deques\n import
    bitops\n import std/lenientops\n import options\n #\n proc scanf(formatstr: cstring){.header: \"<stdio.h>\", varargs.}\n proc
    getchar(): char {.importc: \"getchar_unlocked\", header: \"<stdio.h>\", discardable.}\n proc ii(): int {.inline.} = scanf(\"%lld\\n\", addr
    result)\n proc lii(N: int): seq[int] {.inline.} = newSeqWith(N, ii())\n proc si(): string {.inline.} =\n result = \"\"\n var c
    : char\n while true:\n c = getchar()\n if c == ' ' or c == '\\n':\n break\n result &= c\n
     #chmin,chmax\n template `max=`(x, y) = x = max(x, y)\n template `min=`(x, y) = x = min(x, y)\n #bit\n proc `%`*(x: int, y: int):
    int =\n result = x mod y\n if y > 0 and result < 0: result += y\n if y < 0 and result > 0: result += y\n proc `//`*(x: int
    , y: int): int{.inline.} =\n result = x div y\n if y > 0 and result * y > x: result -= 1\n if y < 0 and result * y < x:
    result -= 1\n proc `%=`(x: var int, y: int): void = x = x%y\n proc `//=`(x: var int, y: int): void = x = x//y\n proc `**`(x: int, y: int
    ): int = x^y\n proc `**=`(x: var int, y: int): void = x = x^y\n proc `^`(x: int, y: int): int = x xor y\n proc `|`(x: int, y: int): int =
    x or y\n proc `&`(x: int, y: int): int = x and y\n proc `>>`(x: int, y: int): int = x shr y\n proc `<<`(x: int, y: int): int = x shl y\n
     proc `~`(x: int): int = not x\n proc `^=`(x: var int, y: int): void = x = x ^ y\n proc `&=`(x: var int, y: int): void = x = x & y\n
    proc `|=`(x: var int, y: int): void = x = x | y\n proc `>>=`(x: var int, y: int): void = x = x >> y\n proc `<<=`(x: var int, y: int): void =
    x = x << y\n proc `[]`(x: int, n: int): bool = (x and (1 shl n)) != 0\n #便\n proc `!`(x: char, a = '0'): int = int(x)-int(a)\n
     #\n #[ include cplib/utils/constants ]#\n when not declared CPLIB_UTILS_CONSTANTS:\n const CPLIB_UTILS_CONSTANTS* = 1\n
    const INF32*: int32 = 100100111.int32\n const INF64*: int = int(3300300300300300491)\n const INF = INF64\n #converter\n\n #range\n
     iterator range(start: int, ends: int, step: int): int =\n var i = start\n if step < 0:\n while i > ends:\n
     yield i\n i += step\n elif step > 0:\n while i < ends:\n yield i\n i += step\n
     iterator range(ends: int): int = (for i in 0..<ends: yield i)\n iterator range(start: int, ends: int): int = (for i in\n start
    ..<ends: yield i)\n\n #joinstring\n proc join*[T: not string](a: openArray[T], sep: string = \"\"): string
    = a.mapit($it).join(sep)\n"
ImportExpand "cplib/collections/segtree.nim" <=== "when not declared CPLIB_COLLECTIONS_SEGTREE:\n const CPLIB_COLLECTIONS_SEGTREE* = 1\n import
    algorithm\n import strutils\n import sequtils\n type SegmentTree*[T] = ref object\n default: T\n merge: proc(x: T, y: T):
    T\n arr*: seq[T]\n lastnode: int\n length: int\n proc initSegmentTree*[T](v: seq[T], merge: proc(x: T, y: T): T, default:
    T): SegmentTree[T] =\n ## \n ##
    vmerge\n var lastnode = 1\n while lastnode < len
    (v):\n lastnode*=2\n var arr = newSeq[T](2*lastnode)\n arr.fill(default)\n var self = SegmentTree[T](default:
    default, merge: merge, arr: arr, lastnode: lastnode, length: len(v))\n #1-indexed\n for i in 0..<len(v):\n self
    .arr[self.lastnode+i] = v[i]\n for i in countdown(lastnode-1, 1):\n self.arr[i] = self.merge(self.arr[2*i], self.arr[2*i+1])\n
     return self\n proc initSegmentTree*[T](n: int, merge: proc(x: T, y: T): T, default: T): SegmentTree[T] =\n ##
    \n ##
    nmerge\n initSegmentTree(newSeqWith
    (n, default), merge, default)\n\n proc update*[T](self: SegmentTree[T], x: Natural, val: T) =\n ## xval\n
    assert x < self.length\n var x = x\n x += self.lastnode\n self.arr[x] = val\n while x > 1:\n x = x shr 1\n
     self.arr[x] = self.merge(self.arr[2*x], self.arr[2*x+1])\n proc get*[T](self: SegmentTree[T], q_left: Natural, q_right: Natural): T
    =\n ## [q_left,q_right)\n assert q_left <= q_right and 0 <= q_left and q_right <= self
    .length\n var q_left = q_left\n var q_right = q_right\n q_left += self.lastnode\n q_right += self.lastnode\n
    var (lres, rres) = (self.default, self.default)\n while q_left < q_right:\n if (q_left and 1) > 0:\n lres = self
    .merge(lres, self.arr[q_left])\n q_left += 1\n if (q_right and 1) > 0:\n q_right -= 1\n
    rres = self.merge(self.arr[q_right], rres)\n q_left = q_left shr 1\n q_right = q_right shr 1\n return self.merge(lres
    , rres)\n proc get*[T](self: SegmentTree[T], segment: HSlice[int, int]): T =\n assert segment.a <= segment.b + 1 and 0 <= segment.a and
    segment.b+1 <= self.length\n return self.get(segment.a, segment.b+1)\n proc `[]`*[T](self: SegmentTree[T], segment: HSlice[int, int]): T
    = self.get(segment)\n proc `[]`*[T](self: SegmentTree[T], index: Natural): T =\n assert index < self.length\n return self
    .arr[index+self.lastnode]\n proc `[]=`*[T](self: SegmentTree[T], index: Natural, val: T) =\n assert index < self.length\n self
    .update(index, val)\n proc get_all*[T](self: SegmentTree[T]): T =\n ## [0,len(self))O(1)\n return self
    .arr[1]\n proc len*[T](self: SegmentTree[T]): int =\n return self.length\n proc `$`*[T](self: SegmentTree[T]): string =\n var
    s = self.arr.len div 2\n return self.arr[s..<s+self.len].join(\" \")\n template newSegWith*(V, merge, default: untyped): untyped =\n
     initSegmentTree[typeof(default)](V, proc (l{.inject.}, r{.inject.}: typeof(default)): typeof(default) = merge, default)\n proc max_right
    *[T](self: SegmentTree[T], l: int, f: proc(l: T): bool): int =\n assert 0 <= l and l <= self.len\n assert f(self.default)\n
    if l == self.len: return self.len\n var l = l\n l += self.lastnode\n var sm = self.default\n while true:\n
    while l mod 2 == 0: l = (l shr 1)\n if not f(self.merge(sm, self.arr[l])):\n while l < self.lastnode:\n
     l *= 2\n if f(self.merge(sm, self.arr[l])):\n sm = self.merge(sm, self.arr[l])\n
     l += 1\n return l - self.lastnode\n sm = self.merge(sm, self.arr[l])\n l += 1\n if (l and -l)
    == l: break\n return self.len\n proc min_left*[T](self: SegmentTree[T], r: int, f: proc(l: T): bool): int =\n assert 0 <= r and r
    <= self.len\n assert f(self.default)\n if r == 0: return 0\n var r = r\n r += self.lastnode\n var sm = self
    .default\n while true:\n r -= 1\n while (r > 1 and r mod 2 != 0): r = (r shr 1)\n if not f(self.merge(self
    .arr[r], sm)):\n while r < self.lastnode:\n r = 2 * r + 1\n if f(self.merge(self.arr[r], sm
    )):\n sm = self.merge(self.arr[r], sm)\n r -= 1\n return r + 1 - self.lastnode\n
     if (r and -r) == r: break\n return 0\n"
var N,M = ii()
if M == 0:
echo (1..N).toseq().reversed().join("\n")
quit()
var A = lii(N)
#l
#rmexM
#
#
var now = 0
var cnt = newSeqWith(M,0)
var imos = newseqwith(N+1,0)
var r = 0
for l in range(N):
while r != N and now != M:
if A[r] < M:
cnt[A[r]] += 1
if cnt[A[r]] == 1:
now += 1
r += 1
if now == M:
imos[r-l-1] += 1
imos[N-l] -= 1
if A[l] < M:
cnt[A[l]] -= 1
if cnt[A[l]] == 0:
now -= 1
echo imos.cumsummed()[0..<N].join("\n")
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0