题目链接

 #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 (莫队板子题)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. CodeForces - 617E XOR and Favorite Number 莫队算法

    https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry,  问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...

  8. Codeforces 617E XOR and Favorite Number莫队

    http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...

  9. E. XOR and Favorite Number 莫队 2038: [2009国家集训队]小Z的袜子(hose)

    一直都说学莫队,直到现在才学,训练的时候就跪了   T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来 ...

  10. SP3267 DQUERY - D-query 莫队板子题

    题意可见:https://www.luogu.com.cn/problem/SP3267 可在vj上提交:https://vjudge.net/problem/SPOJ-DQUERY 题意翻译 给出一 ...

随机推荐

  1. APP上线审核注意事项

    基本要点 ·         不能导致手机故障(比如崩溃或屏幕问题) ·         长时间/过度使用之后反应仍然很快 ·         应用内的所有价格信息中不能用固定值代替可变变量 ·    ...

  2. 负载均衡LVS

    可参考:http://ixdba.blog.51cto.com/2895551/555738 http://os.51cto.com/art/201202/319979.html 也可以参考官网:ht ...

  3. Long转换为date

    public static void main(String[] args) { Long time = System.currentTimeMillis(); System.out.println( ...

  4. Appium——WebDriverException: Message: A new session could not be created.

    每次启动完一次脚本再次启动的时候会报这个错误,会话没有被创建 查看了下Appium日志: 查看下设备是否准备好,我用的是模拟器,就cmd下查看下设备: 可以看到设备掉线了... 好吧,重启下设备 脚本 ...

  5. __FILE__,__LINE__,__func__ 真好用,DEBUG利器啊!

    我是不喜欢用类似VC下的F5,F10.曾经很喜欢用.被代码逻辑逼的没招了.所以不喜欢用了. 比如,错误是根据动态数据,产生的行为错误,无论是该写的未写,还是不该写的写了.指针跑飞什么等等,无非就是上述 ...

  6. JMeter参数化设置——通过函数助手

    Now you can know everything in the world, but the only way you're findin' out that one is by givin' ...

  7. 为什要使用预编译SQL?

    今天在研发部技术大牛的指点下,我终于明白了为什么要使用SQL预编译的形式执行数据库JDBC:

  8. 看 迪杰斯特拉(Dijsktra)算法体会

    迪杰斯特拉 看啊哈算法中迪杰斯特拉算法体会: 算法思路 : 1.先找到源头到其他点的最短路: 2.以最短路作为中转点进行比较,用一个dis数组保存源头到他的最优距离 3.用循环进行最优筛选: #inc ...

  9. ZOJ3201(树形DP)

    Tree of Tree Time Limit: 1 Second      Memory Limit: 32768 KB You're given a tree with weights of ea ...

  10. Servlet中init-param与context-param的区别

    web.xml文件中Servlet中配置如下: <servlet> <servlet-name>loginServlet</servlet-name> <se ...