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 n tasks (1≤n≤2⋅105). Unfortunately, he doesn't know when he needs to complete the tasks.
Initially, the time is 0. Time travel will now happen according to the following rules:
-
For each k=1,2,…,n, Okabe will realize at time bk that he was supposed to complete the k-th task at time ak (ak<bk).
-
When he realizes this, if k-th task was already completed at time ak, Okabe keeps the usual flow of time. Otherwise, he time travels to time ak then immediately completes the task.
-
If Okabe time travels to time ak, all tasks completed after this time will become incomplete again. That is, for every j, if aj>ak, the j-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 ak only immediately after getting to time bk and learning that he was supposed to complete the k-th task at time ak. That is, even if Okabe already had to perform k-th task before, he wouldn't remember it before stumbling on the info about this task at time bk again.
Please refer to the notes for an example of time travelling.
There is a certain set s of tasks such that the first moment that all of the tasks in s 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+7. It can be proven that eventually all n tasks will be completed and so the answer always exists.
El Psy Kongroo。
Omkar 正在观看《命运石之门》(Steins;Gate)。
在《命运石之门》中,Okabe Rintarou 需要完成 n 个任务(1≤n≤2⋅105)。不幸的是,他并不知道自己应在何时完成这些任务。
初始时刻为 0。时间旅行将按以下规则发生:
-
对每个 k=1,2,…,n,Okabe 将于时刻 bk 意识到:他本应在时刻 ak 完成第 k 个任务(其中 ak<bk)。
-
当他意识到这一点时,若第 k 个任务已在时刻 ak 完成,则 Okabe 维持时间的正常流动;否则,他将立即穿越至时刻 ak 并立刻完成该任务。
-
若 Okabe 穿越至时刻 ak,则所有在此之后完成的任务将再次变为未完成状态。即:对每个 j,若 aj>ak,则第 j 个任务若此前已完成,将变为未完成(若此前本就未完成,则保持不变)。
-
Okabe 记忆力很差,因此他仅能在抵达时刻 bk 并得知“第 k 个任务本应在时刻 ak 完成”这一信息后,立即穿越至时刻 ak。换言之,即使 Okabe 此前曾因其他原因执行过第 k 个任务,他也不会在时间 bk 再次获知该任务信息之前记起此事。
请参阅注释部分以了解时间旅行的具体示例。
存在一个特定的任务集合 s,当集合 s 中的所有任务首次同时处于已完成状态时(无论其余任务是否完成),便会触发一段搞笑场景。Omkar 非常喜爱这一场景,他想知道 Okabe 在该场景发生前总共会进行多少次时间旅行。请输出该次数对 109+7 取模的结果。可以证明:最终所有 n 个任务都会被完成,因此答案一定存在。
输入格式
The first line contains an integer n (1≤n≤2⋅105) — the number of tasks that Okabe needs to complete.
n lines follow. The k-th of these lines contain two integers ak and bk (1≤ak<bk≤2n) — the time at which Okabe needs to complete the k-th task and the time that he realizes this respectively. All 2n of these times are distinct (so every time from 1 to 2n inclusive appears exactly once in the input).
The next line contains a single integer t (1≤t≤n) — the size of the set s of tasks that lead to the funny scene.
The last line contains t integers s1,s2,…,st — (1≤sk≤n, the numbers s1,s2,…,st are distinct) — the set s of tasks.
第一行包含一个整数 n(1≤n≤2⋅105)—— Okabe 需要完成的任务数量。
接下来有 n 行。其中第 k 行包含两个整数 ak 和 bk(1≤ak<bk≤2n)—— 分别表示 Okabe 需要完成第 k 个任务的时间,以及他意识到该任务需求的时间。这 2n 个时间互不相同(即从 1 到 2n 的每个整数在输入中恰好出现一次)。
下一行包含一个整数 t(1≤t≤n)—— 导致搞笑场景的任务集合 s 的大小。
最后一行包含 t 个整数 s1,s2,…,st(1≤sk≤n,且 s1,s2,…,st 互不相同)—— 即任务集合 s。
输出格式
Output a single integer — the number of times that Okabe time travels until all tasks in the set s are simultaneously completed, modulo 109+7.
输出一个整数——Okabe 为使集合 s 中的所有任务同时完成所需进行的时间旅行次数,对 109+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 0. Nothing happens until time 3, when Okabe realizes that he should have done the 2-nd task at time 2. He then time travels to time 2 and completes the task.
As the task is done now, he does not time travel again when the time is again 3. However, at time 4, he travels to time 1 to complete the 1-st task.
This undoes the 2-nd task. This means that the 2-nd task is not currently completed, meaning that the funny scene will not occur at this point even though the 1-st task is currently completed and Okabe had previously completed the 2-nd task.
Once it is again time 3 he travels back to time 2 once more and does the 2-nd task again.
Now all tasks are complete, with Okabe having time travelled 3 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 2 times.
对于第一个样例,所有任务都必须完成,滑稽场景才会发生。
初始时刻为 0。直到时刻 3 之前,什么都不会发生;此时 Okabe 意识到他本应在时刻 2 完成第 2 个任务,于是他时间旅行回到时刻 2 并完成该任务。
由于该任务现已完成,因此当时间再次到达 3 时,他不再进行时间旅行。然而,在时刻 4,他旅行回到时刻 1 以完成第 1 个任务。
这会撤销第 2 个任务的完成状态。这意味着第 2 个任务当前并未完成,因此尽管第 1 个任务当前已完成、且 Okabe 此前曾完成过第 2 个任务,此时滑稽场景仍不会发生。
当时间再次到达 3 时,他再次回到时刻 2,重新完成第 2 个任务。
此时所有任务均已全部完成,Okabe 共进行了 3 次时间旅行。
第二个样例中,Okabe 需要完成的任务与第一个样例相同。但这一次,滑稽场景的发生仅需第 1 个任务完成即可。从上述样例的分析可知,这种情况会在 Okabe 进行 2 次时间旅行后发生。
输入解题思路,AI测评打分。不知道怎么写?