#P10063. [SNOI2024] 平方数

[SNOI2024] 平方数

Background

The original time limit was 1.5 s.

Because it was hard to pass due to hack testdata, it was changed to 10 s.

Problem Description

You are given a sequence of positive integers a1,a2,,ana_1, a_2, \ldots, a_n. How many subarrays have a product that is a perfect square. In other words, how many pairs (l,r)(l, r) (1lrn1 \le l \le r \le n) satisfy that i=lrai\prod_{i = l}^{r} a_i is a perfect square.

Input Format

The first line contains an integer nn, the number of integers.
The next line contains nn integers, a1,a2,,ana_1, a_2, \ldots, a_n.

Output Format

Output one integer, the number of subarrays whose product is a perfect square.
Then output these subarrays in lexicographical order, i.e., output by increasing ll.
If multiple subarrays have the same ll, output them by increasing rr. If the number of subarrays exceeds 105{10}^5, output only the first 105{10}^5.

10
1 2 3 4 6 8 9 12 16 18

12
1 1
1 5
2 5
3 6
3 7
4 4
4 8
4 9
5 8
5 9
7 7
9 9

3
999999999999999956000000000000000363 999999999999999844000000000000004059 999999999999999866000000000000001353

1
1 3

Hint

[Explanation for Sample #2]

In the second sample, the three numbers are 101811,101833,1018123{10}^{18} - 11, {10}^{18} - 33, {10}^{18} - 123, and every pairwise product is computed.


[Sample #3]

See the attachments square/square3.in and square/square3.ans.

This sample satisfies the constraint limits of test points 464 \sim 6.


[Sample #4]

See the attachments square/square4.in and square/square4.ans.

This sample satisfies the constraint limits of test points 111411 \sim 14.


[Sample #5]

See the attachments square/square5.in and square/square5.ans.

This sample satisfies the constraint limits of test points 182018 \sim 20.


[Constraints]

For all testdata, it is guaranteed that 1n3×1051 \le n \le 3 \times {10}^5, 1ai10361 \le a_i \le {10}^{36}.

Specifically:

Test Point ID nn \le aia_i \le
131 \sim 3 10001000 104{10}^4
464 \sim 6 105{10}^5 106{10}^6
7107 \sim 10 100100 1036{10}^{36}
111411 \sim 14 10001000
151715 \sim 17 105{10}^5
182018 \sim 20 3×1053 \times {10}^5

Translated by ChatGPT 5