zoukankan      html  css  js  c++  java
  • hdu 5683 zxa and xor 暴力

    zxa and xor

    Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


    Problem Description
    zxa had a great interest in exclusive disjunction(i.e. XOR) recently, therefore he took out a non-negative integer sequence a1,a2,,an of length n.

    zxa thought only doing this was too boring, hence a function funct(x,y) defined by him, in which ax would be changed into y irrevocably and then compute 1i<jn(ai+aj) as return value.

    zxa is interested to know, assuming that he called such function m times for this sequence, then what is the return value for each calling, can you help him?

    tips:1i<jn(ai+aj) means that (a1+a2)(a1+a3)(a1+an)(a2+a3)(a2+a4)(a2+an)(an1+an).
     
    Input
    The first line contains an positive integer T, represents there are T test cases.

    For each test case:

    The first line contains two positive integers n and m.

    The second line contains n non-negative integers, represent a1,a2,,an.

    The next m lines, the i-th line contains two non-negative integers x and y, represent the i-th called function is funct(x,y).

    There is a blank between each integer with no other extra space in one line.

    1T1000,2n2104,1m2104,0ai,y109,1xn,1n,m105
     
    Output
    For each test case, output in m lines, the i-th line a positive integer, repersents the return value for the i-th called function.
     
    Sample Input
    1 3 3 1 2 3 1 4 2 5 3 6
     
    Sample Output
    4 6 8
    Hint
    After the first called function, this sequence is ${4,2,3}$, and $(4+2)otimes(4+3)otimes(2+3)=4$. After the second called function, this sequence is ${4,5,3}$ and $(4+5)otimes(4+3)otimes(5+3)=6$. After the third called function, this sequence is ${4,5,6}$ and $(4+5)otimes(4+6)otimes(5+6)=8$.
    思路:通过位运算一些简单性质,暴力;(居然不会超时。。。)
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000009
    #define inf 999999999
    #define esp 0.00000000001
    //#pragma comment(linker, "/STACK:102400000,102400000")
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF ) return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    int a[100010];
    int main()
    {
        int x,y,z,i,t;
        scanf("%d",&x);
        while(x--)
        {
            scanf("%d%d",&y,&z);
            for(i=1;i<=y;i++)
            scanf("%d",&a[i]);
            int sum=0;
            for(i=1;i<=y;i++)
            for(t=i+1;t<=y;t++)
            sum^=(a[i]+a[t]);
            while(z--)
            {
                int pos,change;
                scanf("%d%d",&pos,&change);
                for(i=1;i<=y;i++)
                {
                    if(i!=pos)
                    sum^=(a[i]+change)^(a[i]+a[pos]);
                }
                printf("%d
    ",sum);
                a[pos]=change;
            }
        }
        return 0;
    }
  • 相关阅读:
    linux 下载openssl 亲测有效
    在linux文件中 怎么查看文件的行数
    linux 安装mysql 数据库
    bccomp
    javascript之date
    javascript之函数
    JavaScript数据类型之数组
    BOM
    canvas
    javascript数据类型之对象
  • 原文地址:https://www.cnblogs.com/jhz033/p/5496382.html
Copyright © 2011-2022 走看看