luogu#P5385. [Cnoi2019] 须臾幻境
[Cnoi2019] 须臾幻境
Background
There used to be a sad and touching story here, but the problem setter deleted the file and it was lost.
Problem Description
Initially, you are given an undirected graph with vertices and edges. The vertices are numbered .
Now, number all edges in in order and arrange them into an edge sequence of length : , where is an ordered pair representing an undirected edge connecting and .
Then Cirno will give you query pairs , asking: “If we only keep the edges in this interval, what is the number of connected components in the graph?”
Time is tight. You need to design an algorithm as fast as possible to answer Cirno’s queries. Also, since in some cases queries may depend on each other, your program must run online.
Input Format
The first line contains four integers separated by spaces: , , , , where is the forced-online parameter used to decrypt the real queries.
The next lines describe the edges. The -th line contains two integers and separated by a space, representing the edge sequence .
The next lines each contain two integers separated by spaces, representing an encrypted query.
The real query pair is decrypted as follows.
DecodeQuery( l', r', m, t, last_ans )
(l, r) <- (l', r')
IF t > 0 THEN
l <- (l + t * last_ans) Mod |E| + 1
r <- (r + t * last_ans) Mod |E| + 1
IF l' > r' THEN
Swap(l, r)
RETURN (l, r)
Here, last_ans is the answer to the previous query. Initially, last_ans = 0.
Output Format
Output lines, each being the answer to one query.
5 5 4 0
1 2
3 4
2 3
4 5
1 5
1 3
2 5
3 4
5 5
2
1
3
4
见附件中 sample2.in
见附件中 sample2.out
Hint
Sample Explanation

Constraints and Notes
For of the testdata, it is guaranteed that , , , and . Note that the testdata may contain multiple edges and self-loops.
Subtasks
Subtask 1 ( points): .
Subtask 2 ( points): .
Subtask 3 ( points): , .
Subtask 4 ( points): No special restrictions.
Translated by ChatGPT 5