[CF617E]XOR and Favorite Number
来源:互联网 发布:温十如何解除网络禁用 编辑:程序博客网 时间:2024/06/05 02:37
617E:XOR and Favorite Number
题意简述
给出一个
数据范围
思路
莫队。
先把求出前缀异或和,这样任意区间都可以通过两个前缀异或得到。
莫队的每个修改都可以在
总时间复杂度
代码
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int n,q,k,lim;int seq[100010],cnt[1100010];long long tot;long long ans[100010];struct ask{ int l,r,id; bool operator < (const ask &n1) const { return l/lim==n1.l/lim ? r<n1.r : l/lim<n1.l/lim; }}a[100010];int main(){ scanf("%d%d%d",&n,&q,&k); lim=int(sqrt(n)); for (int i=1;i<=n;i++) scanf("%d",&seq[i]); for (int i=1;i<=n;i++) seq[i]^=seq[i-1]; for (int i=1;i<=q;i++) { scanf("%d%d",&a[i].l,&a[i].r); a[i].id=i; } sort(a+1,a+q+1); int l=a[1].l,r=a[1].l; cnt[seq[l-1]]++; tot=cnt[k^seq[a[1].l]]; cnt[seq[l]]++; for (int i=1;i<=q;i++) { while (l<a[i].l) { cnt[seq[l-1]]--; tot-=cnt[k^seq[l-1]]; l++; } while (l>a[i].l) { l--; tot+=cnt[k^seq[l-1]]; cnt[seq[l-1]]++; } while (r<a[i].r) { r++; tot+=cnt[k^seq[r]]; cnt[seq[r]]++; } while (r>a[i].r) { cnt[seq[r]]--; tot-=cnt[k^seq[r]]; r--; } ans[a[i].id]=tot; } for (int i=1;i<=q;i++) printf("%I64d\n",ans[i]); return 0;}
0 0
- [CF617E]XOR and Favorite Number
- XOR and Favorite Number
- cf XOR and Favorite Number
- E. XOR and Favorite Number
- 【CodeForces617E】XOR and Favorite Number
- Codeforces 617E XOR and Favorite Number
- 【codeforce】XOR and Favorite Number 莫队
- [Codeforces617E]XOR and Favorite Number(莫队)
- Codeforces 617E XOR and Favorite Number
- codeforces 617E XOR and Favorite Number
- Codeforces 617E XOR and Favorite Number 【莫队】
- CF 617E(XOR and Favorite Number-莫队算法)
- Codeforces Round #340 (Div. 2) E XOR and Favorite Number
- Codeforces617 E . XOR and Favorite Number(莫队算法)
- Codeforces 617E:XOR and Favorite Number 莫队算法
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number
- codeforces 617E XOR and Favorite Number (莫队)
- 莫队算法 Codeforces617E XOR and Favorite Number
- 前端-网站文件、资源优化
- Unity的50个使用技巧(2016 Edition)
- Kali Linux 网络扫描秘籍 第七章 Web 应用扫描(一)
- java项目编码问题解决
- [leetcode]19. Remove Nth Node From End of List
- [CF617E]XOR and Favorite Number
- 深度网络pre-train对于深度网络的意义
- C++实现的访问者模式
- Android Modem修改点以及修改方法
- this运算符
- 无刷电机控制器
- D3.js symbol 符号生成器
- 结构体初始化
- 6款免费的PDF解锁软件