#P15591. [ICPC 2020 Jakarta R] Moon and Sun

[ICPC 2020 Jakarta R] Moon and Sun

题目描述

Let SS be a non-empty sequence of integers and KK be a positive integer. The functions moon()moon() and sun()sun() are defined as follows.

$$moon(S_{1..|S|}) = \begin{cases} S & \text{if } |S| = 1 \\ [S_2 - S_1, S_3 - S_2, \dots, S_{|S|} - S_{|S|-1}] & \text{if } |S| > 1 \end{cases} $$$$sun(S_{1..|S|}, K) = \begin{cases} S & \text{if } K = 1 \\ sun(moon(S_{1..|S|}), K - 1) & \text{if } K > 1 \end{cases} $$

For example,

  • moon([2,7])=[5]moon([2, 7]) = [5].
  • moon([4,1,0,7,2])=[3,1,7,5]moon([4, 1, 0, 7, 2]) = [-3, -1, 7, -5].
  • $sun([4, 1, 0, 7, 2], 5) = sun([-3, -1, 7, -5], 4) = sun([2, 8, -12], 3) = sun([6, -20], 2) = sun([-26], 1) = [-26]$.

Observe that sun(S1..S,S)sun(S_{1..|S|}, |S|) is always a sequence with exactly one element.

You are given a sequence of NN integers A1..NA_{1..N}. An index i=[1..N]i = [1..N] is hot if and only if there exists a sequence A1..NA'_{1..N} satisfying the following conditions:

  • AiAiA'_i \ne A_i and AiA'_i is an integer between 100000-100\,000 and 100000100\,000, inclusive;
  • Aj=AjA'_j = A_j for all jij \ne i;
  • The only element in sun(A1..N,N)sun(A'_{1..N}, N) is a multiple of 235813235\,813.

Your task in this problem is to count the number of hot indices in a given A1..NA_{1..N}.

For example, there are 33 hot indices in A1..5=[4,1,0,7,2]A_{1..5} = [4, 1, 0, 7, 2], which are {1,3,5}\{1, 3, 5\}.

  • i=1i = 1, A1=30A'_1 = 30A1..5=[30,1,0,7,2]A'_{1..5} = [30, 1, 0, 7, 2]sun([30,1,0,7,2],5)=[0]sun([30, 1, 0, 7, 2], 5) = [0]
  • i=3i = 3, A1=78600A'_1 = -78\,600A1..5=[4,1,78600,7,2]A'_{1..5} = [4, 1, -78\,600, 7, 2]sun([4,1,78600,7,2],5)=[471626]sun([4, 1, -78\,600, 7, 2], 5) = [-471\,626]
  • i=5i = 5, A1=28A'_1 = 28A1..5=[4,1,0,7,28]A'_{1..5} = [4, 1, 0, 7, 28]sun([4,1,0,7,28],5)=[0]sun([4, 1, 0, 7, 28], 5) = [0]

Note that both 00 and 471626-471\,626 are multiples of 235813235\,813. On the other hand, the index i=2i = 2 is not hot as there does not exist an integer A2A2A'_2 \ne A_2 between 100000-100\,000 and 100000100\,000, inclusive, such that the only element in sun(A1..5,5)sun(A'_{1..5}, 5) is a multiple of 235813235\,813. The index i=4i = 4 is also not hot for a similar reason.

输入格式

Input begins with a line containing an integer: NN (1N1000001 \leq N \leq 100\,000) representing the number of integers in AA. The next line contains NN integers: AiA_i (100000Ai100000-100\,000 \leq A_i \leq 100\,000) representing the sequence of integers.

输出格式

Output in a line an integer representing the number of hot indices in the given A1..NA_{1..N}.

5
4 1 0 7 2
3
4
10 20 30 -40
4
2
100 100
0

提示

Explanation for the sample input/output #1

This is the example from the problem description.

Explanation for the sample input/output #2

  • i=1i = 1, A1=70A'_1 = -70A1..4=[70,20,30,40]A'_{1..4} = [-70, 20, 30, -40]sun([70,20,30,40],4)=[0]sun([-70, 20, 30, -40], 4) = [0]
  • i=2i = 2, A2=78651A'_2 = 78\,651A1..4=[10,78651,30,40]A'_{1..4} = [10, 78\,651, 30, -40]sun([10,78651,30,40],4)=[235813]sun([10, 78\,651, 30, -40], 4) = [235\,813]
  • i=3i = 3, A3=78601A'_3 = -78\,601A1..4=[10,20,78601,40]A'_{1..4} = [10, 20, -78\,601, -40]sun([10,20,78601,40],4)=[235813]sun([10, 20, -78\,601, -40], 4) = [235\,813]
  • i=4i = 4, A4=40A'_4 = 40A1..4=[10,20,30,40]A'_{1..4} = [10, 20, 30, 40]sun([10,20,30,40],4)=[0]sun([10, 20, 30, 40], 4) = [0]