Crtež

시간 제한2초메모리 제한2048 MB

요약
왼쪽으로 이어지는 서로 다른 색 칠하기와 -1 칠하기로 만들 수 있는 서로 다른 최종 상태의 수를 구간 0/-1 교환마다 세는 문제.
난이도

어려움10점 중 9점

유형
조합론, 세그먼트 트리, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

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 different 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.

입력

In the first line, there are 22 natural numbers NN, QQ (1≤N≤10181 ≤ N ≤ 10^{18}, 1≤Q≤1051 ≤ 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 (1≤L,R≤N1 ≤ L, R ≤ N), indicating the positions that describe the update from the problem statement.

출력

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.

힌트

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.

예제3

  1. 예제 1

    입력
    1 2
    1 1
    1 1
    
    예상 출력
    1
    3
    
  2. 예제 2

    입력
    3 2
    2 2
    1 3
    
    예상 출력
    9
    3
    
  3. 예제 3

    입력
    57 2
    13 39
    6 42
    
    예상 출력
    130653412
    804077942