CF1583G.Omkar and Time Travel

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

El Psy Kongroo.

Omkar is watching Steins;Gate.

In Steins;Gate, Okabe Rintarou needs to complete nn tasks ( 1n21051 \leq n \leq 2 \cdot 10^5 ). Unfortunately, he doesn't know when he needs to complete the tasks.

Initially, the time is 00 . Time travel will now happen according to the following rules:

  • For each k=1,2,,nk = 1, 2, \ldots, n , Okabe will realize at time bkb_k that he was supposed to complete the kk -th task at time aka_k ( ak<bka_k < b_k ).
  • When he realizes this, if kk -th task was already completed at time aka_k , Okabe keeps the usual flow of time. Otherwise, he time travels to time aka_k then immediately completes the task.
  • If Okabe time travels to time aka_k , all tasks completed after this time will become incomplete again. That is, for every jj , if aj>aka_j>a_k , the jj -th task will become incomplete, if it was complete (if it was incomplete, nothing will change).
  • Okabe has bad memory, so he can time travel to time aka_k only immediately after getting to time bkb_k and learning that he was supposed to complete the kk -th task at time aka_k . That is, even if Okabe already had to perform kk -th task before, he wouldn't remember it before stumbling on the info about this task at time bkb_k again.

Please refer to the notes for an example of time travelling.

There is a certain set ss of tasks such that the first moment that all of the tasks in ss are simultaneously completed (regardless of whether any other tasks are currently completed), a funny scene will take place. Omkar loves this scene and wants to know how many times Okabe will time travel before this scene takes place. Find this number modulo 109+710^9 + 7 . It can be proven that eventually all nn tasks will be completed and so the answer always exists.

输入格式

The first line contains an integer nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the number of tasks that Okabe needs to complete.

nn lines follow. The kk -th of these lines contain two integers aka_k and bkb_k ( 1ak<bk2n1 \leq a_k < b_k \leq 2n ) — the time at which Okabe needs to complete the kk -th task and the time that he realizes this respectively. All 2n2n of these times are distinct (so every time from 11 to 2n2n inclusive appears exactly once in the input).

The next line contains a single integer tt ( 1tn1 \leq t \leq n ) — the size of the set ss of tasks that lead to the funny scene.

The last line contains tt integers s1,s2,,sts_1, s_2, \ldots, s_t — ( 1skn1 \leq s_k \leq n , the numbers s1,s2,,sts_1, s_2, \ldots, s_t are distinct) — the set ss of tasks.

输出格式

Output a single integer — the number of times that Okabe time travels until all tasks in the set ss are simultaneously completed, modulo 109+710^9 + 7 .

输入输出样例

  • 输入#1

    2
    1 4
    2 3
    2
    1 2

    输出#1

    3
  • 输入#2

    2
    1 4
    2 3
    1
    1

    输出#2

    2
  • 输入#3

    1
    1 2
    1
    1

    输出#3

    1
  • 输入#4

    6
    10 12
    3 7
    4 6
    2 9
    5 8
    1 11
    3
    2 4 6

    输出#4

    17
  • 输入#5

    16
    31 32
    3 26
    17 19
    4 24
    1 28
    15 21
    12 16
    18 29
    20 23
    7 8
    11 14
    9 22
    6 30
    5 10
    25 27
    2 13
    6
    3 8 2 5 12 11

    输出#5

    138

说明/提示

For the first sample, all tasks need to be completed in order for the funny scene to occur.

Initially, the time is 00 . Nothing happens until time 33 , when Okabe realizes that he should have done the 22 -nd task at time 22 . He then time travels to time 22 and completes the task.

As the task is done now, he does not time travel again when the time is again 33 . However, at time 44 , he travels to time 11 to complete the 11 -st task.

This undoes the 22 -nd task. This means that the 22 -nd task is not currently completed, meaning that the funny scene will not occur at this point even though the 11 -st task is currently completed and Okabe had previously completed the 22 -nd task.

Once it is again time 33 he travels back to time 22 once more and does the 22 -nd task again.

Now all tasks are complete, with Okabe having time travelled 33 times.

The second sample has the same tasks for Okabe to complete. However, this time the funny scene only needs the first task to be completed in order to occur. From reading the above sample you can see that this occurs once Okabe has time travelled 22 times.

首页