#P9747. 「KDOI-06-S」签到题
「KDOI-06-S」签到题
Background
You are watching anime, and suddenly your parents come in, so you pretend you are solving a data structure problem.
Problem Description
Define an array of length to be valid if and only if, after performing the following operation some number of times, all elements in can be made equal:
- Choose four integers (, ) such that , and$$v_a\operatorname{~or~}v_{a+1}\operatorname{~or~}\cdots\operatorname{~or~}v_b=v_c\operatorname{~or~}v_{c+1}\operatorname{~or~}\cdots\operatorname{~or~}v_d,$$where denotes the bitwise OR operation. Then, copy the numbers in interval and overwrite them onto interval . Note: intervals and may overlap.
You are given a sequence of length and queries. Each query gives two positive integers . You need to answer the length of the longest valid sub-interval within .
Input Format
Read from standard input.
This problem contains multiple test cases.
The first line contains two integers , representing the number of test cases and the test point ID (the sample’s test point ID is ).
For each test case, the first line contains two positive integers , representing the sequence length and the number of queries.
The second line contains positive integers , representing the values of the sequence .
The next lines each contain two positive integers , representing the query interval.
Output Format
Write to standard output.
For each query in each test case, output one integer per line, representing the length of the longest valid sub-interval within .
2 0
7 2
0 4 2 6 0 6 6
1 7
2 3
3 1
1 2 3
1 3
7
1
3
Hint
[Sample Explanation #1]
For the first query of the first test case, the longest valid sub-interval is . One possible sequence of operations is:
-
Choose intervals and . First copy the numbers in , then overwrite them onto . The sequence becomes .
-
Choose intervals and . The sequence becomes .
-
Choose intervals and . The sequence becomes .
Note that the operations do not actually modify the values in the original sequence.
For the second query of the first test case, the longest valid sub-intervals are and .
[Sample #2]
See binary/binary2.in and binary/binary2.ans in the contestant directory.
This sample satisfies the constraints of test points .
[Sample #3]
See binary/binary3.in and binary/binary3.ans in the contestant directory.
This sample satisfies the constraints of test points .
[Sample #4]
See binary/binary4.in and binary/binary4.ans in the contestant directory.
This sample satisfies the constraints of test points .
[Constraints]
It is guaranteed for all data that: , , .
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| B | |||
| None | |||
| B | |||
| None | |||
| A | |||
| None | |||
- Special Property A: Every number in sequence is generated uniformly at random within .
- Special Property B: For any , .
[Hint]
The input/output size of this problem is large. Please use an appropriate I/O method.
Please pay attention to the impact of constant factors on program runtime efficiency.
A warm reminder from the KDOI problemset team: If you do not clear your data between test cases, you will get zero points and cry for two lines.
Translated by ChatGPT 5