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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【计蒜客 - 2019南昌邀请赛网络赛 - K】MORE XOR(数学,找规律,打表)

發(fā)布時(shí)間:2023/12/10 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【计蒜客 - 2019南昌邀请赛网络赛 - K】MORE XOR(数学,找规律,打表) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Given a sequence of?nn?numbers?a_1, a_2, \cdots, a_na1?,a2?,?,an??and three functions.

Define a function?f(l,r)f(l,r)?which returns?\oplus a[x]⊕a[x]?(l \le x \le rl≤x≤r). The?\oplus⊕?represents exclusive OR.

Define a function?g(l,r)g(l,r)?which returns?\oplus f(x,y)(l \le x \le y \le r)⊕f(x,y)(l≤x≤y≤r).

Define a function?w(l,r)w(l,r)?which returns?\oplus g(x,y)(l \le x \le y \le r)⊕g(x,y)(l≤x≤y≤r).

You are also given a number of xor-queries. A xor-query is a pair (i, ji,j) (1 \le i \le j \le n1≤i≤j≤n). For each xor-query?(i, j)(i,j), you have to answer the result of function?w(l,r)w(l,r).

Input

Line?11:?t (1 \le t \le 20)t(1≤t≤20).

For each test case:

Line?11:?n (1 \le n \le 100000)n(1≤n≤100000).

Line?22:?nn?numbers?a_1, a_2, \cdots, a_n (1 \le a_i \le 10^9)a1?,a2?,?,an?(1≤ai?≤109).

Line?33:?q (1 \le q \le 100000)q(1≤q≤100000), the number of xor-queries.

In the next?qq?lines, each line contains?22?numbers?i, ji,j?representing a xor-query?(1 \le i \le j \le n)(1≤i≤j≤n).

It is guaranteed that sum of?nn?and?q \le 10^6q≤106.

Output

For each xor-query?(i, j)(i,j), print the result of function?w(i,j)w(i,j)?in a single line.

樣例輸入復(fù)制

1 5 1 2 3 4 5 5 1 3 1 5 1 4 4 5 3 5

樣例輸出復(fù)制

2 4 0 1 4

解題報(bào)告:

? ?記錄每個(gè)數(shù)字出現(xiàn)的次數(shù),奇數(shù)次說明這個(gè)數(shù)存在于答案中,偶數(shù)次相當(dāng)于對答案沒有貢獻(xiàn)。打表找規(guī)律發(fā)現(xiàn)跟4的倍數(shù)有關(guān),所以我們預(yù)處理以4為分組的異或和,然后O(1)輸出結(jié)果就可以了。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; ll a[MAX]; ll x0[MAX],x1[MAX],x2[MAX],x3[MAX]; ll all[MAX]; int main() {int t;cin>>t;int n,q;while(t--) {scanf("%d",&n);for(int i = 1; i<=n; i++) {scanf("%lld",a+i);x0[i] = x0[i-1];x1[i] = x1[i-1];x2[i] = x2[i-1];x3[i] = x3[i-1];all[i] = all[i-1]^a[i];if(i%4==0) x0[i] ^= a[i];else if(i%4==1) x1[i] ^= a[i];else if(i%4==2) x2[i] ^= a[i];else if(i%4==3) x3[i] ^= a[i];}scanf("%d",&q);int l,r,len;ll ans;while(q--) {scanf("%d%d",&l,&r);len = r-l+1;if(len%2==0) {if(len%4==0) ans=0;else {if(l%4==0) {ans = x1[r]^x1[l];ans ^= x0[r]^x0[l-1];}else if(l%4==1) {ans = x2[r]^x2[l];ans ^= x1[r]^x1[l-1];}else if(l%4==2) {ans = x3[r]^x3[l];ans ^= x2[r]^x2[l-1];}else if(l%4==3) {ans = x0[r]^x0[l];ans ^= x3[r]^x3[l-1];}}}else {if(len%4 == 1) { if(l%4==0) {ans = x0[r]^x0[l-1]; }else if(l%4==1) {ans = x1[r]^x1[l-1]; }else if(l%4==2) {ans = x2[r]^x2[l-1];}else if(l%4==3) {ans = x3[r]^x3[l-1]; } }else {if(l%4==0) {ans = x1[r]^x1[l-1]; }else if(l%4==1) {ans = x2[r]^x2[l-1]; }else if(l%4==2) {ans = x3[r]^x3[l-1]; }else if(l%4==3) {ans = x0[r]^x0[l-1]; } }}printf("%lld\n",ans);}}return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【计蒜客 - 2019南昌邀请赛网络赛 - K】MORE XOR(数学,找规律,打表)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。