..拿金了 没给学校丢脸
A
....SB题啊 比赛的时候都没看 裸的一个bitset前缀和
先开一个1e4*1e4的二维bitset数组 初始第i个数组的值为1 << i (即B[i]=1 B[i]<<=i)
很容易我们可以知道要单独翻转某一位而不去影响其他位的话 方法是唯一的
然后我们从可以后往前DP 就可以知道要单独翻转某一位的话需要翻转那些位
最后的每次翻转过后的答案就是 上一个答案^PreL-1 ^PreR
注意用cout的话容易System Error......(再喷一次OJ
/*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}}; const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9; const int MAXN = 1e5 + 5, MAXM = 1e5 + 5, N = 1e4 + 5; const int MAXQ = 100010; int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1; inline void addedge(int u, int v) { to[++tot] = v; nxt[tot] = Head[u]; Head[u] = tot; } inline void read(int &v) { v = 0; char c = 0; int p = 1; while (c < '0' || c > '9') { if (c == '-') { p = -1; } c = getchar(); } while (c >= '0' && c <= '9') { v = (v << 3) + (v << 1) + c - '0'; c = getchar(); } v *= p; } int n, m, l, r; bitset<N> B[10005], pre[10005], ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; read(T); while (T--) { ans.reset(); read(n), read(m); for (int i = 1; i <= n; i++) { B[i].reset(); } B[0] = 1; for (int i = n; i >= 1; i--) { B[i] = 1; B[i] <<= i; for (int j = 2 * i; j <= n; j += i) { B[i] = B[i] ^ B[j]; } } pre[0] = 0; for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] ^ B[i]; } for (int i = 1; i <= m; i++) { read(l), read(r); ans = ans ^ pre[l - 1] ^ pre[r]; printf("%d\n", ans.count()); } } return 0; }