Submission #884232

# Submission time Handle Problem Language Result Execution time Memory
884232 2023-12-06T21:15:25 Z aykhn XOR Sum (info1cup17_xorsum) C++17
45 / 100
1600 ms 15956 KB
#include <bits/stdc++.h>
 
// author : aykhn
 
using namespace std;
typedef long long ll;
 
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcountll
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F

const int MXN = 1e5 + 5;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int res = 0;
    for (int j = 0; j <= 30; j++)
    {
        int b[n];
        for (int i = 0; i < n; i++) b[i] = (a[i] & (1 << (j + 1)) - 1);
        sort(b, b + n);
        int c = 0;
        for (int i = 0; i < n; i++)
        {
            int l = lower_bound(b, b + n, (1 << j) - b[i]) - b;
            int r = lower_bound(b, b + n, (1 << (j + 1)) - b[i]) - b;
            l = max(l, i);
            if (l < r) c += r - l;
            l = lower_bound(b, b + n, ((1 << (j + 1)) | (1 << j)) - b[i]) - b;
            r = lower_bound(b, b + n, (1 << (j + 2)) - b[i]) - b;
            l = max(l, i);
            if (l < r) c += r - l;
        }
        if (c & 1) res |= (1 << j);
    }
    cout << res << '\n';
}
// ignore (i + 1 -> 23];
// a[i] &= (1 << (i + 1)) - 1;
// (1 << i) <= a[i] + a[j] < (1 << (i + 1));
// (1 << (i + 1)) | (1 << i) <= a[i] + a[j] < (1 << (i + 2))

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:35:67: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   35 |         for (int i = 0; i < n; i++) b[i] = (a[i] & (1 << (j + 1)) - 1);
      |                                                    ~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 348 KB Output is correct
2 Correct 15 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1665 ms 15956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1665 ms 15956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 348 KB Output is correct
2 Correct 15 ms 372 KB Output is correct
3 Correct 421 ms 2904 KB Output is correct
4 Correct 421 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 348 KB Output is correct
2 Correct 15 ms 372 KB Output is correct
3 Execution timed out 1665 ms 15956 KB Time limit exceeded
4 Halted 0 ms 0 KB -