답안 #1115138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115138 2024-11-20T06:33:43 Z 12345678 XOR Sum (info1cup17_xorsum) C++17
7 / 100
1600 ms 27288 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

#define ll long long

const int nx=1e5+5;

int n, a[nx], ans;
multiset<int> ms;
map<int, int> mp;

struct segtree
{
    struct node
    {
        node *l, *r;
        int sm;
        node(): l(0), r(0), sm(0){}
    };
    typedef node* pnode;
    pnode rt;
    void update(int l, int r, pnode &k, int idx)
    {
        if (!k) k=new node();
        if (l==r) return k->sm++, void();
        int md=(l+r)/2;
        if (idx<=md) update(l, md, k->l, idx);
        else update(md+1, r, k->r, idx);
        k->sm=((k->l)?(k->l->sm):0)+((k->r)?(k->r->sm):0);
    }
    int query(int l, int r, pnode k, int ql, int qr)
    {
        if (!k||qr<l||r<ql) return 0;
        if (ql<=l&&r<=qr) return k->sm;
        int md=(l+r)/2;
        return query(l, md, k->l, ql, qr)+query(md+1, r, k->r, ql, qr);
    }
    void remove(int l, int r, pnode k)
    {
        if (l==r) return free(k), void();
        int md=(l+r)/2;
        if (k->l) remove(l, md, k->l);
        if (k->r) remove(md+1, r, k->r);
        free(k);
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int bit=0; bit<31; bit++)
    {
        ll cur=0, res=0, mod=(1<<(bit+1));
        s.rt=NULL;
        for (int i=1; i<=n; i++)
        {
            s.update(0, mod-1, s.rt, a[i]%mod);
            int l=((((1<<bit)-a[i])%mod)+mod)%mod, r=(l+(1<<bit)-1)%mod;
            if (l<=r) res+=s.query(0, mod-1, s.rt, l, r);
            else res+=i-s.query(0, mod-1, s.rt, r+1, l-1);
        }
        s.remove(0, mod-1, s.rt);
        //cout<<res<<'\n';
        if (res%2) ans+=(1<<bit);
    }
    cout<<ans;
}

/*
3
1 2 3
*/

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:59:12: warning: unused variable 'cur' [-Wunused-variable]
   59 |         ll cur=0, res=0, mod=(1<<(bit+1));
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 2496 KB Output is correct
2 Correct 75 ms 2528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 2496 KB Output is correct
2 Correct 75 ms 2528 KB Output is correct
3 Execution timed out 1649 ms 27288 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 2496 KB Output is correct
2 Correct 75 ms 2528 KB Output is correct
3 Incorrect 18 ms 1008 KB Output isn't correct
4 Halted 0 ms 0 KB -