#P2671. [NOIP 2015 普及组] 求和

    ID: 1695 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2015线性结构NOIp 普及组排序前缀和

[NOIP 2015 普及组] 求和

Description

A long narrow strip of paper is evenly divided into nn cells, numbered from 11 to nn. Each cell is colored with a color coloricolor_i (represented by an integer from [1,m][1, m]), and a number numberinumber_i is written on it.

Index 1 2 3 4 5 6
Color and number 5\color{blue}{5} 3\color{red}{3} 2\color{red}{2} 2\color{blue}{2} 2\color{red}{2}

Define a special triplet (x,y,z)(x, y, z), where xx, yy, zz are indices of cells on the strip, satisfying both of the following conditions:

  1. xx, yy, zz are integers, x<y<zx < y < z, yx=zyy - x = z - y.
  2. colorx=colorzcolor_x = color_z.

The score of such a triplet is defined as (x+z)×(numberx+numberz)(x+z) \times (number_x+number_z). The score of the entire strip is the sum of the scores of all triplets that satisfy the conditions. This score can be very large; you only need to output the remainder when the total score is divided by 1000710007.

Input Format

The first line contains two positive integers nn and mm separated by a space. nn is the number of cells on the strip, and mm is the number of colors.

The second line contains nn positive integers separated by spaces; the ii-th number is the number numberinumber_i written on cell ii.

The third line contains nn positive integers separated by spaces; the ii-th number is the color coloricolor_i of cell ii.

Output Format

A single integer, the remainder of the total score modulo 1000710007.

6 2
5 5 3 2 2 2
2 2 1 1 2 1
82

15 4
5 10 8 2 2 2 9 9 7 7 5 6 4 2 4
2 2 3 3 4 3 3 2 4 4 4 4 1 1 1
1388

Hint

Sample 1 Explanation.

The strip is as shown in the figure in the problem description.

All valid triplets are: (1,3,5)(1, 3, 5), (4,5,6)(4, 5, 6).

Therefore, the total score is $(1 + 5) \times (5 + 2) + (4 + 6) \times (2 + 2) = 42 + 40 = 82$.

Constraints:

  • For testdata groups 11 to 22, 1n1001 \le n \le 100, 1m51 \le m \le 5.
  • For testdata groups 33 to 44, 1n30001 \le n \le 3000, 1m1001 \le m \le 100.
  • For testdata groups 55 to 66, 1n1051 \le n \le 10^5, 1m1051 \le m \le 10^5, and no color appears more than 2020 times.
  • For all 1010 testdata groups, 1n1051 \le n \le 10^5, 1m1051 \le m \le 10^5, 1colorim1 \le color_i \le m, 1numberi1051 \le number_i \le 10^5.

Translated by ChatGPT 5