From 1a3b4008de470b2f05fdaae9625abb3a490dfa0f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 2 Jun 2022 15:55:59 +0800 Subject: [PATCH] =?UTF-8?q?P4462=20[CQOI2018]=E5=BC=82=E6=88=96=E5=BA=8F?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/76790818 --- Luogu/P4462/P4462.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Luogu/P4462/P4462.cpp diff --git a/Luogu/P4462/P4462.cpp b/Luogu/P4462/P4462.cpp new file mode 100644 index 00000000..f324f600 --- /dev/null +++ b/Luogu/P4462/P4462.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m, k, a[N], c[N], t, ans[N]; +std::vector> q; + +void add(int x, int &res) { + c[x]++; + res += c[x ^ k]; +} + +void del(int x, int &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, 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; +}