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

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

Order-Preserving Partition

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

요약
순열을 네 개의 연속된 비어 있지 않은 구간으로 나눌 때, 각 구간의 값이 연속 정수가 되고 구간 최솟값의 순서가 주어진 순위 순열과 일치하는 분할의 수를 센다.
난이도

보통10점 중 7점

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

문제

Bobo has two permutations: P=p_1,p_2,…,p_nP = \\{p\_1, p\_2, \ldots, p\_n\\} and Q=q_1,q_2,q_3,q_4Q = \\{q\_1, q\_2, q\_3, q\_4\\}. He would like to partition PP into four non-empty and contiguous parts in such a manner that:

  • The numbers in each part can be rearranged to form an interval of values: an increasing sequence where each element is greater than the previous by exactly one.
  • For all 1≤i<j≤41 \leq i < j \leq 4, (s_i−s_j)⋅(q_i−q_j)>0(s\_i - s\_j) \cdot (q\_i - q\_j) > 0 where s_is\_i is the minimum value in the ii-th part.

Bobo wants to know the number of such partitions. As the number may be very large, you just need to print the answer modulo (109+7)(10^9 + 7).

입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains an integer nn, the length of the first permutation (4≤n≤106)(4 \leq n \leq 10^6).

The second line contains nn integers p_1,p_2,…,p_np\_1, p\_2, \dots, p\_n.

The third line contains four integers q_1,q_2,q_3,q_4q\_1, q\_2, q\_3, q\_4.

It is guaranteed that the sum of all nn does not exceed 10610^6.

출력

For each test case, output an integer denoting the answer.

예제1

  1. 예제 1

    입력
    10
    2 1 4 3 10 9 8 7 5 6
    2 4 1 3
    10
    1 2 3 4 5 6 7 8 9 10
    1 2 3 4
    
    예상 출력
    0
    84