2015北京网络赛 J Scores

题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据

思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂。bitset之前没用过,查了下发现其实就是一个二进制表示,这里的每一位就表示原序中的状态。

    建一个bitset<50000> bs[6][sqrt(50000)], bs[i][j] 就表示在第i维上前j个块中的数据在原序中是哪些位置。

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 50005
using namespace std;
struct Node{
int x, pos;
};
bitset<MAXN> bs[][];
int t[];
bitset<MAXN> res[], w;
bool compare(Node a, Node b){
return a.x < b.x;
}
Node s[][MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int T;
int n, m;
scanf("%d", &T);
while (T--){
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++){
for (int j = ; j <= ; j++){
scanf("%d", &s[j][i].x);
s[j][i].pos = i;
}
}
for (int i = ; i <= ; i++){
sort(s[i] + , s[i] + + n, compare);
}
int u = sqrt(n);
int num = n / u;
if (n % u != ){
num++;
}
memset(bs, , sizeof(bs));
for (int i = ; i <= ; i++){
for (int j = ;j <= num; j++){
bs[i][j] |= bs[i][j - ];
int left = (j - ) * u + , right = j * u;
if (right > n){
right = n;
}
for (int k = left; k <= right; k++){
bs[i][j][s[i][k].pos] = ;
}
}
}
int ans = ;
int q;
scanf("%d", &q);
while (q--){
for (int i = ; i <= ; i++){
scanf("%d", &t[i]);
t[i] ^= ans;
}
for (int i = ; i <= ; i++){
int left = , right = n;
while (left < right){
int mid = (left + right) >> ;
if (s[i][mid].x > t[i]){
right = mid;
}
else{
left = mid + ;
}
}
int pos;
if (s[i][left].x > t[i]){
pos = left - ;
}
else{
pos = left;
}
int u_pos = (pos - ) / u;
res[i] = bs[i][u_pos];
for (int j = u_pos * u + ; j <= pos; j++){
res[i][s[i][j].pos] = ;
}
}
w = res[];
for (int i = ; i <= ; i++){
w &= res[i];
}
ans = w.count();
printf("%d\n", ans);
}
}
}

2015北京网络赛 J Scores bitset+分块的更多相关文章

  1. hihocoder1236(北京网络赛J):scores 分块+bitset

    北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...

  2. 2015北京网络赛 J Clarke and puzzle 求五维偏序 分块+bitset

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc20 ...

  3. hihocoder 1236(2015北京网络赛 J题) 分块bitset乱搞题

    题目大意: 每个人有五门课成绩,初始给定一部分学生的成绩,然后每次询问给出一个学生的成绩,希望知道在给定的一堆学生的成绩比这个学生每门都低或者相等的人数 因为强行要求在线查询,所以题目要求,每次当前给 ...

  4. 2015北京网络赛 Couple Trees 倍增算法

    2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道.  解法来自 q ...

  5. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...

  6. Hiho coder 1236 2015 北京网络赛 Score

    五维偏序..一开始被吓到了,后来知道了一种BITSET分块的方法,感觉非常不错. 呆马: #include <iostream> #include <cstdio> #incl ...

  7. 2015北京网络赛 F Couple Trees 暴力倍增

    Couple Trees Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/123 ...

  8. 2015北京网络赛A题The Cats' Feeding Spots

    题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...

  9. 2015北京网络赛 G题 Boxes bfs

    Boxes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingonl ...

随机推荐

  1. LAMP环境搭建备忘 -- MariaDB 安装(三)

    因为 MySQL 的一些原因,在 Linux 平台上的开源数据库渐渐被 MariaDB 取代. MariaDB 安装命令如下图 安装成功后,接下来就启动这个数据库服务 我们还需要对数据库做一些初始化的 ...

  2. 浅谈 MySQL的外键的作用

    MySQL中外键的介绍: MySQL外键必须使用存储引擎为  innDB  其中MySAM 和MEMORYH这两种引擎不支持 由数据库自身保证数据一致性,完整性,更可靠,因为程序很难100%保证数据的 ...

  3. Linux学习之计算机基础理论

    一.描述计算机的组成及其功能. 计算机系统是由硬件系统(hardware)和软件系统(software system)两部分组成. 硬件系统: 从硬件基本结构上来讲,计算机是由运算器.控制器.存储器. ...

  4. 重载和const形参

    1.int lookup(string p); 2.int lookup(const string p);//同1 3.int lookup(string *);//传入一个指针,指针指向string ...

  5. 【Henu ACM Round#24 E】Connected Components

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 要求把连续的一段li..ri的边全都删掉. 然后求剩下的图的联通数 如果暴力的话 复杂度显然是O(k*m)级别的. 考虑我们把li. ...

  6. jquery validate验证remote时的多状态问题

    因为远程验证用户名时可能会出现几种错误情况: 1.用户名字符非法: 2.长度超限: 3.用户名已经存在: 但remote返回的内容只能是布尔型的,即使用dataFilter来过滤也不知道如何对应的把错 ...

  7. [javase学习笔记]-7.6 thiskeyword的原理

    这一节我们来讲一个keyword.就是thiskeyword. 我们还是通过样例来看吧: class Person { private String name; private int age; Pe ...

  8. [ACM] hdu 4248 A Famous Stone Collector (DP+组合)

    A Famous Stone Collector Problem Description Mr. B loves to play with colorful stones. There are n c ...

  9. 写给自己的Java程序员学习路线图_转载

    如下是我做开发这三年经常使用一些技术和工具,当然这些技术也都是需要加强的(有些是我一直使用的,不过不深入,有些内部的原理等等不是很清楚) 前端部分: 1)HTML:网页的核心语言,构成网页的基础 2) ...

  10. c# protected public private internal

    1 internal 只能在一个项目中引用,不能跨项目引用,只有在同一程序集的文件中 2 public 最高级别的访问权限 对访问公共成员没有限制 3 private 最低级别的访问权限 只能在声明它 ...