10409 | 2024-04-01 21:15:18 | Valaki2 | Xorzótábla | cpp17 | Accepted 100/100 | 1.715s | 35924 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();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2000 KiB | ||||
2 | Accepted | 1.672s | 30624 KiB | ||||
subtask2 | 14/14 | ||||||
3 | Accepted | 3ms | 2320 KiB | ||||
4 | Accepted | 9ms | 2800 KiB | ||||
5 | Accepted | 6ms | 3000 KiB | ||||
6 | Accepted | 6ms | 2984 KiB | ||||
7 | Accepted | 9ms | 3320 KiB | ||||
8 | Accepted | 12ms | 3468 KiB | ||||
9 | Accepted | 14ms | 3624 KiB | ||||
subtask3 | 14/14 | ||||||
10 | Accepted | 3ms | 3436 KiB | ||||
11 | Accepted | 1.664s | 34128 KiB | ||||
12 | Accepted | 1.555s | 32640 KiB | ||||
13 | Accepted | 1.708s | 33992 KiB | ||||
14 | Accepted | 1.708s | 33984 KiB | ||||
subtask4 | 14/14 | ||||||
15 | Accepted | 1.111s | 31628 KiB | ||||
16 | Accepted | 1.345s | 32668 KiB | ||||
17 | Accepted | 1.077s | 31012 KiB | ||||
18 | Accepted | 1.455s | 34116 KiB | ||||
19 | Accepted | 1.444s | 34128 KiB | ||||
subtask5 | 21/21 | ||||||
20 | Accepted | 177ms | 10576 KiB | ||||
21 | Accepted | 896ms | 22096 KiB | ||||
22 | Accepted | 861ms | 21520 KiB | ||||
23 | Accepted | 1.269s | 33672 KiB | ||||
24 | Accepted | 1.315s | 33948 KiB | ||||
25 | Accepted | 950ms | 35908 KiB | ||||
subtask6 | 37/37 | ||||||
26 | Accepted | 119ms | 7336 KiB | ||||
27 | Accepted | 1.276s | 30584 KiB | ||||
28 | Accepted | 1.054s | 21364 KiB | ||||
29 | Accepted | 1.386s | 31444 KiB | ||||
30 | Accepted | 1.712s | 34424 KiB | ||||
31 | Accepted | 1.715s | 34344 KiB | ||||
32 | Accepted | 1.141s | 35924 KiB | ||||
33 | Accepted | 1.71s | 35524 KiB | ||||
34 | Accepted | 1.715s | 35740 KiB |