Clarke and puzzle

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://hihocoder.com/contest/acmicpc2015beijingonline/problem/10

Description

Kyle is a student of Programming Monkey Elementary School. Just as others, he is deeply concerned with his grades.

Last month, the school held an examination including five subjects, without any doubt, Kyle got a perfect score in every single subject.

There are n students took part in this examination(not including Kyle), and everyone got an integer between 1 to m as the score of one subject.

Now, looking at the grade table of these n students, Kyle wants to know how many students still did no better than him even if his scores are something else – Here, “no better” means there is no subject in which the student got strictly greater score than Kyle.

Input

There are multiple test cases.

The first line of the input contains an integer T (T <= 3) which means the number of test cases.

The first line of each test case contains two integers, n, m(n, m≤ 50,000), which are the number of students and the perfect score of each subject.

In the next n lines, each line consists of five integers, indicating a student’s scores.

Then one line follows. This line contains an integer q(q≤ 50,000) indicating the number of queries.

In the next q lines, each line contains five integers as well, representing a query. Each query indicates a set of scores, and for each query, you should figure out that if Kyle's grade is this set of scores, how many students still did no better than him. But for the sake of security, only the first query is in its original form, and other queries are encrypted. To decrypt a query, you must let each integer in the query do xor operation with the answer of last query. It's guaranteed that all the decrypted queries contain integers between 1 and 50000.

Output

For each test case, you should output q lines as the answer for all queries.

Sample Input

2
2 3
1 1 1 1 1
2 2 2 2 2
2
1 1 1 1 1
3 3 3 3 3
3 5
1 1 1 1 1
1 1 1 1 1
1 2 3 4 5
2
1 1 1 1 1
1 1 1 1 1

Sample Output

1
2
2
2

HINT

In case 1, there are two students with different scores and the scores of the first student (1, 1, 1, 1, 1) are not larger than the first query (1 1 1 1 1) in every subject, so the answer for this query is 1.

After having xor operation with the last answer 1, the second query (3,3,3,3,3) will be decrypted into (2, 2, 2, 2, 2). Because both students’ scores are no better than  (2, 2, 2, 2, 2), so the answer for query 2 is 2.

题意

求五维偏序,强制在线

题解:

首先,如果维数低的话,就直接裸着跑kdtree就好了。

但是这个有五维,所以kdtree就不要想了

我写的是分块+bitset

我预处理5*sqrt(n)个bitset,bitset[i][j]表示在第i维,当前排名为j*sqrt(n)的时候的bitset的样子

那么每次询问的时候,我们就可以从最近的bitset里面转移过来就好了

对于每一个case,预处理的复杂度是O(n)的,询问的复杂度是5*sqrt(n),所以跑过去了~

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1006
#define mod 1000000007
#define eps 1e-9
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* bitset<> b[][];
bitset<> Ans[];
int now[];
struct node
{
int x,y;
};
bool cmp(node a,node b)
{
return a.x<b.x;
}
node a[][];
int l[],r[];
int belong[];
int main()
{
int t;scanf("%d",&t);
for(int cas=;cas<=t;cas++)
{
int n=read(),m=read();
for(int i=;i<=;i++)
for(int j=;j<;j++)
b[i][j].reset();
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++)
{
a[j][i].x=read();
a[j][i].y=i;
}
}
for(int i=;i<=;i++)
sort(a[i]+,a[i]+n+,cmp);
int block = sqrt(n);
int num = n/block;
if(n%block)num++;
for(int i=;i<=num;i++)
l[i]=(i-)*block+,r[i]=i*block;
r[num]=n;
for(int i=;i<=n;i++)
belong[i]=(i-)/block+;
for(int i=;i<=;i++)
{
for(int j=;j<=num;j++)
{
b[i][j]|=b[i][j-];
for(int k=l[j];k<=r[j];k++)
b[i][j][a[i][k].y]=;
}
} int q=read();
int lastans = ;
while(q--)
{
for(int i=;i<=;i++)
now[i]=read();
for(int i=;i<=;i++)
now[i]^=lastans;
for(int i=;i<=;i++)
Ans[i].reset();
for(int i=;i<=;i++)
{
int L = ,R = n;
while(L<=R)
{
int mid = (L+R)/;
if(now[i]>=a[i][mid].x)
L = mid+;
else
R = mid-;
}
int p = L-;
if(p==)continue;
Ans[i]|=b[i][belong[p]-];
for(int j=l[belong[p]];j<=p;j++)
Ans[i][a[i][j].y]=;
}
Ans[] = Ans[]&Ans[]&Ans[]&Ans[]&Ans[];
lastans = Ans[].count();
printf("%d\n",lastans);
}
}
}

2015北京网络赛 J Clarke and puzzle 求五维偏序 分块+bitset的更多相关文章

  1. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

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

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

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

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

  4. 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 ...

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

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

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

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

  7. acm 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北京网络赛 F Couple Trees 暴力倍增

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

随机推荐

  1. poj1226,poj3080

    看来以后用pascal的函数要小心了: 简简单单pos其实时间复杂度是二次方级的…… 今天学习的是KMP——字符匹配算法: 这两道题也都很简单,都是为这个算法练手的, 最朴素的匹配显然是穷举起始位置然 ...

  2. 解决项目中EF5.0升级到EF6.0无法安装包的方法

    今天在vs2012上新建了一个mvc4的项目,mvc4中默认的Entity Framework是5.0的版本,如下所示: 或者:,但是项目中有些要用到EF6.0的相关方法,用EF5.0实在繁琐,于是在 ...

  3. UVA 11082 Matrix Decompressing 矩阵解压(最大流,经典)

    题意: 知道矩阵的前i行之和,和前j列之和(任意i和j都可以).求这个矩阵.每个格子中的元素必须在1~20之间.矩阵大小上限20*20. 思路: 这么也想不到用网络流解决,这个模型很不错.假设这个矩阵 ...

  4. 【jQuery】jQuery操作<input>的聚焦与全选其内容

    实现效果: 源代码: $(function() { $("#exist_code_remind").attr("style","display:non ...

  5. ejabberd源码流程梳理

    ejabberd的工程主要通过ejabberd.app 组织起来 ejabberd.erl : application:start(ejabberd). ejabberd_app.erl: Mod:s ...

  6. 使用SVN小结

    自从加入团队后,开始使用SVN,以下是个人对SVN的一些认识和小结. 一.SVN是什么? SVN是版本管理工具,譬如团队进行项目开发,项目代码都储存在服务器上,成员可用SVN在本地获得并更新代码. 二 ...

  7. 在Linux运行期间升级Linux系统(Uboot+kernel+Rootfs)

    版本:v1.2   Crifan Li 摘要 本文主要介绍了如何在嵌入式Linux系统运行的时候,进行升级整个Linux系统,包括uboot,kernel和rootfs.以及简介Linux中的已有的通 ...

  8. JSON--List集合转换成JSON对象

    转自:http://www.cnblogs.com/xmaomao/p/3184542.html 1. 简单的手动放置 键值对 到JSONObject,然后在put到JSONArray对象里 List ...

  9. HDU 5007 Post Robot

    Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  10. POJ3281 Dining 最大流

    题意:有f种菜,d种饮品,每个牛有喜欢的一些菜和饮品,每种菜只能被选一次,饮品一样,问最多能使多少头牛享受自己喜欢的饮品和菜 分析:建边的时候,把牛拆成两个点,出和入 1,源点向每种菜流量为1 2,每 ...