洛谷P4462 [CQOI2018]异或序列(莫队)
程序员文章站
2022-05-14 09:33:13
题意 "题目链接" Sol 一开始以为K每次都是给出的想了半天不会做。 然而发现读错题了维护个前缀异或和然后直接莫队搞就行,。 cpp include define Pair pair define MP(x, y) make_pair(x, y) define fi first define se ......
题意
sol
一开始以为k每次都是给出的想了半天不会做。
然而发现读错题了维护个前缀异或和然后直接莫队搞就行,。
#include<bits/stdc++.h> #define pair pair<int, int> #define mp(x, y) make_pair(x, y) #define fi first #define se second //#define int long long #define ll long long #define fin(x) {freopen(#x".in","r",stdin);} #define fout(x) {freopen(#x".out","w",stdout);} using namespace std; const int maxn = 1e6 + 10, mod = 998244353, inf = 1e9 + 10; const double eps = 1e-9; template <typename a, typename b> inline bool chmin(a &a, b b){if(a > b) {a = b; return 1;} return 0;} template <typename a, typename b> inline bool chmax(a &a, b b){if(a < b) {a = b; return 1;} return 0;} template <typename a, typename b> inline ll add(a x, b y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;} template <typename a, typename b> inline void add2(a &x, b y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);} template <typename a, typename b> inline ll mul(a x, b y) {return 1ll * x * y % mod;} template <typename a, typename b> inline void mul2(a &x, b y) {x = (1ll * x * y % mod + mod) % mod;} template <typename a> inline void debug(a a){cout << a << '\n';} template <typename a> inline ll sqr(a x){return 1ll * x * x;} inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int n, q, k, a[maxn], num[maxn], belong[maxn], block; ll now, ans[maxn]; struct query { int l, r, id; bool operator < (const query &rhs) const { return belong[l] == belong[rhs.l] ? r < rhs.r : belong[l] < belong[rhs.l]; } }q[maxn]; void add(int x) { now += num[k ^ x]; num[x]++; } void delet(int x) { num[x]--; now -= num[k ^ x]; } void solve() { int l = 1, r = 0; for(int i = 1; i <= q; i++) { while(r < q[i].r) add(a[++r]); while(r > q[i].r) delet(a[r--]); while(l < q[i].l) delet(a[l++]); while(l > q[i].l) add(a[--l]); ans[q[i].id] = now; } } signed main() { n = read(); q = read(); k = read(); block = sqrt(n); for(int i = 1; i <= n; i++) a[i] = read() ^ a[i - 1], belong[i] = (i - 1) / block + 1; for(int i = 1; i <= q; i++) q[i].l = read() - 1, q[i].r = read(), q[i].id = i; sort(q + 1, q + q + 1); solve(); for(int i = 1; i <= q; i++) cout << ans[i] << '\n'; return 0; }
上一篇: px妙转rem
下一篇: 全开源ASP.NET工作流快速开发平台