답안 #468239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468239 2021-08-27T10:21:15 Z Killer2501 XOR Sum (info1cup17_xorsum) C++14
100 / 100
748 ms 41060 KB
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e15+7;
const ll N = 1e6+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, c[N], a[N], b[N], h[N], dp[N], cnt, top[N], nchain[N], chain, par[N];
vector<pll> adj[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
bool check(int j)
{
    int l = 0, r = 0;
    if(j)
    {
        b[0] = b[1] = 0;
        for(int i = 0; i < n; i ++)
        {
            k = (a[i] >> (j-1)) & 1;
            ++b[k];
        }
        b[1] += b[0];
        for(int i = n-1; i >= 0; i --)
        {
            k = (a[i] >> (j-1)) & 1;
            c[--b[k]] = a[i];
        }
        for(int i = 0; i < n; i ++)a[i] = c[i];
    }
    int p = n-1;
    for(int i = 0; i < n; i ++)l += ((a[i] >> j) & 1);
    bool ok = 0;
    for(int i = 0; i < n; i ++)
    {

        while(p >= i && (a[i] & ((1<<j)-1)) + (a[p] & ((1<<j)-1)) >= (1<<j))
        {
            r += ((a[p] >> j) & 1);
            l -= ((a[p] >> j) & 1);
            --p;
        }
        if((a[i] >> j) & 1)
        {
            if((r+p-i+1-l)&1)ok = !ok;
        }
        else
        {
            if((l+n-1-p-r)&1)ok = !ok;
        }
        l -= ((a[i] >> j) & 1);
        if(p < i)
        {
            ++p;
            r -= ((a[p] >> j) & 1);
            l += ((a[p] >> j) & 1);
        }
    }
    return ok;
}
void sol()
{
    cin >> n;
    for(int i = 0; i < n; i ++)cin >> a[i];
    for(int i = 0; i < 30; i ++)if(check(i))ans += (1<<i);
    cout << ans;
}
int main()
{
    if(fopen(task".in", "r"))
    {
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
0 1 2
0 2 3
1 3 5
2 4 6
1 1
4 3
*/

Compilation message

xorsum.cpp:11:20: warning: overflow in conversion from 'double' to 'int' changes value from '1.000000000000007e+15' to '2147483647' [-Woverflow]
   11 | const ll mod = 1e15+7;
      |                ~~~~^~
xorsum.cpp: In function 'int main()':
xorsum.cpp:86:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:87:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23876 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 36240 KB Output is correct
2 Correct 570 ms 35400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 36240 KB Output is correct
2 Correct 570 ms 35400 KB Output is correct
3 Correct 628 ms 38368 KB Output is correct
4 Correct 612 ms 37848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23876 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 98 ms 25572 KB Output is correct
4 Correct 93 ms 25644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23876 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 568 ms 36240 KB Output is correct
4 Correct 570 ms 35400 KB Output is correct
5 Correct 628 ms 38368 KB Output is correct
6 Correct 612 ms 37848 KB Output is correct
7 Correct 98 ms 25572 KB Output is correct
8 Correct 93 ms 25644 KB Output is correct
9 Correct 734 ms 41060 KB Output is correct
10 Correct 748 ms 40964 KB Output is correct
11 Correct 746 ms 40964 KB Output is correct