F. Equal XOR Segments

原题链接

题解

1.如果能分成偶数个区间,那么一定能分为两个区间
2.如果能分为奇数个区间,那么一定能分为三个区间
3.能分为两个区间,说明区间异或和为 0
4.能分为三个区间,这三个区间分别为区间 a,b,c ,则 ab 区间异或和为零, bc 区间异或和为零

code

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 200005;
int pre[MAXN] = {0};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, q;
        cin >> n >> q;
        map<int,vector<int> > id;
        id[0].push_back(0);
        for (int i = 1; i <= n; i++)
        {
            int x;
            cin>>x;
            pre[i]=pre[i-1]^x;
            id[pre[i]].push_back(i);
        }
        while(q--)
        {
            int l,r;
            cin>>l>>r;
            if(pre[r]==pre[l-1]) cout<<"YES\n";
            else
            {
                int itl=*(lower_bound(id[pre[l-1]].begin(),id[pre[l-1]].end(),r)-1);//如果[l,r]区间异或和为零,代表前缀和pre[l-1]==pre[r]
                int itr=*(lower_bound(id[pre[r]].begin(),id[pre[r]].end(),l));
                //printf("itl:%d  itr:%d\n",itl,itr);
                if(itl>=itr&&itl!=l&&itr!=r) cout<<"YES\n";
                else cout<<"NO\n";
            }
        }
        cout<<"\n";
    }
    return 0;
}
posted @   纯粹的  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示