結果

問題 No.1804 Intersection of LIS
ユーザー chineristACchineristAC
提出日時 2022-01-07 23:12:09
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 617 ms / 2,000 ms
コード長 2,497 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 170,988 KB
最終ジャッジ日時 2023-08-09 03:40:39
合計ジャッジ時間 15,419 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
74,444 KB
testcase_01 AC 111 ms
74,320 KB
testcase_02 AC 109 ms
74,272 KB
testcase_03 AC 614 ms
142,312 KB
testcase_04 AC 523 ms
142,020 KB
testcase_05 AC 527 ms
142,240 KB
testcase_06 AC 514 ms
142,276 KB
testcase_07 AC 596 ms
142,396 KB
testcase_08 AC 507 ms
142,060 KB
testcase_09 AC 517 ms
142,128 KB
testcase_10 AC 523 ms
142,144 KB
testcase_11 AC 527 ms
142,232 KB
testcase_12 AC 529 ms
142,108 KB
testcase_13 AC 526 ms
142,036 KB
testcase_14 AC 524 ms
142,064 KB
testcase_15 AC 520 ms
142,216 KB
testcase_16 AC 522 ms
142,156 KB
testcase_17 AC 518 ms
142,140 KB
testcase_18 AC 147 ms
82,176 KB
testcase_19 AC 144 ms
81,708 KB
testcase_20 AC 143 ms
81,936 KB
testcase_21 AC 142 ms
82,108 KB
testcase_22 AC 145 ms
81,780 KB
testcase_23 AC 147 ms
81,856 KB
testcase_24 AC 145 ms
81,980 KB
testcase_25 AC 144 ms
82,092 KB
testcase_26 AC 146 ms
82,160 KB
testcase_27 AC 142 ms
82,136 KB
testcase_28 AC 110 ms
74,216 KB
testcase_29 AC 113 ms
74,448 KB
testcase_30 AC 113 ms
74,508 KB
testcase_31 AC 110 ms
74,404 KB
testcase_32 AC 111 ms
74,516 KB
testcase_33 AC 109 ms
74,364 KB
testcase_34 AC 110 ms
74,424 KB
testcase_35 AC 611 ms
170,980 KB
testcase_36 AC 617 ms
170,988 KB
testcase_37 AC 393 ms
137,580 KB
testcase_38 AC 393 ms
137,416 KB
testcase_39 AC 113 ms
74,128 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