| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 31503 |
| 문제명 | DP (Large) |
| 레벨 | 플래티넘 5 |
| 분류 |
lis |
| 시간복잡도 | O(nlogn + q) |
| 인풋사이즈 | n<=300,000, q<=300,000 |
| 사용한 언어 | Python 3.13 |
| 제출기록 | 79224KB / 592ms |
| 최고기록 | 588ms |
| 해결날짜 | 2026/01/18 |
"""Solution code for "BOJ 31503. DP (Large)".
- Problem link: https://www.acmicpc.net/problem/31503
- Solution link: http://www.teferi.net/ps/problems/boj/31503
Tags: [lis]
"""
import sys
from teflib import seqtask
def main():
_N, Q = [int(x) for x in sys.stdin.readline().split()]
D = [int(x) for x in sys.stdin.readline().split()]
len_by_last = seqtask.longest_inc_subseq_length_by_last_elem(D)
len_by_first = seqtask.longest_inc_subseq_length_by_first_elem(D)
for _ in range(Q):
A = int(sys.stdin.readline()) - 1
print(len_by_last[A] + len_by_first[A] - 1)
if __name__ == '__main__':
main()