#P13688. 【MX-X16-T6】「DLESS-3」XOR and Powerless Suffix Mode

    ID: 13473 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>莫队O2优化组合数学Lucas 定理根号分治梦熊比赛

【MX-X16-T6】「DLESS-3」XOR and Powerless Suffix Mode

Description

We define a value xx as a "Powerless Suffix Mode" of a subsequence of a given sequence bb, with a parameter pp, if and only if the following conditions are met:

  • xx is a mode of the subsequence (i.e., one of the most frequent elements).
  • Let the subsequence be formed by elements of bb at indices w1,w2,,wkw_1, w_2, \dots, w_k, and let w={w1,w2,,wk}w = \{w_1, w_2, \dots, w_k\}. There do not exist indices i,ji, j (of the sequence bb) such that i<ji < j, bi=bj=xb_i = b_j = x, iwi \in w, and jwj \notin w.
  • The number of occurrences of xx in the subsequence does not exceed p%p\% of the total number of occurrences of xx in the entire sequence bb.

You are given a sequence aa of nn non-negative integers and qq queries. Each query provides three integers l,r,pl, r, p. For each query, consider the subarray b=a[lr]b = a[l \dots r] as the base sequence. You need to calculate the XOR sum of all Powerless Suffix Modes over all subsequences of bb. If a particular subsequence has multiple Powerless Suffix Modes, all of them should be included in the XOR sum.

Input Format

The first line contains two integers, nn and qq.

The second line contains nn integers, representing the sequence aa.

Each of the next qq lines contains three integers, l,r,pl, r, p, describing one query.

Output Format

For each query, output a single integer on one line, representing the answer.

13 6
1 1 4 5 1 4 1 9 1 9 8 1 0
7 9 100
3 6 50
7 11 100
7 11 99
1 3 100
2 4 100
9
0
8
0
4
0
18 1
1 1 1 1 1 1 2 2 2 2 2 2 4 4 4 4 4 4
1 18 40
7

Hint

For all test cases, it is guaranteed that:

  • 1n2.5×1051\le n\le 2.5\times10^5
  • 1q2.5×1051\le q\le 2.5\times10^5
  • 0ai<2240\le a_i<2^{24}
  • 0<p1000<p\le100
  • 1lrn1\le l\le r\le n

This problem uses subtasks for scoring. The descriptions of the subtasks are as follows:

Subtask nn\le qq\le ai<a_i< Score
11 1818 2020 2242^{24} 77
22 500500 1111
33 50005000 1515
44 2.5×1052.5\times10^5 2.5×1052.5\times10^5 22 1313
55 262^6 1414
66 282^8
77 5×1045\times10^4 2242^{24}
88 2.5×1052.5\times10^5 1212