結果

問題 No.1804 Intersection of LIS
ユーザー chineristACchineristAC
提出日時 2022-01-07 23:12:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 607 ms / 2,000 ms
コード長 2,497 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 168,088 KB
最終ジャッジ日時 2024-04-26 19:02:39
合計ジャッジ時間 12,799 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
55,936 KB
testcase_01 AC 51 ms
56,192 KB
testcase_02 AC 51 ms
56,192 KB
testcase_03 AC 586 ms
138,656 KB
testcase_04 AC 484 ms
138,636 KB
testcase_05 AC 482 ms
138,904 KB
testcase_06 AC 490 ms
138,768 KB
testcase_07 AC 575 ms
138,904 KB
testcase_08 AC 494 ms
138,388 KB
testcase_09 AC 492 ms
138,648 KB
testcase_10 AC 489 ms
138,772 KB
testcase_11 AC 483 ms
138,776 KB
testcase_12 AC 494 ms
138,772 KB
testcase_13 AC 489 ms
138,772 KB
testcase_14 AC 491 ms
138,892 KB
testcase_15 AC 480 ms
138,776 KB
testcase_16 AC 493 ms
138,520 KB
testcase_17 AC 498 ms
138,644 KB
testcase_18 AC 93 ms
77,824 KB
testcase_19 AC 98 ms
77,824 KB
testcase_20 AC 94 ms
77,696 KB
testcase_21 AC 97 ms
77,824 KB
testcase_22 AC 96 ms
77,696 KB
testcase_23 AC 96 ms
77,568 KB
testcase_24 AC 99 ms
77,696 KB
testcase_25 AC 95 ms
77,748 KB
testcase_26 AC 96 ms
77,764 KB
testcase_27 AC 94 ms
77,760 KB
testcase_28 AC 51 ms
56,192 KB
testcase_29 AC 51 ms
56,192 KB
testcase_30 AC 50 ms
56,320 KB
testcase_31 AC 52 ms
56,064 KB
testcase_32 AC 52 ms
56,320 KB
testcase_33 AC 51 ms
56,064 KB
testcase_34 AC 50 ms
56,064 KB
testcase_35 AC 607 ms
167,968 KB
testcase_36 AC 598 ms
168,088 KB
testcase_37 AC 353 ms
133,512 KB
testcase_38 AC 350 ms
133,264 KB
testcase_39 AC 49 ms
56,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import e, log,gcd

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        stack = [x]
        while self._parent[stack[-1]]!=stack[-1]:
            stack.append(self._parent[stack[-1]])
        for v in stack:
            self._parent[v] = stack[-1]
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

input = lambda :sys.stdin.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
P = li()

dp = [N+1 for i in range(N+1)]
dp[0] = 0
for i in range(N):
    idx = bisect.bisect_right(dp,P[i])
    dp[idx] = P[i]
L = -1
for i in range(N+1):
    if dp[i]!=N+1:
        L = i

back = [0 for i in range(N+1)]
back[0] = N+1

use_bisect = [-back[i] for i in range(N+1)]

update = [None for i in range(N)]

for i in range(N)[::-1]:
    idx = bisect.bisect_right(use_bisect,-P[i])

    pre,next = back[idx],P[i]
    update[i] = (idx,back[idx],P[i])
    back[idx] = P[i]
    use_bisect[idx] = -P[i]

dp = [N+1 for i in range(N+1)]
dp[0] = 0
cnt = 0
for i in range(L+1):
    if dp[i] < back[L-i]:
        cnt += 1 
    
res = []
for i in range(N):
    idx_dp = bisect.bisect_right(dp,P[i])
    idx_back,_from,_to = update[i]

    if 1:
        if dp[L-idx_back] < back[idx_back]:
            cnt -= 1
        back[idx_back] = _from
        if dp[L-idx_back] < back[idx_back]:
            cnt += 1
    
    #print(dp)
    #print(back)
    #print(cnt)
    #print()
    
    
    if cnt==0:
        res.append(P[i])
    
    if dp[idx_dp] < back[L-idx_dp]:
        cnt -= 1
    dp[idx_dp] = P[i]
    if dp[idx_dp] < back[L-idx_dp]:
        cnt += 1

print(len(res))
print(*res)




0