日韩性视频-久久久蜜桃-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在线 | 免费污片在线观看 | 国产一区免费观看 | 久久伊人操 | 奇米影视在线 | 性高潮影院| 噜啪啪| 一个人看的www片免费高清中文 | 亚洲一区二区三区午夜 | 91国产免费看 | 国产精品久久久一区二区三区 | 欧美激情久久久 | 一本色道久久88亚洲精品综合 | 含羞草一区二区三区 | 国产精品一区在线播放 | 久久国产网 | h欧美| 99re国产| 你懂的国产在线 | 免费欧美 | 黑人操欧美人 | 狠狠干老司机 | 国产色在线观看 | 亚洲国产精品久 | 亚洲精品成人 | 免费a级片视频 | 禁漫天堂黄漫画无遮挡观看 | 中文字幕五码 | 亚洲精品日韩av | 三级大片在线观看 | 在线精品播放 | 日韩欧美久久 | 欧美多p | 日韩在线观看视频一区二区 | 成人av手机在线观看 | 公车乳尖揉捏酥软呻吟 | 成人拍拍拍 | 欧美一区二区三区爱爱 | 人妻va精品va欧美va | 久草视频福利在线 | 97超碰网 | 国产精品久久视频 | 污污内射久久一区二区欧美日韩 | 亚洲成人av| 日本人妻换人妻毛片 | 欧美激情精品 | 日韩不卡视频一区二区 | 亚洲区中文字幕 | 中文字幕乱轮 | 午夜宅男网 | 日韩精品大片 | 国产乱真实合集 | 亚洲色图21p | 少妇人妻好深好紧精品无码 | 亚洲精品白浆高清久久久久久 | 欧美大片免费播放器 | 国产精品视频h | 三大队在线观看 | 亚洲av成人精品一区二区三区在线播放 | 国产成人精品一区二区无码呦 | 黄色网页在线 | 成人网视频 | 亚洲不卡在线观看 | 浓精喷进老师黑色丝袜在线观看 | 亚洲色成人网站www永久四虎 | 婷婷超碰| 国产日韩精品suv | 国产一区 在线播放 | 网爆门在线 | 男人操女人免费网站 | 黄色小视频网 | av无码精品一区二区三区宅噜噜 | 精品一区二区久久 | 男人添女人下部高潮视频 | 欧美亚洲另类小说 | 91国产网站| 亚洲国产999| 天堂av一区二区 | jizz日本免费 | 日日操天天操 | 亚洲视频一二三 | 最新日韩视频 | 日韩不卡av在线 | 精品国产免费视频 | 欧美嫩草 | 女人被狂躁c到高潮 | 天天狠天天干 | 黄色av大全 | 男人的网站在线观看 | 伊人国产在线观看 | 精品国产二区三区 | 尹人av| 久久久久久无码精品人妻一区二区 | 天天色综合图片 | 二区国产 | 日韩经典第一页 | 韩国伦理在线看 | 台湾佬av| 亚洲涩涩图 |