2053: [USACO 2025 February Contest, Gold] Problem 2. The Best Subsequence

文件提交:无需freopen 内存限制:256 MB 时间限制:8.000 S
评测方式:普通裁判 命题人:
提交:3 解决:1

题目描述

Farmer John has a binary string of length  , initially all zeros.

He will first perform  () updates on the string, in order. Each update flips every character from  to . Specifically, flipping a character changes it from  to , or vice versa.

Then, he asks you  () queries. For each query, he asks you to output the lexicographically greatest subsequence of length  comprised of characters from the substring from  to . If your answer is a binary string , then output (that is, its value when interpreted as a binary number) modulo .

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  is lexicographically greater than string  of equal length if and only if at the first position , if it exists, where , we have .

输入

The first line contains , , and .

The next  lines contain two integers,  and  () — the endpoints of each update.

The next  lines contain three integers, , , and  () — the endpoints of each query and the length of the subsequence.

输出

Output Q lines. The ith line should contain the answer for the ith query.

样例输入

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

提示

After performing the  operations, the string is .

For the first query, there is only one subsequence of length , , which is interpreted as.

For the second query, there are  unique subsequences of length : , , , , . The lexicographically largest subsequence is , which is interpreted as .

For the third query, the lexicographically largest sequence is , which is interpreted as .

SAMPLE INPUT:

9 1 1

7 9

1 8 8

SAMPLE OUTPUT:

3


SAMPLE INPUT:

30   1   1

1    30

1    30  30


SAMPLE OUTPUT:

73741816

Make sure to output the answer modulo .


SCORING:

  • Input 4: 
  • Input 5: 
  • Inputs 6-7: 
  • Inputs 8-12: 
  • Inputs 13-20: No additional constraints.


来源/分类