#P11754. [COCI 2024/2025 #5] 绘图 / Crtež

    ID: 11422 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树2025COCI(克罗地亚)Ad-hoc

[COCI 2024/2025 #5] 绘图 / Crtež

Description

A game is given on a sequence of length NN, initially filled with zeros. During the game, we color positions in the sequence using a series of operations, and we can stop coloring after any operation.

The XX-th coloring operation is described by the following procedure:

  • We select a position containing 00.
  • We decide whether to:
    • Paint the selected position with 1−1.
    • Paint the selected position with color XX and continue painting adjacent positions to the left with color XX. We stop painting when we encounter a position with a value less than 00 (which we do not paint) or when we go out of the sequence bounds.

Two games are considered equivalent if, in their final sequences, we can rename the colors greater than 00, i.e., if there is a bijective mapping such that:

  • Colors after mapping remain greater than 00.
  • Each color receives exactly one new label.
  • After mapping, both sequences are identical.

An example of equivalent games is:

  • [1,1,1,2,1,3,0][1, 1,−1, 2,−1, 3, 0]
  • [3,3,1,1,1,2,0][3, 3,−1, 1,−1, 2, 0]

because there is a mapping of colors (color 11 to color 33, color 22 to color 11, color 33 to color 22) such that all the above conditions are satisfied.

There are QQ updates given, where for each update, we swap all 00s with 1−1s and all 1−1s with 00s in the interval [L,R][L,R] in the sequence.

After each update, print the number KK, the number of different games that can be played with an arbitrary number of operations such that no two games are equivalent. Since KK is very large, print the result modulo 109+710^9 + 7.

Input Format

In the first line, there are 22 natural numbers N,QN, Q (1N1018,1Q1051 ≤ N ≤ 10^{18}, 1 ≤ Q ≤ 10^5), representing the number of fields in the sequence and the number of updates.

In the following QQ lines, there are two natural numbers, LL and RR (1L,RN1 ≤ L,R ≤ N), indicating the positions that describe the update from the problem statement.

Output Format

In the ii-th of the following QQ lines, print the remainder of the division of the number KK by 109+710^9 + 7 after each update.

1 2
1 1
1 1
1
3
3 2
2 2
1 3
9
3
57 2
13 39
6 42
130653412
804077942

Hint

Clarification of the first example:

After the first update, the sequence is equal to [1][−1]. We cannot perform any operations on it, so the maximum number of games we can play is 11.

After the second update, the sequence is equal to [0][0]. From the sequence [0][0], using the operations described in the problem statement, we can create the sequences [0][0], [1][1], and [1][−1]. We observe that no pair of these sequences is equivalent, so the maximum number of games we can play is 33.

Scoring

Subtask Points Constraints
11 2020 N,Q1000N,Q ≤ 1000
22 5555 N106N ≤ 10^6
33 4545 No additional constraints.