Submission #499205

# Submission time Handle Problem Language Result Execution time Memory
499205 2021-12-27T12:41:01 Z LucaIlie XOR Sum (info1cup17_xorsum) C++17
45 / 100
1600 ms 8020 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, r, maxLog2, st, dr, res, 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 );
        nrSume = 0;
        for ( i = 0; i < n; i++ ) {
            r = rest[i];

            st = (1 << p) - r;
            if ( st < 0 )
                st += (1 << (p + 1));
            dr = (1 << (p + 1)) - 1 - r;
            if ( dr < 0 )
                dr += (1 << (p + 1));

            if ( st <= dr ) {
                nrSume += countLower( rest, n, dr ) - countLower( rest, n, st - 1 );
                if ( st <= r && r <= dr )
                    nrSume++;
            } else {
                nrSume += n - countLower( rest, n, st - 1 ) + countLower( rest, n, dr );
                if ( st <= r || r <= dr )
                    nrSume++;
            }
        }
        nrSume /= 2;

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

    cout << res;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 336 KB Output is correct
2 Correct 18 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1674 ms 8020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1674 ms 8020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 336 KB Output is correct
2 Correct 18 ms 204 KB Output is correct
3 Correct 632 ms 1096 KB Output is correct
4 Correct 647 ms 2008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 336 KB Output is correct
2 Correct 18 ms 204 KB Output is correct
3 Execution timed out 1674 ms 8020 KB Time limit exceeded
4 Halted 0 ms 0 KB -