Submission #1009493

# Submission time Handle Problem Language Result Execution time Memory
1009493 2024-06-27T15:05:30 Z hahahoang132 XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 15956 KB
#include<bits/stdc++.h>
#define ll long long
#define task " "
using namespace std;
const ll N = 1e6 + 5;
const ll mod = 1e9 + 7;
ll a[N],b[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll i,j;
    for(i = 1;i <= n;i++) cin >> a[i];
    ll ans =  0;
    for(ll id = 0;id <= 30;id++)
    {
        for(i = 1;i <= n;i++) b[i] = a[i] % (1LL << (id + 1));
        sort(b + 1,b + 1 + n);
        ll cnt = 0;
        ll l = n + 1,r = 0,s = n + 1;
        ll t1 = (1LL << id),t2 = (1LL << (id + 1));
        for(i = n;i >= 1;i--)
        {
            if(b[1] + b[i] >= t1) l = i;
            else break;
        }
        for(i = 1;i <= n;i++)
        {
            if(b[1] + b[i] < t2) r = i;
            else break;
        }
        for(i = n;i >= 1;i--)
        {
            if(t1 + t2 - b[1] <= b[i]) s = i;
            else break;
        }
        cnt += max(0LL,r - l + 1) + (n - s + 1);
        for(i = 2;i <= n;i++)
        {
            while(l - 1 >= 1 && b[i] + b[l - 1] >= t1) l--;
            while(b[i] + b[r] >= t2) r--;
            while(s >= 1 && t1 + t2 - b[i] <= b[s - 1]) s--;
            cnt += max(0LL,r - max(l,i) + 1) + (n - max(i,s) + 1);
        }
        if(cnt % 2 == 1) ans = ans ^ (1 << id);
    }
    cout << ans;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:14:10: warning: unused variable 'j' [-Wunused-variable]
   14 |     ll i,j;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2392 KB Output is correct
2 Correct 7 ms 2544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1387 ms 15956 KB Output is correct
2 Correct 1249 ms 15444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1387 ms 15956 KB Output is correct
2 Correct 1249 ms 15444 KB Output is correct
3 Execution timed out 1646 ms 15952 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2392 KB Output is correct
2 Correct 7 ms 2544 KB Output is correct
3 Correct 190 ms 6776 KB Output is correct
4 Correct 186 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2392 KB Output is correct
2 Correct 7 ms 2544 KB Output is correct
3 Correct 1387 ms 15956 KB Output is correct
4 Correct 1249 ms 15444 KB Output is correct
5 Execution timed out 1646 ms 15952 KB Time limit exceeded
6 Halted 0 ms 0 KB -