結果

問題 No.2210 equence Squence Seuence
ユーザー タコイモタコイモ
提出日時 2023-02-11 11:50:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,873 ms / 2,000 ms
コード長 3,343 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 129,756 KB
最終ジャッジ日時 2023-09-22 10:04:15
合計ジャッジ時間 19,819 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
72,676 KB
testcase_01 AC 104 ms
72,600 KB
testcase_02 AC 106 ms
72,480 KB
testcase_03 AC 484 ms
90,272 KB
testcase_04 AC 526 ms
92,184 KB
testcase_05 AC 729 ms
96,972 KB
testcase_06 AC 707 ms
95,516 KB
testcase_07 AC 1,522 ms
119,620 KB
testcase_08 AC 110 ms
72,392 KB
testcase_09 AC 116 ms
77,184 KB
testcase_10 AC 116 ms
77,088 KB
testcase_11 AC 114 ms
77,052 KB
testcase_12 AC 121 ms
77,164 KB
testcase_13 AC 1,838 ms
127,252 KB
testcase_14 AC 1,860 ms
129,756 KB
testcase_15 AC 1,848 ms
129,552 KB
testcase_16 AC 1,858 ms
128,228 KB
testcase_17 AC 1,873 ms
128,632 KB
testcase_18 AC 108 ms
72,644 KB
testcase_19 AC 106 ms
72,540 KB
testcase_20 AC 105 ms
72,352 KB
testcase_21 AC 107 ms
72,580 KB
testcase_22 AC 107 ms
72,512 KB
testcase_23 AC 625 ms
116,824 KB
testcase_24 AC 495 ms
106,000 KB
testcase_25 AC 571 ms
112,156 KB
testcase_26 AC 722 ms
124,048 KB
testcase_27 AC 297 ms
93,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

base = 37 #こっちはsr未満ならなんでもよい、modはいじれない
mod = 2305843009213693951 #2**61 - 1 制限時間に余裕があり衝突したらこっちを使う
ss = 2**31
sr = 2**30
def abm(a,b): #a*b mod m
  au = a // ss
  ad = a % ss
  bu = b // ss
  bd = b % ss
  mid = au*bd + ad*bu
  midu = mid // sr
  midd = mid % sr
  return (au*bu*2 + midu + midd*ss + ad*bd)%mod

  
class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        l = len(s)
        self.pw = pw = [1]*(l+1)
        self.h = h = [0]*(l+1)
        v = 0
        vv = 1
        for i in range(l):
            ad = v % ss
            au = v // ss
            mid = au*base
            midu = mid//sr
            midd = mid%sr
            #小文字のみ
            #h[i+1] = v = (midu+midd*ss+ad*base + ord(s[i])-96) % mod
            #大文字のみ or 大文字と小文字のみ
            #h[i+1] = v = (midu+midd*ss+ad*base + ord(s[i])-64) % mod
            #通常
            #h[i+1] = v = (midu+midd*ss+ad*base + ord(s[i])+1) % mod
            #自然数
            h[i+1] = v = (midu+midd*ss+ad*base + s[i]) % mod
            ad = vv % ss
            au = vv // ss
            mid = au*base
            midu = mid//sr
            midd = mid%sr
            pw[i+1] = vv = (midu+midd*ss+ad*base)% mod
    #[l,r)
    def get(self, l, r):
        return (self.h[r] - abm(self.h[l],self.pw[r-l])) % self.mod

  
import sys
#sys.setrecursionlimit(500000)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def TI(): return tuple(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip())
#for i, pi in enumerate(p):
from collections import defaultdict,deque
import bisect
import itertools
dic = defaultdict(int)
d = deque()

N,K = MI()
A = LI()
S = RollingHash(A,base,mod)
#https://aotamasaki.hatenablog.com/entry/meguru_bisect
#arg桁
def is_ok(arg,x,y):
  if arg == 0:
    return True
  if arg == N:
    return False
  if arg <= x and arg <= y:
    return True
  
  if arg <= x:
    X = S.get(0,arg)
  else:
    X = (abm(S.get(0,x),S.pw[arg-x])+S.get(x+1,arg+1))%mod
  if arg <= y:
    Y = S.get(0,arg)
  else:
    Y = (abm(S.get(0,y),S.pw[arg-y])+S.get(y+1,arg+1))%mod  
  
  if X == Y:
    return True
  else:
    return False
        
def meguru_bisect(ng, ok,s,t):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid,s,t):
            ok = mid
        else:
            ng = mid
    return ok
def cmp(x,y):
  h = meguru_bisect(N,0,x,y)
  
  if h == N-1:
    return 0
  
  if x > h:
    f = A[h]
  else:
    f = A[h+1]
  if y > h:
    ff = A[h]
  else:
    ff = A[h+1]
  if f < ff:
    return -1
  elif f == ff:
    return 0
  else:
    return 1
    
  
D = list(range(N))
from functools import cmp_to_key
p = sorted(D, key = cmp_to_key(cmp))
x = p[K - 1]

ans = A[:x] + A[x + 1:]

print(*ans)
0