Suppose you have an array π. Initially, you also have a set π that contains allβ¦
- User
Suppose you have an array π. Initially, you also have a set π that contains all distinct elements of π. The array π is called orangutan-approved if it can be emptied by repeatedly performing the following operation:
In one operation, select indices π and π (1β€πβ€πβ€|π|) such that π£=ππ=ππ+1=β¦=ππ and π£ is present in π. Remove π£ from π, and simultaneously remove all ππ such that πβ€πβ€π. Then, reindex the elements ππ+1,ππ+2,β¦ as ππ,ππ+1,β¦ accordingly. You are given an array π of length π and π queries.
Each query consists of two indices π and π (1β€πβ€πβ€π), and you need to determine whether or not the subarray ππ,ππ+1,β¦,ππ is orangutan-approved.
Input The first line contains π‘ (1β€π‘β€104) β the number of test cases.
The first line of each test case contains integers π and π (1β€π,πβ€2β 105) β the size of π and the number of queries, respectively.
The following line contains π integers π1,π2,β¦,ππ (1β€ππβ€π) β the elements of the array π.
The following π lines contain two integers π and π β the endpoints of the subarray for each query (1β€πβ€πβ€π).
It is guaranteed that the sum of π and π over all test cases does not exceed 2β 105.
Output For each query, output "YES" (without quotes) if the subarray from π to π is orangutan-approved, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
Example inputCopy 3 4 2 1 2 2 1 1 4 1 3 5 3 1 2 1 2 1 2 5 3 5 1 3 8 4 1 2 3 2 1 3 2 3 1 5 2 8 3 5 6 8 outputCopy YES YES NO YES YES YES NO YES YES Note In the first query of the first testcase, the answer is YES.
Initially, π={1,2} and π=[1,2,2,1] Select π=2 and π=3. Since π2=π3=2 is in π, we may erase π2 and π3 from the array, as well as erasing 2 from π. The set π becomes {1} and the array becomes [1,1]. Select π=1 and π=2. Since π1=π2=1 is in π, we may erase π1 and π2 from the array, as well as erasing 1 from π. The set π becomes {} and the array becomes []. Since the array is now empty, we can say the original array is orangutan-approved. In the first query of the second testcase, the answer is NO, because it can be shown that the subarray [2,1,2,1] cannot become empty through any sequence of valid operations. please solve using the following template with 2 space tab only #include #include #include
using namespace std;
void solve() { int n, q; cin >> n >> q; vector a(n); for(auto &x : a) cin >> x;
}
int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) solve(); }
- Assistant