Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
1.5 kB
5
Indexable
Never
#include<bits/stdc++.h>

using namespace std;

int build(vector<int>&segTree, int indx, int left, int right, vector<int>&v)
{
    if (left == right)
    {
        segTree[indx] = v[left] + 9999999 ;
        return segTree[indx];
    }
    int mid = (left + right) / 2;
    int l = build(segTree, indx * 2, left, mid, v);
    int r = build(segTree, (indx * 2) + 1, mid + 1, right, v);
    segTree[indx] = l ^ r;
    return segTree[indx];
}

int query(vector<int> &segTree, int indx, int l, int r, int ss, int se)
{
    if (l > se || r < ss)
    {
        return 0;
    }

    if (l <= ss && r >= se)
    {
        return segTree[indx];
    }

    int mid = (ss + se) / 2;
    int leftQ = query(segTree, indx * 2, l, r, ss, mid);
    int rightQ = query(segTree, (indx * 2) + 1, l, r, mid + 1, se);
    return (leftQ ^ rightQ);
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, q;
        cin >> n >> q;
        vector<int> segTree(4 * n);
        vector<int> v(n);
        for (auto &x: v)
        {
            cin >> x;
        }
        build(segTree, 1, 0, n - 1, v);
        while (q--)
        {
            int l, r;
            cin >> l >> r;
            if (l == r)
            {
                cout << "NO\n";
                continue;
            }
            int ans = query(segTree, 1, l - 1, r - 1, 0, n - 1);
            string str = ans ? "NO\n" : "YES\n";
            cout << str;
        }
    }
    return 0;
}
Leave a Comment