首页 技术 正文
技术 2022年11月15日
0 收藏 400 点赞 4,877 浏览 3678 个字

#1236 : Scores

时间限制:4000ms单点时限:4000ms内存限制:256MB

描述

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.

输入

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.

输出

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

提示

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.

样例输入
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
样例输出
1
2
2
2
分析:在线求五维偏序点对数;
   考虑bitset存编号,预处理前缀bitset并且分块;
   对于每次询问,每一维可以直接二分得到位置,把当前bitset和剩下的或起来就是当前这一维的;
   最后把五维或起来求count即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
#define inf 0x3f3f3f3f
#define mod 998244353
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
#define ls (rt<<1)
#define rs (rt<<1|1)
#define all(x) x.begin(),x.end()
const int maxn=5e4+;
const int N=4e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qmul(ll p,ll q,ll mo){ll f=;while(q){if(q&)f=(f+p)%mo;p=(p+p)%mo;q>>=;}return f;}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,bl[maxn];
struct node
{
int id,v;
bool operator<(const node&p)const
{
return v<p.v;
}
}a[][maxn];
bitset<maxn>dp[][],ans[];
int main(){
int i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
rep(i,,)rep(j,,)dp[i][j].reset();
rep(i,,n)rep(j,,)
{
scanf("%d",&k);
a[j][i]=node{i,k};
}
rep(i,,)sort(a[i]+,a[i]+n+);
int sz=(int)round(sqrt(n));
rep(i,,n)bl[i]=(i-)/sz+;
rep(i,,)
{
int pos=,go=;
while(++go<=n)
{
pos++;
dp[i][pos]|=dp[i][pos-];
dp[i][pos][a[i][go].id]=;
while(go+<=n&&bl[go+]==bl[go])
{
dp[i][pos][a[i][++go].id]=;
}
}
}
int q,lst=;
scanf("%d",&q);
while(q--)
{
int qu[];
rep(i,,)
{
ans[i].reset();
scanf("%d",&qu[i]);
qu[i]^=lst;
int l=,r=n,ret=;
while(l<=r)
{
int mid=l+r>>;
if(qu[i]>=a[i][mid].v)ret=mid,l=mid+;
else r=mid-;
}
if(!ret)continue;
else
{
ans[i]|=dp[i][bl[ret]-];
for(j=(bl[ret]-)*sz+;j<=ret;j++)ans[i][a[i][j].id]=;
}
}
lst=(ans[]&ans[]&ans[]&ans[]&ans[]).count();
printf("%d\n",lst);
}
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,429
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,245
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,689
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726