[MtOI2019]永夜的报应

[MtOI2019]永夜的报应

这个题猛地一看其实是感觉非常难的.
但是,冷静分析一下,你会发现:
因为\(x \: xor \: y \le x + y\),所以说一个子序列一个子序列地异或和加起来肯定大于等于所有数字的异或和.
于是得到答案是所有数字的异或和.愉快 \(AC.\)
当然,卡卡常是为了\(rank\)高一点,毕竟\(IOI\)赛制.

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>

using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;

namespace fastIO {
    #define BUF_SIZE 100000
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};

using namespace fastIO;

template < class T >
    inline void write (T x) {
        if ( x < 0 ) putchar('-') , x = - x ;
        if ( x > 9 ) write ( x / 10 ) ;
        putchar ( x % 10 + '0' ) ;
    }

const int N = 1e6 + 100 ;

int n , v[N] , ans ;

int main() {
    read ( n ) ;
    rep ( i , 1 , n ) read ( v[i] ) , ans ^= v[i] ;
    write ( ans ) ;
    system ("pause") ; return 0 ;
}
posted @ 2019-08-24 16:40  Phecda  阅读(218)  评论(0编辑  收藏  举报

Contact with me