제출 #503121

#제출 시각아이디문제언어결과실행 시간메모리
503121LucaIlieXOR (IZhO12_xor)C++17
0 / 100
2044 ms916 KiB
#include <iostream>
#include <set>

using namespace std;

#define MAX_N 100000
#define MAX_LOG_A 30

int v[MAX_N + 1];

int main() {
    int n, a, x, y, temp, maxLen, poz, p, i, j;

    maxLen = 0;
    poz = -1;
    cin >> n >> x;
    for ( i = 1; i <= n; i++ ) {
        cin >> a;

        v[i] = v[i - 1] ^ a;
        //printf( "%d ", v[i] );

        y = 0;
        for ( p = MAX_LOG_A; p >= 0; p-- ) {
            if ( x & (1 << p) ) {
                if ( (v[i] & (1 << p)) == 0 )
                    y += (1 << p);

            } else {
                temp = y;
                if ( v[i] & (1 << p) )
                    y += (1 << p);
                else
                    temp += (1 << p);
                for ( j = 0; j < i; j++ ) {
                    if ( temp <= v[j] && v[j] <= temp + (1 << p) - 1 ) {
                        if ( i - j > maxLen ) {
                            maxLen = i - j;
                            poz = j + 1;
                        } else if ( i - j == maxLen ) {
                            if ( j + 1 < poz )
                                poz = j + 1;
                        }
                    }
                }
            }
        }
        for ( j = 0; j < i; j++ ) {
            if ( (v[j] ^ v[i]) == x ) {
                if ( i - j > maxLen ) {
                    maxLen = i - j;
                    poz = j + 1;
                } else if ( i - j == maxLen ) {
                    if ( j + 1 < poz )
                        poz = j + 1;
                }
            }
        }
    }

    cout << poz << " " << maxLen;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...