日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces - 617E XOR and Favorite Number (莫队+前缀和)

發布時間:2023/12/18 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces - 617E XOR and Favorite Number (莫队+前缀和) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Bob has a favorite number?k?and?ai?of length?n. Now he asks you to answer?m?queries. Each query is given by a pair?li?and?ri?and asks you to count the number of pairs of integers?i?and?j, such that?l?≤?i?≤?j?≤?r?and the xor of the numbers?ai,?ai?+?1,?...,?ajis equal to?k.

Input

The first line of the input contains integers?n,?m?and?k?(1?≤?n,?m?≤?100?000,?0?≤?k?≤?1?000?000)?— the length of the array, the number of queries and Bob's favorite number respectively.

The second line contains?n?integers?ai?(0?≤?ai?≤?1?000?000)?— Bob's array.

Then?m?lines follow. The?i-th line contains integers?li?and?ri?(1?≤?li?≤?ri?≤?n)?— the parameters of the?i-th query.

Output

Print?m?lines, answer the queries in the order they appear in the input.

Examples

Input 6 2 3
1 2 1 1 0 3
1 6
3 5 Output 7
0 Input 5 3 1
1 1 1 1 1
1 5
2 4
1 3 Output 9
4
4

題意:
詢問區間內異或和剛好為k的字段個數。
思路:
莫隊+前綴和。
這個前綴和比較套路,用的是前綴異或和。
字段【l,r】的異或和就是pre[r]^pre[l-1],
這種情況下我們在莫隊的過程中記錄l,r的pre[i]出現的次數,就可以完成更新了。

注意當L<q[i].l時,要先讓記錄per[L]出現次數的個數減一。 #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #define fuck(x) cout<<#x<<" = "<<x<<endl; #define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl; #define ls (t<<1) #define rs ((t<<1)+1) using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 100086; const int maxm = 1000086; const int inf = 2.1e9; const ll Inf = 999999999999999999; const int mod = 1000000007; const double eps = 1e-6; const double pi = acos(-1); int num[maxm*2],pre[maxn],a[maxn];struct node{int l,r;int id; }q[maxn]; ll ans[maxn]; ll anss; int block;bool cmp(node a,node b){if(a.l/block!=b.l/block){return a.l<b.l;}return a.r<b.r; }int main() {int n,m,k;scanf("%d%d%d",&n,&m,&k);for(int i=1;i<=n;i++){scanf("%d",&a[i]);pre[i]=pre[i-1]^a[i];}block=sqrt(n);for(int i=1;i<=m;i++){scanf("%d%d",&q[i].l,&q[i].r);q[i].id=i;}sort(q+1,q+1+m,cmp);int L=1,R=0;anss=0;num[0]=1;for(int i=1;i<=m;i++){while(L<q[i].l){int t=k^pre[L-1];num[pre[L-1]]--;///注意語句順序anss-=num[t];L++;}while(R>q[i].r){int t=k^pre[R];num[pre[R]]--;anss-=num[t];R--;}while(L>q[i].l){L--;int t=k^pre[L-1];anss+=num[t];num[pre[L-1]]++;}while(R<q[i].r){R++;int t=k^pre[R];anss+=num[t];num[pre[R]]++;}ans[q[i].id]=anss;}for(int i=1;i<=m;i++){printf("%lld\n",ans[i]);}return 0; } View Code

轉載于:https://www.cnblogs.com/ZGQblogs/p/10863851.html

總結

以上是生活随笔為你收集整理的CodeForces - 617E XOR and Favorite Number (莫队+前缀和)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 爱爱激情网 | 麻豆性生活| 欧美日韩亚洲视频 | 免费看av的网址 | 蜜臀久久99精品久久一区二区 | 欧美一二三 | 欧美午夜精品久久久久免费视 | 波多野结衣一区在线 | 国产h视频在线 | 综合色婷婷一区二区亚洲欧美国产 | 日本亚洲天堂 | 国产乱强伦一区二区三区 | 国产精品一区二区人人爽 | 伊人久久大香线蕉成人综合网 | 欧美在线一级片 | 免费黄色大片 | 久久久综合 | 在线观看的黄色网址 | 中文字幕人妻无码系列第三区 | 中文字幕日韩精品亚洲一区小树林 | 亚洲特级片 | 免费av软件 | 日韩精品免费 | 黄色成人在线观看 | 超碰黑人| 亚洲午夜在线视频 | 爱情岛亚洲品质自拍极速福利网站 | 成人一级大片 | 人人超碰在线 | 亚洲精品免费在线观看视频 | 国产污污视频在线观看 | 精品国产高清在线观看 | 亚洲免费一二三区 | 国外成人免费视频 | 成人自拍视频在线观看 | 三级在线看中文字幕完整版 | 狠狠干男人的天堂 | 国产精品骚 | 色诱久久av | 亚洲精品国产欧美在线观看 | 亚洲一区二区免费电影 | 日韩的一区二区 | 国产人免费人成免费视频 | 亚洲免费视| 99热久久这里只有精品 | sm乳奴虐乳调教bdsm | jlzzjlzzjlzz亚洲人| www.污污| 亚洲免费一区视频 | 国产一区二区在线免费 | 免费麻豆视频 | 动漫av在线免费观看 | 涩涩视频网址 | 久久久久网 | 狠狠操影视 | 久久亚洲国产精品 | 亚洲黄色免费在线观看 | 蜜桃臀一区二区三区 | 亚洲av综合色区 | 久久久久久久久蜜桃 | 亚洲天堂网在线观看视频 | 女同久久另类69精品国产 | www久久久| 天天综合入口 | 国产福利社 | 日韩国产免费 | 在线免费观看黄网站 | 国产美女91| 免费一级全黄少妇性色生活片 | 国产欧美精品一区二区色综合朱莉 | 一级黄色片a | 国产无遮挡又黄又爽又色 | 91成人免费在线观看视频 | 亚洲精品久久久 | 日韩欧美激情在线 | 99久久综合| 午夜国产福利在线 | 国产古装艳史毛片hd | 精品福利影院 | 麻豆av免费观看 | 日韩特黄 | 天天操导航 | 欧美另类高清 | av动态 | 亚洲五码在线 | 少妇捆绑紧缚av | 天天干天天操天天干 | 大陆熟妇丰满多毛xxxⅹ | 国产精品亚洲一区 | 骑骑上司妻电影 | 69精品在线观看 | 男男受被啪到高潮自述 | 国产小视频你懂的 | 中国毛片在线 | 黄色一级片免费 | 中文字幕无码人妻少妇免费 | 欧洲久久久久 | 99视频在线免费 | 中文字幕一区二区三区在线观看 |