#P7577. 「PMOI-3」简单模拟题

    ID: 8322 远端评测题 4500ms 256MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>二分O2优化可持久化线段树

「PMOI-3」简单模拟题

Problem Description

You are given a sequence ss of length nn.

There are qq queries. Each query is in the form a b c d e f, and you need to compute the value of the following expression:

$$\sum_{L=a}^{b}[e\le G(F(L,c),F(L,c+1),\cdots,F(L,d))\le f]$$

Here, F(l,r)F(l,r) denotes the number of distinct values in the subarray [l,r][l,r] of sequence ss, and G(x1,x2,⋯ ,xk)G(x_1,x_2,\cdots,x_k) denotes the number of distinct values among x1,x2,⋯ ,xkx_1,x_2,\cdots,x_k.

Input Format

The first line contains two integers n,qn,q, representing the length of the sequence and the number of queries.

The second line contains nn integers, where the ii-th integer represents sis_i.

The next qq lines each contain 66 integers a′,b′,c′,d′,e,fa',b',c',d',e,f. Let the answer to the previous query be lastans\text{lastans} (in particular, if this is the first query, then lastans=0\text{lastans}=0). Then in this query: a=(a′+lastans) mod n+1a=(a'+\text{lastans})\bmod n+1\\ b=(b′+lastans) mod n+1b=(b'+\text{lastans})\bmod n+1\\ c=(c′+lastans) mod n+1c=(c'+\text{lastans})\bmod n+1\\ d=(d′+lastans) mod n+1d=(d'+\text{lastans})\bmod n+1\\

Note that you need to reorder a,b,c,da,b,c,d so that a≤b≤c≤da\le b\le c\le d.

Output Format

For each query, output the answer in order.

3 1
2020 2021 2020
3 3 2 2 1 1
1
10 3
2 2 4 3 5 3 5 4 1 2
3 5 2 4 1 2
5 7 2 9 2 4
1 3 1 8 1 3
2
4
4

Hint

[Sample 1 Explanation]

In the first query, a=1,b=1,c=3,d=3,e=1,f=1a=1,b=1,c=3,d=3,e=1,f=1.

It is easy to get G(F(1,3))=1G(F(1,3))=1, and e≤G(F(1,3))≤fe\le G(F(1,3))\le f, so the answer is 11.

[Sample 2 Explanation]

Query ID aa bb cc dd ee ff
① 3 4 5 6 1 2
② 2 5 8 10 2 4
③ 3 6 8 1 3

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (10 pts): n,q≤500n,q\le500, 1≤si≤1061\le s_i\le10^6.
  • Subtask 2 (15 pts): n,q≤3×103n,q\le3\times10^3.
  • Subtask 3 (20 pts): b−a≤20b-a\le20.
  • Subtask 4 (25 pts): n,q≤105n,q\le10^5.
  • Subtask 5 (30 pts): no special constraints.

For 100%100\% of the testdata, 1≤n,q≤3×1051\le n,q\le3\times10^5, 0≤∣si∣≤1090\le|s_i|\le10^9. For all queries, 1≤a,b,c,d≤n1\le a,b,c,d\le n, 0≤e≤f≤n0\le e\le f\le n.

[Hint]

  1. In this problem, [x≤y≤z][x \le y \le z] indicates whether yy is ∈[x,z]\in[x,z]. If it is in this interval, the value is 11; otherwise it is 00.

  2. The input size is large, so please use a faster input method.

Translated by ChatGPT 5