#K77022. Unique Words Query

    ID: 34772 Type: Default 1000ms 256MiB

Unique Words Query

Unique Words Query

You are given a sequence of n words and q queries. Each query consists of two indices l and r (1-indexed). For each query, determine whether all the words in the subarray from index l to r are unique.

If they are all unique, print YES; otherwise, print NO.

Note: The indices of the array start from 1.

Mathematically, for a query defined by indices \(l\) and \(r\), you need to check if \[ |\{ words[l], words[l+1], \ldots, words[r] \}| = r - l + 1. \]

inputFormat

The input is given from stdin in the following format:

 n
 word1 word2 ... wordn
 q
 l1 r1
 l2 r2
 ...
 lq rq

Where:

  • n is the number of words.
  • The next line contains n space-separated words.
  • q is the number of queries.
  • Each of the next q lines contains two integers l and r (1-indexed) representing the range of the query.

outputFormat

For each query, output a single line containing either YES if all words in the range are unique, or NO if there is any repetition.

## sample
5
apple banana cherry date elderberry
3
1 3
2 5
3 4
YES

YES YES

</p>