아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Hectic Harbour II

시간 제한4초메모리 제한1024 MB

요약
두 더미에서 추적 번호 1번부터 n번까지 순서대로 꺼내려고 크레인이 상자를 옮기는 과정을 시뮬레이션하면서, 표시 없는 내 상자가 꼭대기에 올라오는 횟수를 센다.
난이도

보통10점 중 7점

유형
시뮬레이션, 스택, 구현, 배열
정답자
아직 제출이 없습니다

문제

An upcycled shipping container makes a good site to open a pop-up store in a trendy part of town. Such a business comes with its own risks -- for example, this morning a local freight company mistook your premises for one of their crates and sent it to the shipyard for loading.

Your crate is now sitting in the shipyard in one of two stacks ready for loading onto the ship. Each crate except yours has its own tracking number.

Figure H.1: Illustration of Sample Input 2. Your business is in the unmarked crate.

The system for loading crates is automated and proceeds in a preset order. First, the crate with the next tracking number is uncovered by picking up all of the crates on top, one-by-one, and moving every single one across to the other stack individually. Then the crate is taken to the ship. Since your crate is not part of this order, it is generally ignored and will not be loaded.

After loading a crate, some time is spent securing the whole cargo on board. This is your chance to recover your container -- if it is on top of one of the stacks, you will have just enough time to slide it off and get it back.

How many such opportunities will you have in total?

입력

The input consists of:

  • One line with three integers nn, s_1s\_1 and s_2s\_2 (2≤s_1,s_2≤2⋅105,s_1+s_2=n+12 \leq s\_1, s\_2 \leq 2 \cdot 10^{5}, s\_1 + s\_2 = n + 1), the number of crates with a tracking number, the number of crates on the first stack, and the number of crates on the second stack respectively.
  • One line containing s_1s\_1 integers, the tracking numbers of the crates on the first stack, in order from bottom to top.
  • One line containing s_2s\_2 integers, the tracking numbers of the crates on the second stack, in order from bottom to top.

The crates with tracking number are numbered from 11 to nn and are removed from the stacks in that order. Your crate has tracking number 00 and will never be on top of one of the stacks initially.

출력

Output the number of occasions at which your crate is on top of one of the stacks and the crane is busy loading a crate.

예제2

  1. 예제 1

    입력
    4 3 2
    2 0 3
    1 4
    
    예상 출력
    3
    
  2. 예제 2

    입력
    6 4 3
    2 4 0 1
    6 3 5
    
    예상 출력
    4