HDU 6085 Rikka with Candies
来源:互联网 发布:python ftplib 编辑:程序博客网 时间:2024/06/05 10:38
因为题目要求答案mod 2,所以类似CS Academy #32的Light Count,将5e4的空间压缩成大概800份,每份空间用64位ULL状压。
对于每个qk,求得多少对ai % bj = qk, 即ai = bj*x+qk && qk<=bj-1.
将q数组和b数组从大到小排序后,枚举qk,如果存在还未使用过的bj>qk,那么类似于素数筛,将0, bj, 2*bj, 3*bj…异或进d数组,如果大于qk的bj都取完了,那么查询qk就相当于将整个d数组右移qk位,并将这个右移过的d数组与a数组进行&操作。
代码:
#include<bits/stdc++.h>using namespace std;#define CLR(A, X) memset(A, X, sizeof(A))typedef unsigned long long LL;const int N = 5e4+5, M = 8e2+5;int b[N], c[N], g[N], ans[N];LL d[M], a[M];void add(LL *f, int pos) { f[pos>>6] ^= (LL)1<<(pos&63); }int query(int t, int m) { int x = t>>6, y = t&63, cnt = 0; for(int i = 0; i < m; i++) { if(i+x < m) cnt ^= __builtin_popcountll(a[i+x]&(d[i]<<y)); else break; if(i+x+1<m && y) cnt ^= __builtin_popcountll(a[i+x+1]&(d[i]>>(64-y))); } return cnt&1;}int main() { int T; scanf("%d", &T); while(T--) { CLR(d, 0); CLR(a, 0); int n, m, q, x, mx = 0; scanf("%d%d%d", &n, &m, &q); for(int i = 0; i < n; i++) { scanf("%d", &x); add(a, x); mx = max(mx, x); } for(int i = 1; i <= m; i++) scanf("%d", &b[i]); for(int i = 1; i <= q; i++) scanf("%d", &c[i]), g[i] = c[i]; sort(b+1, b+m+1); sort(c+1, c+q+1); int i = m, j = unique(c+1, c+q+1)-c-1, mn = (mx>>6)+1; while(i>=1 || j>=1) { while(i>=1 && b[i]>c[j]) { for(int x = 0; x <= mx; x += b[i]) add(d, x); i--; } while(j>=1 && c[j]>=b[i]) ans[c[j]] = query(c[j], mn), j--; } for(int i = 1; i <= q; i++) printf("%d\n", ans[g[i]]); } return 0;}
阅读全文
0 0
- HDU 6085 Rikka with Candies
- HDU 6085 Rikka with Candies
- HDU 6085 Rikka with Candies
- hdu 6085 Rikka with Candies
- Rikka with Candies HDU
- Hdu 6085 Rikka with Candies【思维+Bitset】
- hdu 6085 Rikka with Candies bitset
- HDU 6085 Rikka with Candies 模拟bitset
- HDU 6085 Rikka with Candies (bitset)
- HDU 6085 Rikka with Candies(bitset)
- HDU 6085 Rikka with Candies (bitset)
- HDU 6085 Rikka with Candies (暴力压位)
- HDU 6085 Rikka with Candies 压位 bitset区间提取
- hdu 6085 Rikka with Candies(bitset 计数原理)
- hdu 6085 Rikka with Candies(bitset容器)
- 【多校训练】hdu 6085 Rikka with Candies bitset
- HDU 6085 Rikka with Candies(bitset操作+思路转化)
- hdu 6085 Rikka with Candies bitset优化计数
- HDU6090-思维&构造&贪心&&2017多校5-Rikka with Graph
- Stream
- 20170808
- 566. Reshape the Matrix
- POJ
- HDU 6085 Rikka with Candies
- 极大似然估计与最小二乘法(转自知乎)
- 文本挖掘的学习博客--一系列
- codeforces838B-Diverging Directions
- Python中的math模块
- node.js中Event loop机制
- Manifest merger failed with multiple errors
- 微商真的那么让人讨厌吗? 如果找对了方向就不会了
- 20170808面试问题----SQL优化怎么写