Anti-Palindrome Queries
An array 
B
B of length 
M
M is called an anti-palindrome if no pair of its opposite elements are equal.
That is, 
B
i
≠
B
M
+
1
−
i
B 
i
​
 =B 
M+1−i
​
  should hold for every index 
1
≤
i
≤
M
1≤i≤M.
For example, 
[
1
,
2
]
[1,2] and 
[
1
,
2
,
3
,
2
]
[1,2,3,2] are anti-palindromes, but 
[
1
,
2
,
3
]
[1,2,3] and 
[
1
,
2
,
3
,
1
]
[1,2,3,1] are not (
i
=
2
i=2 is violated in the first case, 
i
=
1
i=1 in the second).

We say the array 
B
B is beautiful if every cyclic rotation
†
†
  of 
B
B is an anti-palindrome.

You are given an array 
A
A of length 
N
N, which contains only the integers 
1
,
2
,
1,2, and 
3
3.
Answer 
Q
Q queries on this array:

Given 
L
L and 
R
R, let 
B
=
[
A
L
,
A
L
+
1
,
…
,
A
R
]
B=[A 
L
​
 ,A 
L+1
​
 ,…,A 
R
​
 ] denote the subarray of 
A
A from index 
L
L to index 
R
R.
Is it possible to rearrange the elements of 
B
B to make it beautiful?
†
†
  A cyclic rotation of an array is obtained by repeatedly removing its last element and placing it at the beginning.
For example, the cyclic rotations of 
A
=
[
1
,
2
,
2
,
3
]
A=[1,2,2,3] are:
[
1
,
2
,
2
,
3
]
,
[
3
,
1
,
2
,
2
]
,
[
2
,
3
,
1
,
2
]
,
[
2
,
2
,
3
,
1
]
[1,2,2,3],[3,1,2,2],[2,3,1,2],[2,2,3,1].

Input Format
The first line of input will contain a single integer 
T
T, denoting the number of test cases.
Each test case consists of multiple lines of input.
The first line of each test case contains two space-separated integers 
N
N and 
Q
Q — the length of the array and the number of queries.
The second line contains 
N
N space-separated integers 
A
1
,
A
2
,
…
,
A
N
A 
1
​
 ,A 
2
​
 ,…,A 
N
​
 .
The next 
Q
Q lines describe the queries. The 
i
i-th line contains two space-separated integers 
L
L and 
R
R, the parameters of the 
i
i-th query.
Output Format
For each query, output on a new line the answer: "Yes" if it's possible to rearrange the subarray to make it beautiful, and "No" otherwise (without quotes).

Each character of the output may be printed in either uppercase or lowercase, i.e, the strings NO, nO, No, and no will all be treated as equivalent.

Constraints
1
≤
T
≤
1
0
5
1≤T≤10 
5
 
1
≤
N
,
Q
≤
2
⋅
1
0
5
1≤N,Q≤2⋅10 
5
 
1
≤
A
i
≤
3
1≤A 
i
​
 ≤3
1
≤
L
≤
R
≤
N
1≤L≤R≤N
The sum of 
N
N and the sum of 
Q
Q over all test cases both won't exceed 
2
⋅
1
0
5
2⋅10 
5
 .
simplify this quesition and solve using c++
ans below is a wrong solutioN

 cin >> n >> q;

    vector<int> a(n + 1), prefix[4];

    for (int i = 1; i <= 3; ++i)
    {
        prefix[i].resize(n + 1, 0);
    }

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        for (int k = 1; k <= 3; ++k)
        {
            prefix[k][i] = prefix[k][i - 1] + (a[i] == k);
        }
    }

    while (q--)
    {
        cin >> l >> r;
        int length = r - l + 1;

        int count[4];
        for (int k = 1; k <= 3; ++k)
        {
            count[k] = prefix[k][r] - prefix[k][l - 1];
        }

        if (length % 2 != 0)
        {
            cout << "No\n";
            continue;
        }

        int max_count = max({count[1], count[2], count[3]});
        if (max_count > length / 2)
        {
            cout << "No\n";
        }
        else
        {
            cout << "Yes\n";
        }
    }