Submission #499234

# Submission time Handle Problem Language Result Execution time Memory
499234 2021-12-27T13:46:34 Z LucaIlie XOR Sum (info1cup17_xorsum) C++17
7 / 100
1600 ms 8124 KB
#include <iostream>
#include <algorithm>
#include <math.h>

#define MAX_N 1000000

using namespace std;

int v[MAX_N], rest[MAX_N];

int countLower( int v[], int n, int a ) {
    int st, dr, mij;

    st = 0;
    dr = n;
    while ( dr - st > 1 ) {
        mij = (st + dr) / 2;

        if ( v[mij] > a )
            dr = mij;
        else
            st = mij;
    }

    if ( v[st] > a )
        return 0;
    return st + 1;
}

int main() {
    int n, maxLog2, st, dr, leftR, rightR, res, it, i, p;
    long long nrSume;

    cin >> n;
    maxLog2 = 0;
    for ( i = 0; i < n; i++ ) {
        cin >> v[i];
        if ( log2( v[i] ) > maxLog2 )
            maxLog2 = log2( v[i] );
    }

    res = 0;
    for ( p = 0; p <= maxLog2 + 1; p++ ) {
        for ( i = 0; i < n; i++ )
            rest[i] = v[i] & ((1 << (p + 1)) - 1);
        sort( rest, rest + n );

        it = 0;
        nrSume = 0;
        st = dr = 0;
        for ( i = n - 1; i >= 0; i-- ) {
            leftR = (1 << p) - rest[i];
            if ( leftR < 0 )
                leftR += (1 << (p + 1));
            rightR = (1 << (p + 1)) - 1 - rest[i];
            if ( rightR < 0 )
                rightR += (1 << (p + 1));

            if ( rest[st] > leftR ) {
                if ( st > 0 )
                    it++;
                st = 0;
            }
            while ( st < n && rest[st] < leftR ) {
                st++;
                //it++;
            }

            if ( rest[dr] > rightR ) {
                if ( dr > 0 )
                    it++;
                dr = 0;

            }
            while ( dr < n && rest[dr] <= rightR ) {
                dr++;
                //it++;
            }

            if ( leftR <= rightR ) {
                nrSume += dr - st;
                if ( leftR <= rest[i] && rest[i] <= rightR )
                    nrSume++;
            } else {
                nrSume += n - st + dr;
                if ( leftR <= rest[i] || rest[i] <= rightR )
                    nrSume++;
            }

            if ( st == n )
                st--;
            if ( dr == n )
                dr--;
            if ( it > 2000000 )
                return 1;
        }
        nrSume /= 2;

        if ( nrSume % 2 == 1 )
            res += (1 << p);
    }

    cout << res;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 94 ms 332 KB Output is correct
2 Correct 95 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1670 ms 8124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1670 ms 8124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 332 KB Output is correct
2 Correct 95 ms 312 KB Output is correct
3 Execution timed out 1684 ms 1024 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 332 KB Output is correct
2 Correct 95 ms 312 KB Output is correct
3 Execution timed out 1670 ms 8124 KB Time limit exceeded
4 Halted 0 ms 0 KB -