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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

CF617E. XOR and Favorite Number

發布時間:2024/4/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CF617E. XOR and Favorite Number 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 /* 2 CF617E. XOR and Favorite Number 3 http://codeforces.com/contest/617/problem/E 4 莫隊算法 5 題意:求l,r區間內異或和為k的對數 6 用times記錄某異或值在當前區間中的個數 7 */ 8 #include <cstdio> 9 #include <algorithm> 10 #include <cstring> 11 #include <cmath> 12 #include <vector> 13 #include <queue> 14 //#define test 15 using namespace std; 16 const int Nmax=1<<20; 17 struct Q 18 { 19 int l,r,id; 20 }q[Nmax]; 21 long long ans[Nmax]; 22 long long Ans; 23 int l=1,r=0; 24 int n,m,k; 25 int num[Nmax]; 26 int pos[Nmax]; 27 long long times[Nmax]; 28 bool cmp(Q a,Q b) 29 { 30 if(pos[a.l]==pos[b.l]) 31 return a.r<b.r; 32 return pos[a.l]<pos[b.l]; 33 } 34 void del(int x) 35 { 36 times[num[x]]--; 37 Ans-=times[num[x]^k]; 38 } 39 void add(int x) 40 { 41 Ans+=times[num[x]^k]; 42 times[num[x]]++; 43 } 44 int main() 45 { 46 #ifdef test 47 #endif 48 scanf("%d%d%d",&n,&m,&k); 49 int sz=sqrt(n); 50 for(int i=1;i<=n;i++) 51 { 52 scanf("%d",&num[i]); 53 num[i]^=num[i-1]; 54 pos[i]=i/sz; 55 } 56 for(int i=1;i<=m;i++) 57 { 58 scanf("%d%d",&q[i].l,&q[i].r); 59 q[i].id=i; 60 } 61 sort(q+1,q+1+m,cmp); 62 times[0]=1LL; 63 for(int i=1;i<=m;i++) 64 { 65 while(l<q[i].l) 66 { 67 del(l-1); 68 l++; 69 } 70 while(l>q[i].l) 71 { 72 l--; 73 add(l-1); 74 } 75 while(r<q[i].r) 76 { 77 r++; 78 add(r); 79 } 80 while(r>q[i].r) 81 { 82 del(r); 83 r--; 84 } 85 ans[q[i].id]=Ans; 86 } 87 for(int i=1;i<=m;i++) 88 printf("%lld\n",ans[i]); 89 return 0; 90 }

?

轉載于:https://www.cnblogs.com/BBBob/p/6636745.html

總結

以上是生活随笔為你收集整理的CF617E. XOR and Favorite Number的全部內容,希望文章能夠幫你解決所遇到的問題。

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