#P1494. [国家集训队] 小 Z 的袜子

[国家集训队] 小 Z 的袜子

Description

Updated on 2020.6.10: time limit updated.

As a somewhat careless person, Xiao Z spends a long time every morning trying to find a pair of socks from a pile of colorful ones. One day, he could no longer stand this annoying process and decided to leave it to fate.

Specifically, Xiao Z numbers his NN socks from 11 to NN, then randomly selects two socks to wear from those numbered LL to RR. Although Xiao Z does not care whether the two socks form a true pair, he does care about their colors, since wearing two socks of different colors would be embarrassing.

Your task is to tell Xiao Z the probability that he draws two socks of the same color. Of course, Xiao Z wants this probability to be as high as possible, so he may ask multiple queries (L,R)(L, R) to help him choose.

However, there are cases with L=RL = R in the testdata. Please handle this case specially and output 0/1.

Input Format

The first line contains two positive integers NN and MM. NN is the number of socks, and MM is the number of queries Xiao Z asks. The next line contains NN positive integers CiC_i, where CiC_i denotes the color of the ii-th sock; the same color is represented by the same integer. Then follow MM lines, each containing two positive integers L,RL, R representing a query.

Output Format

Output MM lines. For each query, output a fraction A/BA/B on a single line representing the probability that two randomly chosen socks from the interval [L,R][L, R] have the same color. If this probability is 00, output 0/1. Otherwise, A/BA/B must be in lowest terms (see the sample).

6 4
1 2 3 3 3 2
2 6
1 3
3 5
1 6
2/5
0/1
1/1
4/15

Hint

In 30%30\% of the testdata, N,M5000N, M \leq 5000.

In 60%60\% of the testdata, N,M25000N, M \leq 25000.

In 100%100\% of the testdata, N,M50000N, M \leq 50000, 1LRN1 \leq L \leq R \leq N, CiNC_i \leq N.

Translated by ChatGPT 5