Logo
(追記) (追記ここまで)

33730번 - The Best Subsequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB633100.000%

문제

Farmer John has a binary string of length $N$ $(1 \leq N \leq 10^9),ドル initially all zeros.

He will first perform $M$ (1ドル \leq M \leq 2 \cdot 10^5$) updates on the string, in order. Each update flips every character from $l$ to $r$. Specifically, flipping a character changes it from 0ドル$ to 1ドル,ドル or vice versa.

Then, he asks you $Q$ (1ドル \leq Q \leq 2 \cdot 10^5$) queries. For each query, he asks you to output the lexicographically greatest subsequence of length $k$ comprised of characters from the substring from $l$ to $r$. If your answer is a binary string $s_1s_2 \dots s_k,ドル then output $\sum_{i=0}^{k-1} 2^i \cdot s_{k-i}$ (that is, its value when interpreted as a binary number) modulo 10ドル^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 $A$ is lexicographically greater than string $B$ of equal length if and only if at the first position $i,ドル if it exists, where $A_i \neq B_i,ドル we have $A_i > B_i$.

입력

The first line contains $N,ドル $M,ドル and $Q$.

The next $M$ lines contain two integers, $l$ and $r$ (1ドル \leq l \leq r \leq N$) — the endpoints of each update.

The next $Q$ lines contain three integers, $l,ドル $r,ドル and $k$ (1ドル \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 $Q$ lines. The $i$th line should contain the answer for the $i$th query.

제한

예제 입력 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

예제 출력 1

21
13
7
3
1
5
5
3
1

After performing the $M$ operations, the string is 10101ドル$.

For the first query, there is only one subsequence of length 5ドル,ドル 10101ドル,ドル which is interpreted as 1ドル \cdot 2^4 + 0 \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1 \cdot 2^0 = 21$.

For the second query, there are 5ドル$ unique subsequences of length 4ドル$: 0101ドル,ドル 1101ドル,ドル 1001ドル,ドル 1011ドル,ドル 1010ドル$. The lexicographically largest subsequence is 1101ドル,ドル which is interpreted as 1ドル \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1\cdot 2^0 = 13$.

For the third query, the lexicographically largest sequence is 111ドル,ドル which is interpreted as 7ドル$.

예제 입력 2

9 1 1
7 9
1 8 8

예제 출력 2

3

예제 입력 3

30 1 1
1 30
1 30 30

예제 출력 3

73741816

Make sure to output the answer modulo 10ドル^9+7$.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 February Contest > Gold 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /