#P4688. [Ynoi Easy Round 2016] 掉进兔子洞

[Ynoi Easy Round 2016] 掉进兔子洞

Description

You are playing a galgame, and suddenly realize you have been slacking off too much today, so you want to write a data structure problem to practice:

There is a sequence aa of length nn.

There are mm queries. Each query gives three intervals. For numbers that appear in all three intervals, delete them one by one. Ask for the sum of the counts of remaining numbers in the three intervals at the end. Queries are independent.

Note that “delete” means deleting one by one, not deleting all elements equal to that value at once. For example, if the three intervals are [1,2,2,3,3,3,3][1,2,2,3,3,3,3], [1,2,2,3,3,3,3][1,2,2,3,3,3,3], and [1,1,2,3,3][1,1,2,3,3], then we throw away 11 occurrence of 11, 11 occurrence of 22, and 22 occurrences of 33 together.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers denoting aia_i.

Then follow mm lines. Each line contains 66 integers l1,r1,l2,r2,l3,r3l_1,r_1,l_2,r_2,l_3,r_3 describing the three intervals.

Output Format

For each query, output one integer denoting the answer.

5 2
1 2 2 3 3
1 2 2 3 3 4
1 5 1 5 1 5
3
0

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477

1n,m1051\leq n , m \leq 10^5, 1ai1091 \leq a_i\leq 10^9, 1l1,r1,l2,r2,l3,r3n1\leq l_1,r_1,l_2,r_2,l_3,r_3\leq n, l1r1l_1\leq r_1, l2r2l_2\leq r_2, l3r3l_3\leq r_3

Translated by ChatGPT 5