The Best Subsequence

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

요약
긴 이진 문자열에 구간 뒤집기 갱신을 적용한 뒤, 각 질의마다 부분 문자열에서 사전순으로 가장 큰 길이 k 부분수열을 골라 그 값을 10^9+7로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

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

문제

Farmer John has a binary string of length NN (1≤N≤109)(1 \leq N \leq 10^9), initially all zeros.

He will first perform MM (1≤M≤2⋅1051 \leq M \leq 2 \cdot 10^5) updates on the string, in order. Each update flips every character from ll to rr. Specifically, flipping a character changes it from 00 to 11, or vice versa.

Then, he asks you QQ (1≤Q≤2⋅1051 \leq Q \leq 2 \cdot 10^5) queries. For each query, he asks you to output the lexicographically greatest subsequence of length kk comprised of characters from the substring from ll to rr. If your answer is a binary string s_1s_2…s_ks\_1s\_2 \dots s\_k, then output ∑_i=0k−12i⋅s_k−i\sum\_{i=0}^{k-1} 2^i \cdot s\_{k-i} (that is, its value when interpreted as a binary number) modulo 109+710^9+7.

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

Recall that string AA is lexicographically greater than string BB of equal length if and only if at the first position ii, if it exists, where A_i≠B_iA\_i \neq B\_i, we have A_i>B_iA\_i > B\_i.

입력

The first line contains NN, MM, and QQ.

The next MM lines contain two integers, ll and rr (1≤l≤r≤N1 \leq l \leq r \leq N) — the endpoints of each update.

The next QQ lines contain three integers, ll, rr, and kk (1≤l≤r≤N,1≤k≤r−l+11 \leq l \leq r \leq N, 1 \leq k \leq r - l + 1) — the endpoints of each query and the length of the subsequence.

출력

Output QQ lines. The iith line should contain the answer for the iith query.

예제3

  1. 예제 1

    입력
    5 3 9
    1 5
    2 4
    3 3
    1 5 5
    1 5 4
    1 5 3
    1 5 2
    1 5 1
    2 5 4
    2 5 3
    2 5 2
    2 5 1
    
    예상 출력
    21
    13
    7
    3
    1
    5
    5
    3
    1
    
  2. 예제 2

    입력
    9 1 1
    7 9
    1 8 8
    
    예상 출력
    3
    
  3. 예제 3

    입력
    30 1 1
    1 30
    1 30 30
    
    예상 출력
    73741816