結果

問題 No.3746 Swap and LIS
コンテスト
ユーザー detteiuu
提出日時 2026-10-20 23:40:16
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 205 ms / 2,000 ms
+ 651µs
コード長 712 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 492 ms
コンパイル使用メモリ 64,680 KB
実行使用メモリ 102,876 KB
最終ジャッジ日時 2026-10-20 23:40:31
合計ジャッジ時間 7,630 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline
from bisect import bisect_left, bisect_right

for _ in range(int(input())):
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    C = []
    for i in range(N):
        C.append(max(A[i], B[i]))
        C.append(min(A[i], B[i]))

    stack = []
    stack2 = []
    for c in C:
        b = bisect_left(stack, c)
        if b < len(stack):
            n = stack[b]
            stack[b] = c
            b = bisect_left(stack2, n)
            if b < len(stack2):
                stack2[b] = n
            else:
                stack2.append(n)
        else:
            stack.append(c)

    print(len(stack)+len(stack2))
0