Prefix equality - MarisaOJ: Marisa Online Judge

Prefix equality

Time limit: 1000 ms
Memory limit: 256 MB
Given two integer arrays $A$ and $B$ both of length $n$. You have to answer $q$ queries, each of the form $i, j$, determine if the set of elements (does not allow duplicity) formed from the prefix $A[1...i]$ and the set formed from prefix $B[1...j]$ are equal. ### Input - The first line contains 2 integers $n, q$. - The second line contains $n$ integers $A_i$. - The third line contains $n$ integeres $B_i$. - The next $q$ lines, each line contains two integers $(i, j)$, a query. ### Output - For each query, print `YES` if two sets are equal, otherwise print `NO`. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le A_i, B_i \le 10^9$. - $1 \le i, j \le n$. ### Example Input: ``` 3 2 1 1 2 2 1 2 1 2 3 2 ``` Output: ``` NO YES ```