13515 - Remove others   

Description

Given a sequence A = a1, a2, ..., aN.

However, for any ai ≠ aj, ai hates aj and aj hates ai. Two distinct elements don't want to be together.

You are given Q queries.

In each query, you are given Li, Ri, and Xi. You have to find the number of elements needed to be removed to make A[Li...Ri] contain Xi only.

It is guaranteed for each i = 1, 2, ..., Q - 1, Li ≤ Li+1 and Ri ≤ Ri+1.

 

For example, if A = [1, 3, 2, 3, 3] and L = 1, R = 5, and X = 3.

Then you have to remove A[1] and A[3] to make A contain 3 only.

Hence, the number of elements needed to be removed is 2 in this example.

 

It is recommended to include<stdio.h> and use scanf/printf instead of cin/cout to speed up input and output.

You may need to select c++11, c++14, c++17 as the compiler to avoid compile error.

 

Input

The first line of the input contains an integer T, the number of testcases.

The first line of each testcase contains two integers N Q, the length of A and the number of queries.

The second line of each testcase contains N integers, a1, a2, ..., aN.

The next Q lines contains three integers Li, Ri, and Xi as described in the statement.

 

For each test,

  1. N ≤ 100, Q ≤ 100
  2. N ≤ 100, Q ≤ 100
  3. N ≤ 1000, Q ≤ 1000
  4. N ≤ 1000, Q ≤ 1000
  5. N ≤ 200000, Q ≤ 100000
  6. N ≤ 200000, Q ≤ 100000

T ≤ 10, 1 ≤ ai ≤ 109, 1 ≤ Li ≤ Ri ≤ N, 1 ≤ Xi ≤ 109.

 

 

Output

For each query in each testcase, please print the number of elements needed to be removed to make A[Li...Ri] contain Xi only.

You have to print an extra new line at the end of each testcase, including the last one.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss