104082024-04-01 21:13:55Valaki2Xorzótáblacpp17Time limit exceeded 49/1002.084s36632 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 < 40; j++) {
        ans += (get_bit(j) << j);
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1984 KiB
2Accepted1.791s30708 KiB
subtask214/14
3Accepted3ms2136 KiB
4Accepted12ms2516 KiB
5Accepted6ms2648 KiB
6Accepted7ms2840 KiB
7Accepted10ms2936 KiB
8Accepted14ms2952 KiB
9Accepted16ms3220 KiB
subtask30/14
10Accepted3ms3188 KiB
11Time limit exceeded2.038s33436 KiB
12Accepted1.916s32264 KiB
13Time limit exceeded2.069s17764 KiB
14Time limit exceeded2.062s17816 KiB
subtask414/14
15Accepted1.381s31420 KiB
16Accepted1.705s32280 KiB
17Accepted1.342s30848 KiB
18Accepted1.853s33760 KiB
19Accepted1.848s33700 KiB
subtask521/21
20Accepted221ms10388 KiB
21Accepted1.118s22056 KiB
22Accepted1.103s21600 KiB
23Accepted1.593s33480 KiB
24Accepted1.728s34140 KiB
25Accepted1.274s36008 KiB
subtask60/37
26Accepted148ms7504 KiB
27Accepted1.595s30908 KiB
28Accepted1.335s21892 KiB
29Accepted1.702s32076 KiB
30Time limit exceeded2.062s19204 KiB
31Time limit exceeded2.071s19104 KiB
32Accepted1.381s36632 KiB
33Time limit exceeded2.084s19732 KiB
34Time limit exceeded2.059s19788 KiB