Little Xor(CF-252A)

Problem Description

Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of all numbers from this segment was maximal possible. Help him with that.

The xor operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.

Output

Print a single integer — the required maximal xor of a segment of consecutive elements.

Examples

Input

5
1 2 1 1 2

Output

3

Input

3
1 2 7

Output

7

Input

4
4 2 4 8

Output

14

Note

In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.

The second sample contains only one optimal segment, which contains exactly one array element (element with index three).

题意:给出一个长度为 n 的正整数序列,求异或和最大的连续子段和

思路:由于异或具有前缀和的性质,因此求前缀和后暴力找最大的区间即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int a[N];
int sum[N];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]^a[i];
    }

    int res=0;
    for(int i=1; i<=n; i++)
        for(int j=i; j<=n; j++)
            res=max(res,sum[j]^sum[i-1]);

    printf("%d\n",res);

    return 0;
}

 

以下是一个C语言的MD5校验函数的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c)))) void md5(const uint8_t *initial_msg, size_t initial_len, uint8_t *digest) { // These vars will contain the hash uint32_t h0, h1, h2, h3; // Message (to prepare) uint8_t *msg = NULL; // Note: All variables are unsigned 32 bit and wrap modulo 2^32 when calculating // r specifies the per-round shift amounts uint32_t r[] = { 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 }; // Use binary integer part of the sines of integers (in radians) as constants// Initialize variables: uint32_t k[] = { 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 }; // Pre-processing: // append "1" bit to message // append "0" bits until message length in bits ≡ 448 (mod 512) // append length mod (2^64) to message // (Prepended "0" bits are represented by adding a whole extra block) uint32_t initial_len_bits = initial_len * 8; // compute number of bytes mod 64 uint32_t initial_len_mod64 = initial_len % 64; // compute number of padding bytes uint32_t padding_len = initial_len_mod64 < 56 ? 56 - initial_len_mod64 : 120 - initial_len_mod64; // allocate array for message with padding and a 64-bit length block appended uint32_t new_len = initial_len + padding_len + 8; msg = (uint8_t *)malloc(new_len); memcpy(msg, initial_msg, initial_len); // append the "1" bit msg[initial_len] = 0x80; // append padding bytes for (uint32_t i = initial_len + 1; i < new_len - 8; i++) { msg[i] = 0x00; } // append length in bits for (uint32_t i = 0; i < 8; i++) { msg[new_len - 8 + i] = (uint8_t)(initial_len_bits >> (i * 8)); } // Process the message in successive 512-bit chunks: // for each 512-bit chunk of message: // break chunk into sixteen 32-bit words w[i], 0 ≤ i ≤ 15 // Initialize hash value for this chunk: // a = h0 // b = h1 // c = h2 // d = h3 // Main loop: // for i from 0 to 63 // if 0 ≤ i ≤ 15 then // f = (b and c) or ((not b) and d) // g = i // else if 16 ≤ i ≤ 31 // f = (d and b) or ((not d) and c) // g = (5×i + 1) mod 16 // else if 32 ≤ i ≤ 47 // f = b xor c xor d // g = (3×i + 5) mod 16 // else if 48 ≤ i ≤ 63 // f = c xor (b or (not d)) // g = (7×i) mod 16 // Be wary of the below definitions of a,b,c,d // rotate left function definition // Let [abcd k s i] denote the operation // a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s) // Do the following 16 operations in order: // [ABCD 0 7 1] [DABC 1 12 2] [CDAB 2 17 3] [BCDA 3 22 4] // [ABCD 4 7 5] [DABC 5 12 6] [CDAB 6 17 7] [BCDA 7 22 8] // [ABCD 8 7 9] [DABC 9 12 10] [CDAB 10 17 11] [BCDA 11 22 12] // [ABCD 12 7 13] [DABC 13 12 14] [CDAB 14 17 15] [BCDA 15 22 16] // Perform the following 16 operations in order: // [ABCD 1 5 17] [DABC 6 9 18] [CDAB 11 14 19] [BCDA 0 20 20] // [ABCD 5 5 21] [DABC 10 9 22] [CDAB 15 14 23] [BCDA 4 20 24] // [ABCD 9 5 25] [DABC 14 9 26] [CDAB 3 14 27] [BCDA 8 20 28] // [ABCD 13 5 29] [DABC 2 9 30] [CDAB 7 14 31] [BCDA 12 20 32] // Perform the following 16 operations in order: // [ABCD 5 4 33] [DABC 8 11 34] [CDAB 11 16 35] [BCDA 14 23 36] // [ABCD 1 4 37] [DABC 4 11 38] [CDAB 7 16 39] [BCDA 10 23 40] // [ABCD 13 4 41] [DABC 0 11 42] [CDAB 3 16 43] [BCDA 6 23 44] // [ABCD 9 4 45] [DABC 12 11 46] [CDAB 15 16 47] [BCDA 2 23 48] // Perform the following 16 operations in order: // [ABCD 0 6 49] [DABC 7 10 50] [CDAB 14 15 51] [BCDA 5 21 52] // [ABCD 12 6 53] [DABC 3 10 54] [CDAB 10 15 55] [BCDA 1 21 56] // [ABCD 8 6 57] [DABC 15 10 58] [CDAB 6 15 59] [BCDA 13 21 60] // [ABCD 4 6 61] [DABC 11 10 62] [CDAB 2 15 63] [BCDA 9 21 64] // Add this chunk's hash to result so far: // h0 = h0 + a // h1 = h1 + b // h2 = h2 + c // h3 = h3 + d // cleanup free(msg); // Output hash (little endian): for (uint32_t i = 0; i < 4; i++) { digest[i] = (uint8_t)(h0 >> (i * 8)); digest[i + 4] = (uint8_t)(h1 >> (i * 8)); digest[i + 8] = (uint8_t)(h2 >> (i * 8)); digest[i + 12] = (uint8_t)(h3 >> (i * 8)); } } int main(int argc, char **argv) { uint8_t digest[16]; char *msg = "hello world"; md5((uint8_t *)msg, strlen(msg), digest); for (int i = 0; i < 16; i++) { printf("%02x", digest[i]); } printf("\n"); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值