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

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

Figurines

시간 제한3초메모리 제한512 MB

요약
N일 동안의 피규어 추가와 제거 기록, 그리고 날짜 순서 d가 주어질 때 매번 조건을 만족하는 개수를 세어 최종 x_N을 구한다.
난이도

보통10점 중 7점

유형
배열, 정렬, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Bob has a lot of mini figurines. He likes to display some of them on a shelf above his computer screen and he likes to regularly change which figurines appear. This ever-changing decoration is really enjoyable. Bob takes care of never adding the same mini figurine more than once. Bob has only NN mini figurines and after NN days he arrives at the point where each of the NN figurines have been added and then removed from the shelf (which is thus empty).

Bob has a very good memory. He is able to remember which mini figurines were displayed on each of the past days. So Bob wants to run a little mental exercise to test its memory and computation ability. For this purpose, Bob numbers his figurines with the numbers 0,…,N−10, \dots, N-1 and selects a sequence of NN integers d_0…d_N−1d\_0 \dots d\_{N-1} all in the range \[0;N]\[0;N]. Then, Bob computes a sequence x_0,…,x_Nx\_0,\dots, x\_N in the following way: x_0=0x\_0=0 and x_i+1=(x_i+y_i)\mboxmodNx\_{i+1}=(x\_i+y\_i)\mbox{ mod } N where \mboxmod\mbox{mod} is the modulo operation and y_iy\_i is the number of figurines displayed on day d_id\_i that have a number higher or equal to x_ix\_i.  The result of Bob's computation is x_Nx\_N.

More formally, if we note S(i)S(i) the subset of 0,…,N−1\\{0,\dots,N-1\\} corresponding to figurines displayed on the shelf on day ii, we have:

  • S(0)S(0) is the empty set;
  • S(i)S(i) is obtained from S(i−1)S(i-1) by inserting and removing some elements.

Each element 0≤j<N0 \le j < N is inserted and removed exactly once and thus, the last set S(N)S(N) is also the empty set.  The computation that Bob performs corresponds to the following program:

x_0←0x\_0 \leftarrow 0
for i∈\[0;N−1]i\in \[0;N-1]
    x\_{i+1} \leftarrow (x\_i + \\#\\{y \in S(d\_i) \text{ such that } y \ge x\_i\\}) \mod N
output x_Nx\_N

Bob asks you to verify his computation. For that he gives you the numbers he used during its computation (the d_0,…,d_N−1d\_0, \dots, d\_{N-1}) as well as the log of which figurines he added or removed every day. Note that a mini figurine added on day ii and removed on day jj is present on a day kk when i≤k<ji\leq k < j. You should tell him the number that you found at the end of the computation.

입력

The input is composed of 2N+12N+1 lines.

  • The first line contains the integer NN.
  • Lines 22 to N+1N+1 describe the figurines added and removed. Line i+1i+1 contains space-separated +jj or -jj, with 0≤j<N0 \le j < N, to indicate that jj is added or removed on day ii. This line may be empty. A line may contain both +jj and -jj, in that order.
  • Lines N+2N+2 to 2N+12N+1 describe the sequence d_0,…,d_N−1d\_0,\dots, d\_{N-1}. Line N+2+iN+2+i contains the integer d_id\_i with 0≤d_i≤N0 \le d\_i \le N.

출력

The output should contain a single line with a single integer which is x_Nx\_N.

제한

  • 1≤N≤100,0001 \le N \le 100\\,000

힌트

The output is 22 since

  • first, x←2x \leftarrow 2 since S(1)=0,2S(1) = \\{ 0, 2 \\} and \\#\\{y \in S(1)  \text{ such that } y \ge 0\\} = 2;
  • then, x←0x \leftarrow 0 since S(2)=1,2S(2) = \\{ 1, 2 \\} and \\#\\{y \in S(2)  \text{ such that } y \ge 2\\} = 1;
  • and finally, x←2x \leftarrow 2 since S(2)=1,2S(2) = \\{ 1, 2 \\} and \\#\\{y \in  S(2) \text{ such that } y \ge 0\\} = 2.

예제1

  1. 예제 1

    입력
    3
    +0 +2
    -0 +1
    -1 -2
    1
    2
    2
    
    예상 출력
    2