hihoCoder 1236 Scores(2015北京赛区网络赛)

时间限制: 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


题目大意:
    
      给n个人,每人有5科成绩,给出q个成绩查询,输出5科都比要查询的这5科低的数目,还有最重要的一点,查询

的成绩是与上次查询结果相异或的值。

解题思路:

     首先题目说要5科都要要比查询的小,于是我们把比要查询的都找出来,用二进制标记一下,于是5科都比要查询

小就转化成5位相与,结果是真就为真,可以用bitset来做。但是这题的n和q比较大,直接算复杂度有点高,可以用分

块来做,对每一科,排好序后,分成sqrt(n)块,由于是排好序的,每块继承前面比它小的,这样就不用查询前面比它

小的,只需要查询它所在的那一块就可以了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <bitset>
using namespace std;
const int maxn=50000+100;
struct node
{
    int v,cur;
    bool operator<(const node& sc)const{
        if(v==sc.v)return cur<sc.cur;
        return v<sc.v;
    }
    node(int v,int cur):v(v),cur(cur){
    }
    node(){
    }
}a[6][maxn];
bitset<maxn> b[6][500];
bitset<maxn> ans;
bitset<maxn> temp;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=5;j++)
            {
                scanf("%d",&a[j][i].v);
                a[j][i].cur=i;
            }
        }
        for(int i=1;i<=5;i++)
        sort(a[i]+1,a[i]+n+1);
        int sqrn=sqrt(n);
        for(int i=1;i<=5;i++)
        {
            for(int j=1;(j-1)*sqrn<n;j++)
            {
                b[i][j].reset();
                b[i][j]=b[i][j-1];
                int st=(j-1)*sqrn;
                for(int k=1;k<=sqrn&&st+k<=n;k++)
                {
                    b[i][j].set(a[i][st+k].cur);
                }
            }
        }
        int q;
        scanf("%d",&q);
        int pre=0;
        int bq[6];
        while(q--)
        {
            for(int i=1;i<=5;i++)
            {
                scanf("%d",&bq[i]);
                bq[i]^=pre;
            }
            ans.reset();
            for(int i=1;i<=5;i++)
            {
                int tmp=lower_bound(a[i]+1,a[i]+n+1,node(bq[i],n+1) )-(a[i]+1);
               // cout<<tmp<<endl;
                tmp=tmp/sqrn;
                temp=b[i][tmp];
                for(int j=tmp*sqrn+1;a[i][j].v<=bq[i]&&j<=n;j++)
                {
                    temp.set(a[i][j].cur);
                }
                if(i==1)
                ans=temp;
                else
                ans &= temp;
            }

            int cou=ans.count();
            pre=cou;
            printf("%d\n",cou);
        }
    }
    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值