F. Equal XOR Segments
1.Iva & Pav2.P2023 [AHOI2009] 维护序列3.P1531 I Hate It4.P5057 [CQOI2006] 简单题5.P2357 守墓人6.P8775 [蓝桥杯 2022 省 A] 青蛙过河7.Dora and Search8.P6492 [COCI2010-2011#6] STEP9.D. Slimes10.P1040 [NOIP2003 提高组] 加分二叉树11.P2466 [SDOI2008] Sue 的小球12.P3957 [NOIP2017 普及组] 跳房子13.P2135 方块消除14.P1884 [USACO12FEB] Overplanting S15.P2642 双子序列最大和16.P2422 良好的感觉17.P3128 [USACO15DEC] Max Flow P18.P3258 [JLOI2014] 松鼠的新家19.P3384 【模板】重链剖分/树链剖分20.P5367 【模板】康托展开21.P2344 [USACO11FEB] Generic Cow Protests G22.P2709 小B的询问23.P4145 上帝造题的七分钟 2 / 花神游历各国24.P5677 [GZOI2017] 配对统计25.P2161 [SHOI2009] 会场预约
26.F. Equal XOR Segments
27.D. A BIT of an Inequality28.P3147 [USACO16OPEN] 262144 P29.P4290 [HAOI2008] 玩具取名30.E. Long Inversions31.P1668 [USACO04DEC] Cleaning Shifts S32.P9691 [GDCPC2023] Base Station Construction33.P2734 [USACO3.3] 游戏 A Game34.D. Sum of XOR Functions35.C. Medium Design36.F. Feed Cats37.E. Boring Segments题解
1.如果能分成偶数个区间,那么一定能分为两个区间
2.如果能分为奇数个区间,那么一定能分为三个区间
3.能分为两个区间,说明区间异或和为
4.能分为三个区间,这三个区间分别为区间
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;
}
合集:
区间问题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~