MORE XOR

Given a sequence of nnn numbers a1,a2,⋯ ,ana_1, a_2, \cdots, a_na1​,a2​,⋯,an​ and three functions.Define a function f(l,r)f(l,r)f(l,r) which returns ⊕a[x]\oplus a[x]⊕a[x] (l≤x≤rl \le x \le rl≤x≤r). The ⊕\oplus⊕ represents exclusive OR.Define a function g(l,r)g(l,r)g(l,r) which returns ⊕f(x,y)(l≤x≤y≤r)\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)w(l,r) which returns ⊕g(x,y)(l≤x≤y≤r)\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, ji,j) (1≤i≤j≤n1 \le i \le j \le n1≤i≤j≤n). For each xor-query (i,j)(i, j)(i,j), you have to answer the result of function w(l,r)w(l,r)w(l,r).InputLine 111: t(1≤t≤20)t (1 \le t \le 20)t(1≤t≤20).For each test case:Line 111: n(1≤n≤100000)n (1 \le n \le 100000)n(1≤n≤100000).Line 222: nnn numbers a1,a2,⋯ ,an(1≤ai≤109)a_1, a_2, \cdots, a_n (1 \le a_i \le 10^9)a1​,a2​,⋯,an​(1≤ai​≤109).Line 333: q(1≤q≤100000)q (1 \le q \le 100000)q(1≤q≤100000), the number of xor-queries.In the next qqq lines, each line contains 222 numbers i,ji, ji,j representing a xor-query (1≤i≤j≤n)(1 \le i \le j \le n)(1≤i≤j≤n).It is guaranteed that sum of nnn and q≤106q \le 10^6q≤106.OutputFor each xor-query (i,j)(i, j)(i,j), print the result of function w(i,j)w(i,j)w(i,j) in a single line
样例输入
5
1 2 3 4 5
5
1 3
1 5
1 4
4 5
3 5
样例输出
4
0
1
4
g(i,j):当区间长度为偶数时为零,为奇数时是区间中第1,3,5,7,9,,,,奇数位数的数的异或和
w(i,j):区间长度为len=j-i+1
若len%4=0 值为0
若len%4=1 值为区间中4k+1位数的数的异或和
若len%4=2 值为区间中4k+1和4k+2位数的数的异或和
若len%4=3 值为区间中4k+3位数的数的异或和

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+20;
int a[N],b[N];
int main()
{
    int t,n,m,i,j,q,l,r,sum;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        memset(b,0,sizeof(b));
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(i=1;i<=n;i++)
        {
            if(i<=4)
                b[i]=a[i];
            else
                b[i]=a[i]^b[i-4];
        }
        scanf("%d",&q);
        while(q--)
        {
            scanf("%d%d",&l,&r);
            m=r-l+1;
            if(m%4==0)
            {
                cout<<"0"<<'\n';
                continue;
            }
            else if(m%4==1)
            {
                sum=b[r];
                if(l-4>=0)
                    sum^=b[l-4];
                cout<<sum<<'\n';
            }
            else if(m%4==3)
            {
                sum=b[r-1];
                if(l-3>=0)
                    sum^=b[l-3];
                cout<<sum<<'\n';
            }
            else
            {
                sum=b[r]^b[r-1];
                if(l-4>=0)
                    sum^=b[l-4];
                if(l-3>=0)
                    sum^=b[l-3];
                cout<<sum<<'\n';
            }
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#!/usr/bin/env python # visit https://tool.lu/pyc/ for more information # Version: Python 3.8 import base64 import marshal import sympy as sp encoded_data = b'#VVVVVVVVVVVVVVVVVVVVVSVVVVFVVVV_YZVVVVMVU|VNFV@pU|V{xUMVYvVzBSMVDSVFRVMFDSV\\VQMV@%7fVAxPMFU{V@BPp]vU%B_MF]eVy]VMFY|UxZUVFUbTPBSMVrSVFRVMV%7fCVT|]N^VVVVVVVVVVVVVVVpVVVVPVVVVFVVV_GFVVVVsVU'V@FUpPSVO\'TMV].V$FUMVPSVBFVOC".U_SqV]/UU|VQU/V_RsV]/V^ZUQpVMVUtVMVR@V_'SqV]/Vo|VqV]/UU|VVpU/VyRGVU/VySGVUoPPFTUVU.U_'SsVXSV_'QqVQRVQ&pqFM/UPFSQU|VENVqFE/V$TqVFMVUtVMVR@V_'SqV]/Vo|VqV]/UU|VVpU/VyRGVU/VySGVU/VyTqVFMV_TqVZMVUtVMVR@VU|VqFs/UvVRqVM/U'RVxFRUV_QfqVACVT|RCb|VVFVV!FVVVVSgVFVVVT|Q%pEdvOY'%pAnN@"yMsxSuPAb%p{~rOE{NO]nNOyvUzQtPAbMT|^%pYeMO{vTOUdN@{bsPA#sYxUB.xUvcxUvAx\\N%{vPAnsPA#sYxRN%%7f%7ftcxUv!|Vtp/VVVS!UzM&u~"rsx[tzZ\'O%AbN$]"t_FUVVVVtoVVVVVVFUUV^ZVDVU_V^^VFNTTVRZVEVUPpRNVEVTt%7fRVVVUmTVVVPA#N@&uPAqv%A"tnxVVVSN{U!ez%M\'!&&VP ez!UZmA.\'X"g^\'/NUcvXd.TPRTTD!&UB\\dT.R}Q{!QQUdr~UguyU&sTU"u$An^PMdN@t!rpA&sPNcXQxSr@Am@p]bu'#gT_^EVVVVtp|VVVUvU@YxM@Ye%pAtz{bsYxQv@"sOCvUzAbN%.|MsxRMzo%7fM&x]M@"}ty{sPA|tp/VVVUnSVVV_^GVVVVt%7fVVVVSvTSocu%E&uPB<VFVVV_ZFVVVVTUFRVFFTTVRZVpxTTVR\Vp**' xor_key = int(input('Plz input key (0<key<100):')) x = sp.symbols('x') f = x ** 2 + x + 1 integral_value = sp.integrate(f, (x, 1, xor_key)) check_value = 13024 if integral_value * 3 == check_value: xor_decoded_data = bytes((lambda .0: [ byte ^ xor_key for byte in .0 ])(encoded_data)) decoded_data = base64.b64decode(xor_decoded_data) code_obj = marshal.loads(decoded_data) exec(code_obj) else: print('Wrong!!') 解出code_obj
最新发布
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值