E. XOR and Favorite Number (莫队板子题)
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- /********************************************************************/
- const int maxn = 1e5+;
- int n, m, k;
- int a[maxn], belong[maxn];
- ll ans[maxn], flag[maxn*]; //注意这里的flag 要大大大大
- ll now;
- struct node{
- int l, r;
- int id;
- }q[maxn];
- bool cmp(node x, node y){
- if(belong[x.l] == belong[y.l])
- return x.r < y.r;
- return belong[x.l] < belong[y.l];
- }
- void Update(int x){
- now += flag[a[x]^k];
- flag[a[x]]++;
- }
- void Delete(int x){
- flag[a[x]]--;
- now -= flag[a[x]^k];
- }
- int main(){
- n = read(); m = read(); k = read();
- int sz = ceil(sqrt(n));
- for(int i = ;i <= n;i++){
- a[i] = read();
- belong[i] = (i-)/sz;
- }
- //前缀异或
- for(int i = ;i <= n;i++){
- a[i] = a[i-]^a[i];
- }
- for(int i = ;i <= m;i++){
- q[i].l = read(); q[i].r = read();
- q[i].id = i;
- }
- sort(q+, q++m, cmp);
- int l = , r = ;
- now = ;
- flag[] = ;
- for(int i = ;i <= m;i++){
- int id = q[i].id;
- //while里面的顺序是不能随意更改的
- while(l < q[i].l){
- Delete(l-);
- l++;
- }
- while(l > q[i].l){
- l--;
- Update(l-);
- }
- while(r < q[i].r){
- r++;
- Update(r);
- }
- while(r > q[i].r){
- Delete(r);
- r--;
- }
- ans[id] = now;
- }
- for(int i = ;i <= m;i++){
- cout << ans[i] << endl;
- }
- return ;
- }
E. XOR and Favorite Number (莫队板子题)的更多相关文章
- CODEFORCES 340 XOR and Favorite Number 莫队模板题
原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries ...
- Codeforces Round #340 (Div. 2) E XOR and Favorite Number 莫队板子
#include<bits/stdc++.h> using namespace std; <<; struct node{ int l,r; int id; }q[N]; in ...
- Codeforces617 E . XOR and Favorite Number(莫队算法)
XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法
E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...
- codeforces 617E E. XOR and Favorite Number(莫队算法)
题目链接: E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes i ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number —— 莫队算法
题目链接:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 ...
- CodeForces - 617E XOR and Favorite Number 莫队算法
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry, 问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...
- Codeforces 617E XOR and Favorite Number莫队
http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...
- E. XOR and Favorite Number 莫队 2038: [2009国家集训队]小Z的袜子(hose)
一直都说学莫队,直到现在才学,训练的时候就跪了 T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来 ...
- SP3267 DQUERY - D-query 莫队板子题
题意可见:https://www.luogu.com.cn/problem/SP3267 可在vj上提交:https://vjudge.net/problem/SPOJ-DQUERY 题意翻译 给出一 ...
随机推荐
- apache下实现301永久性重定向的方法
因为博客是使用了www.php100.com作为博客域名,所以想实现php100.com全部重定向(跳转)到www.php100.com.同时按照google的建议,使用服务器端 301 重定向,为了 ...
- SAP 系统账期开关
(1)OB52 财务账期-C 财务维护表 T001B[维护表T001B] (2)OB29 -C FI 财政年变式 (3)MMPV / MMRV -物料账期 MMPV 商品会计期间设置-结帐期间 [ 如 ...
- 【智能无线小车系列八】在树莓派上使用USB网卡
在这个腾“云”驾“物”(云:云计算,物:物联网)的时代,什么都可以没有,就是不能没有网络,树莓派也离不开它.本章节将详细介绍如何将树莓派接入互联网,因为有一些后期将要使用到的小软件需要联网进行下载和安 ...
- PAT天梯赛 L2-026. 小字辈 【BFS】
题目链接 https://www.patest.cn/contests/gplt/L2-026 思路 用一个二维vector 来保存 每个人的子女 然后用BFS 广搜下去,当目前的状态 是搜完的时候 ...
- Linux-正则表达式学习(精)
正则表达式30分钟入门教程 来园子之前写的一篇正则表达式教程,部分翻译自codeproject的The 30 Minute Regex Tutorial. 由于评论里有过长的URL,所以本页排版比较混 ...
- POJ3279 Fliptile —— 状态压缩 + 模拟
题目链接:http://poj.org/problem?id=3279 Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- 模仿yui将css和js打包,加速网页速度
如果你有机会用firebug看看自己网站的网络请求,你会发现请求数量之多超乎你的想象.为减少这个数量,有许多技术方案.比如yui的combo,会将所有需要的js混合成一个文件下载,现代web服务器好像 ...
- 「LuoguP2252」 取石子游戏(威佐夫博弈
[P2252]取石子游戏 - 洛谷 题目背景 无 题目描述 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以 ...
- 洛谷P1967货车运输——倍增LCA
题目:https://www.luogu.org/problemnew/show/P1967 就是倍增LCA的裸题,注意一些细节即可. 代码如下: #include<iostream> # ...
- win7 第一次装 mysql-5.7.16-winx64 ,不知道root 密码,该如何处理?
转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/52851811 ERROR 1045 (28000): Access denied ...