hihoCoder 1236
来源:互联网 发布:java工程师任职资格 编辑:程序博客网 时间:2024/06/04 01:13
思路:sqrt(n)分块+bitset优化
第一次写分块,以此纪念
参考代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<set>#include<map>#include<cmath>#include<queue>#include<sstream>#include<string>#include<bitset>using namespace std;typedef long long LL;const LL LINF = (1LL <<63);const int INF = 1 << 31;const int NS = 100010;const int MS = 320;const int MOD = 1000000007;const int KS = 5;struct node{ int id; int v; bool operator < (const node &cmp)const { return v < cmp.v; }};struct scorelist{ int len; node s[NS]; int getPos(int key) { node tmp; tmp.v = key; int pos = upper_bound(s, s + len, tmp) - s; return pos; int mid; int l = 0, r = len - 1; if(s[r].v <= key) return len; while(l < r) { mid = (l + r) >> 1; if(key >= s[mid].v) { l = mid + 1; } else { r = mid; } } return r; }}L[KS];bitset<NS> sco[KS][MS];bitset<NS> cnt[KS];int n, m, num;int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);#endif int nCase, T; scanf("%d", &nCase); for(int T = 1; T <= nCase; T++) { // printf("T = %d\n", T); scanf("%d %d", &n, &m); num = int(sqrt(1.0 * n)); if(num <= 0) num = 1; for(int i = 0; i < n; i++) { for(int k = 0; k < KS; k++) { L[k].s[i].id = i; scanf("%d", &L[k].s[i].v); } } int pos, id; int maxpos = 0; for(int k = 0; k < KS; k++) { L[k].len = n; sort(L[k].s, L[k].s + n);// printf("arr[%d] =", k);// for(int i = 0; i < n; i++)// {// printf(" %d", L[k].s[i].v);// }// puts(""); for(int i = 0; i < n; i++) { pos = i / num; if(pos > maxpos) { maxpos = pos; } if(0 == (i % num)) { sco[k][pos].reset(); if(pos > 0) { sco[k][pos] = sco[k][pos - 1]; } } id = L[k].s[i].id; sco[k][pos][id] = 1; } } int q, lim, last = 0; node qu[MS]; scanf("%d", &q); while(q--) { for(int k = 0; k < KS; k++) { scanf("%d", &qu[k].v); qu[k].v ^= last; lim = L[k].getPos(qu[k].v); cnt[k].reset(); if(n == lim) { cnt[k] = sco[k][maxpos]; } else { if(0 == (lim % num)) { pos = int(lim / num); pos --; if(pos >= 0) { cnt[k] = sco[k][pos]; } } else { pos = int((lim - 1) / num); if(pos > 0) { cnt[k] = sco[k][pos - 1]; } for(int j = pos * num; j < lim; j++) { id = L[k].s[j].id; cnt[k][id] = 1; } } } // cout<<"lim = "<<lim<<" cnt["<<k<<"] = "<<cnt[k].to_string()<<endl; } for(int k = 1; k < KS; k++) { cnt[0] &= cnt[k]; } last = cnt[0].count(); printf("%d\n", last); } } return 0;}/*24 81 1 1 1 12 2 2 2 21 2 3 4 55 4 3 2 121 1 1 1 13 3 3 3 35 81 1 1 1 12 2 2 2 21 2 3 4 55 4 3 2 13 3 3 3 361 1 1 1 12 2 2 2 23 3 3 3 35 5 5 5 51 2 3 4 55 4 3 2 1*/
0 0
- hihocoder 1236
- hihoCoder 1236
- hihocoder #1236 : Scores
- hihoCoder 1236 bitset + 分块
- hihocoder:
- hihoCoder
- Hihocoder
- hihocoder
- hihocoder
- hihocoder
- hihocoder
- hihocoder
- HihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- [noip 2012] 同余方程
- 题目:打劫房屋
- 新人学ruby---ruby中的模块
- LevelDB Log
- ExecutorService、Callable、Future
- hihoCoder 1236
- hiho一下 第六十一周
- 如何使用secureCRT连接vmware中的虚拟主机?
- 路由器登录账号密码忘了,拨号账号密码也忘了,费了点事总算是获取到了
- Timer的缺陷 用ScheduledExecutorService替代
- JDK 源码解析 —— AtomicInteger
- #322 (div.2) D. Three Logos
- STM32入门学习之GPIO(STM32F030F4P6基于CooCox IDE)(寄存器操作版)
- NGUI之按钮置灰