0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:16:28 +00:00

CF617E XOR and Favorite Number

https://www.luogu.com.cn/record/76791807
This commit is contained in:
Baoshuo Ren 2022-06-02 16:16:11 +08:00
parent 1a3b4008de
commit 9cff9ca490
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

75
Luogu/CF617E/CF617E.cpp Normal file
View File

@ -0,0 +1,75 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e6 + 5;
int n, m, k, a[N], t;
long long c[N], ans[N];
std::vector<std::tuple<int, int, int>> q;
void add(int x, long long &res) {
res += c[x ^ k];
c[x]++;
}
void del(int x, long long &res) {
c[x]--;
res -= c[x ^ k];
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = a[i - 1] ^ a[i];
}
t = sqrt(n);
for (int i = 1, l, r; i <= m; i++) {
cin >> l >> r;
q.push_back(std::make_tuple(i, l, r));
}
std::sort(q.begin(), q.end(), [&](auto a, auto b) {
int p = std::get<1>(a) / t,
q = std::get<1>(b) / t;
int x = std::get<2>(a),
y = std::get<2>(b);
return p == q ? p & 1 ? x < y : x > y : p < q;
});
int i = 0, j = 1;
long long res = 0;
for (auto &e : q) {
int id, l, r;
std::tie(id, l, r) = e;
while (i < r) add(a[++i], res);
while (i > r) del(a[i--], res);
while (j < l - 1) del(a[j++], res);
while (j > l - 1) add(a[--j], res);
ans[id] = res;
}
for (int i = 1; i <= m; i++) {
cout << ans[i] << endl;
}
return 0;
}