#P7470. [NOI Online 2021 提高组] 岛屿探险

[NOI Online 2021 提高组] 岛屿探险

Problem Description

Songmu is a girl who likes adventures. One day, she came to a sea area to explore.

In this sea area, there are nn islands in a row, numbered 1,2,3,,n1,2,3,\ldots,n. Each island has two values: fatigue aia_i and fun bib_i.

For an island with fatigue aa and fun bb, if this island satisfies (ac)min(b,d)(a\oplus c) \leq \min(b,d), then Songmu will feel happy when exploring this island. Here, cc denotes Songmu's fatigue before going onto the island (called the initial fatigue), and similarly, dd denotes Songmu's initial fun. \oplus denotes bitwise XOR (i.e., addition without carry in binary).

To enjoy herself more, Songmu will ask you qq queries. Each query gives an interval [li,ri][l_i,r_i] and two numbers ci,dic_i,d_i. You need to tell Songmu: if her initial fatigue is cic_i and her initial fun is did_i, then how many islands with indices in the interval [li,ri][l_i,r_i] can make Songmu feel happy while exploring.

Input Format

The first line contains two positive integers n,qn,q, denoting the number of islands and the number of queries.

The next nn lines each contain two integers ai,bia_i,b_i, denoting the fatigue and fun of the ii-th island.

The next qq lines each contain four positive integers li,ri,ci,dil_i,r_i,c_i,d_i, denoting the left endpoint of the interval, the right endpoint of the interval, the initial fatigue, and the initial fun.

Output Format

Output qq lines in total, each containing one integer, the answer to the corresponding query.

4 2
1 1
4 2
5 1
2 7
1 4 6 5
2 4 3 3
2
1
20 10
215 144
2 110
174 132
214 142
116 108
155 192
236 208
216 214
99 220
236 118
190 81
230 131
10 238
189 198
183 13
45 193
14 234
208 192
126 19
49 38
7 14 251 184
2 18 89 76
11 15 49 196
8 11 83 139
10 15 119 239
9 16 148 120
11 17 225 34
15 16 3 46
14 15 86 227
7 18 252 103
7
2
2
2
1
3
1
1
0
7

Hint

Test points 1,21,2 satisfy 1n,q50001\leq n,q\leq 5000.

Test points 3,43,4 satisfy 1n,q1041\leq n,q\leq 10^4.

Test points 5,6,75,6,7 satisfy 1n,q1051\leq n,q\leq 10^5 and max{di}min{bi}\max\{d_i\}\leq \min\{b_i\}.

Test points 8,9,10,118,9,10,11 satisfy 1n,q1051\leq n,q\leq 10^5 and min{di}max{bi}\min\{d_i\}\geq \max\{b_i\}.

Test points 12,1312,13 satisfy 1n,q1051\leq n,q\leq 10^5 and li=1,ri=nl_i=1,r_i=n.

Test points 14,15,1614,15,16 satisfy 1n,q7×1041\leq n,q\leq 7\times 10^4.

Test points 17,18,19,2017,18,19,20 satisfy 1n,q1051\leq n,q\leq 10^5.

All testdata satisfy 1n,q1051\leq n,q\leq 10^5, 1ai,bi,ci,di22411\leq a_i,b_i,c_i,d_i\leq 2^{24}-1.

Translated by ChatGPT 5