Consider an array . Given two indices and of the array, can you count the number of triplets of different numbers in , that is, the number of such that , , , and ? You will have to efficiently answer such questions.
Input consists of several cases. Each case starts with an between 5 and . Follow the integer numbers , …, of the array, all between 0 and . Follow different queries, each with an and an such that , , and .
For every query of each case, print the required answer in a line (be aware that this answer may be large). Print a line with four dashes at the end of each case.
The expected solution solves three maximum cases in about two seconds.
Author: Salvador Roura
Generation: 2026-01-25T10:26:27.807Z
© Jutge.org, 2006–2026.
https://jutge.org