Submission #884234

# Submission time Handle Problem Language Result Execution time Memory
884234 2023-12-06T21:27:43 Z aykhn XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 22704 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;
        int i1, i2, i3, i4;
        i1 = i2 = i3 = i4 = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            while (i1 < n && b[i1] < (1 << j) - b[i]) i1++;
            while (i2 < n && b[i2] < (1 << (j + 1)) - b[i]) i2++;
            while (i3 < n && b[i3] < ((1 << (j + 1)) | (1 << j)) - b[i]) i3++;
            while (i4 < n && b[i4] < (1 << (j + 2)) - b[i]) i4++;
            if (max(i1, i) < i2) c += i2 - max(i1, i);
            if (max(i3, i) < i4) c += i4 - max(i3, i);
        }
        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 7 ms 348 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1454 ms 16088 KB Output is correct
2 Correct 1348 ms 19308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1454 ms 16088 KB Output is correct
2 Correct 1348 ms 19308 KB Output is correct
3 Execution timed out 1635 ms 22704 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 184 ms 2000 KB Output is correct
4 Correct 184 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 1454 ms 16088 KB Output is correct
4 Correct 1348 ms 19308 KB Output is correct
5 Execution timed out 1635 ms 22704 KB Time limit exceeded
6 Halted 0 ms 0 KB -