CF1583G.Omkar and Time Travel

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

El Psy Kongroo.

Omkar is watching Steins;Gate.

In Steins;Gate, Okabe Rintarou needs to complete nn tasks (1≤n≤2⋅1051 \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 \lt 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 \gt 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.

El Psy Kongroo。

Omkar 正在观看《命运石之门》(Steins;Gate)。

在《命运石之门》中,Okabe Rintarou 需要完成 nn 个任务(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)。不幸的是,他并不知道自己应在何时完成这些任务。

初始时刻为 00。时间旅行将按以下规则发生:

  • 对每个 k=1,2,…,nk = 1, 2, \ldots, n,Okabe 将于时刻 bkb_k 意识到:他本应在时刻 aka_k 完成第 kk 个任务(其中 ak<bka_k \lt b_k)。

  • 当他意识到这一点时,若第 kk 个任务已在时刻 aka_k 完成,则 Okabe 维持时间的正常流动;否则,他将立即穿越至时刻 aka_k 并立刻完成该任务。

  • 若 Okabe 穿越至时刻 aka_k,则所有在此之后完成的任务将再次变为未完成状态。即:对每个 jj,若 aj>aka_j \gt a_k,则第 jj 个任务若此前已完成,将变为未完成(若此前本就未完成,则保持不变)。

  • Okabe 记忆力很差,因此他仅能在抵达时刻 bkb_k 并得知“第 kk 个任务本应在时刻 aka_k 完成”这一信息后,立即穿越至时刻 aka_k。换言之,即使 Okabe 此前曾因其他原因执行过第 kk 个任务,他也不会在时间 bkb_k 再次获知该任务信息之前记起此事。

请参阅注释部分以了解时间旅行的具体示例。

存在一个特定的任务集合 ss,当集合 ss 中的所有任务首次同时处于已完成状态时(无论其余任务是否完成),便会触发一段搞笑场景。Omkar 非常喜爱这一场景,他想知道 Okabe 在该场景发生前总共会进行多少次时间旅行。请输出该次数对 109+710^9 + 7 取模的结果。可以证明:最终所有 nn 个任务都会被完成,因此答案一定存在。

输入格式

The first line contains an integer nn (1≤n≤2⋅1051 \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 (1≤ak<bk≤2n1 \leq a_k \lt 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 (1≤t≤n1 \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 — (1≤sk≤n1 \leq s_k \leq n, the numbers s1,s2,…,sts_1, s_2, \ldots, s_t are distinct) — the set ss of tasks.

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— Okabe 需要完成的任务数量。

接下来有 nn 行。其中第 kk 行包含两个整数 aka_k 和 bkb_k(1≤ak<bk≤2n1 \leq a_k \lt b_k \leq 2n)—— 分别表示 Okabe 需要完成第 kk 个任务的时间,以及他意识到该任务需求的时间。这 2n2n 个时间互不相同(即从 11 到 2n2n 的每个整数在输入中恰好出现一次)。

下一行包含一个整数 tt(1≤t≤n1 \leq t \leq n)—— 导致搞笑场景的任务集合 ss 的大小。

最后一行包含 tt 个整数 s1,s2,…,sts_1, s_2, \ldots, s_t(1≤sk≤n1 \leq s_k \leq n,且 s1,s2,…,sts_1, s_2, \ldots, s_t 互不相同)—— 即任务集合 ss。

输出格式

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.

输出一个整数——Okabe 为使集合 ss 中的所有任务同时完成所需进行的时间旅行次数,对 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.

对于第一个样例,所有任务都必须完成,滑稽场景才会发生。

初始时刻为 00。直到时刻 33 之前,什么都不会发生;此时 Okabe 意识到他本应在时刻 22 完成第 22 个任务,于是他时间旅行回到时刻 22 并完成该任务。

由于该任务现已完成,因此当时间再次到达 33 时,他不再进行时间旅行。然而,在时刻 44,他旅行回到时刻 11 以完成第 11 个任务。

这会撤销第 22 个任务的完成状态。这意味着第 22 个任务当前并未完成,因此尽管第 11 个任务当前已完成、且 Okabe 此前曾完成过第 22 个任务,此时滑稽场景仍不会发生。

当时间再次到达 33 时,他再次回到时刻 22,重新完成第 22 个任务。

此时所有任务均已全部完成,Okabe 共进行了 33 次时间旅行。

第二个样例中,Okabe 需要完成的任务与第一个样例相同。但这一次,滑稽场景的发生仅需第 11 个任务完成即可。从上述样例的分析可知,这种情况会在 Okabe 进行 22 次时间旅行后发生。

输入解题思路,AI测评打分。不知道怎么写?

首页