104092024-04-01 21:15:18Valaki2Xorzótáblacpp17Accepted 100/1001.715s35924 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 1e5;

int n, m;
int a[1 + maxn];
int b[1 + maxn];

int len;
int halflen;

struct event {
    int type;
    // 0 - update
    // 1 - query
    int pos;
    bool operator < (const event &other) const {
        if(pos == other.pos) {
            return type < other.type;
        }
        return pos < other.pos;
    }
};

int get_bit(int bit) {
    len = (1ll << (bit + 1));
    halflen = (1ll << bit);
    vector<event> events;
    for(int i = 1; i <= m; i++) {
        int bi = b[i] % len;
        int l = (halflen - bi + 2 * len) % len;
        int r = (len - 1 - bi + 2 * len) % len;
        if(l == 0) {
            events.pb(event{1, r});
        } else {
            if(l <= r) {
                events.pb(event{1, l - 1});
                events.pb(event{1, r});
            } else {
                events.pb(event{1, r});
                events.pb(event{1, l - 1});
                events.pb(event{1, len - 1});
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        int ai = a[i] % len;
        events.pb(event{0, ai});
    }
    sort(events.begin(), events.end());
    int res = 0;
    int cnt = 0;
    for(event e : events) {
        //cout << e.type << " " << e.pos << "; ";
        if(e.type == 0) {
            cnt++;
            cnt %= 2;
        } else {
            res += cnt;
        }
    }
    //cout << " - ";
    res %= 2;
    //cout << bit << " " << res << " - " << (((int) 1e9 >> bit) & 1) << "\n";
    return res;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    int ans = 0;
    for(int j = 0; j < 32; j++) {
        ans += (get_bit(j) << j);
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2000 KiB
2Accepted1.672s30624 KiB
subtask214/14
3Accepted3ms2320 KiB
4Accepted9ms2800 KiB
5Accepted6ms3000 KiB
6Accepted6ms2984 KiB
7Accepted9ms3320 KiB
8Accepted12ms3468 KiB
9Accepted14ms3624 KiB
subtask314/14
10Accepted3ms3436 KiB
11Accepted1.664s34128 KiB
12Accepted1.555s32640 KiB
13Accepted1.708s33992 KiB
14Accepted1.708s33984 KiB
subtask414/14
15Accepted1.111s31628 KiB
16Accepted1.345s32668 KiB
17Accepted1.077s31012 KiB
18Accepted1.455s34116 KiB
19Accepted1.444s34128 KiB
subtask521/21
20Accepted177ms10576 KiB
21Accepted896ms22096 KiB
22Accepted861ms21520 KiB
23Accepted1.269s33672 KiB
24Accepted1.315s33948 KiB
25Accepted950ms35908 KiB
subtask637/37
26Accepted119ms7336 KiB
27Accepted1.276s30584 KiB
28Accepted1.054s21364 KiB
29Accepted1.386s31444 KiB
30Accepted1.712s34424 KiB
31Accepted1.715s34344 KiB
32Accepted1.141s35924 KiB
33Accepted1.71s35524 KiB
34Accepted1.715s35740 KiB