zoukankan      html  css  js  c++  java
  • 2015北京网络赛 J Clarke and puzzle 求五维偏序 分块+bitset

    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-10 ;
    int Num;
    //const int inf=0x7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    bitset<50001> b[7][270];
    bitset<50001> Ans[7];
    int now[7];
    struct node
    {
        int x,y;
    };
    bool cmp(node a,node b)
    {
        return a.x<b.x;
    }
    node a[7][50001];
    int l[300],r[300];
    int belong[50001];
    int main()
    {
        int t;scanf("%d",&t);
        for(int cas=1;cas<=t;cas++)
        {
            int n=read(),m=read();
            for(int i=1;i<=5;i++)
                for(int j=1;j<250;j++)
                    b[i][j].reset();
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=5;j++)
                {
                    a[j][i].x=read();
                    a[j][i].y=i;
                }
            }
            for(int i=1;i<=5;i++)
                sort(a[i]+1,a[i]+n+1,cmp);
            int block = sqrt(n);
            int num = n/block;
            if(n%block)num++;
            for(int i=1;i<=num;i++)
                l[i]=(i-1)*block+1,r[i]=i*block;
            r[num]=n;
            for(int i=1;i<=n;i++)
                belong[i]=(i-1)/block+1;
            for(int i=1;i<=5;i++)
            {
                for(int j=1;j<=num;j++)
                {
                    b[i][j]|=b[i][j-1];
                    for(int k=l[j];k<=r[j];k++)
                        b[i][j][a[i][k].y]=1;
                }
            }
    
            int q=read();
            int lastans = 0;
            while(q--)
            {
                for(int i=1;i<=5;i++)
                    now[i]=read();
                for(int i=1;i<=5;i++)
                    now[i]^=lastans;
                for(int i=1;i<=5;i++)
                    Ans[i].reset();
                for(int i=1;i<=5;i++)
                {
                    int L = 0,R = n;
                    while(L<=R)
                    {
                        int mid = (L+R)/2;
                        if(now[i]>=a[i][mid].x)
                            L = mid+1;
                        else
                            R = mid-1;
                    }
                    int p = L-1;
                    if(p==0)continue;
                    Ans[i]|=b[i][belong[p]-1];
                    for(int j=l[belong[p]];j<=p;j++)
                        Ans[i][a[i][j].y]=1;
                }
                Ans[1] = Ans[1]&Ans[2]&Ans[3]&Ans[4]&Ans[5];
                lastans = Ans[1].count();
                printf("%d
    ",lastans);
            }
        }
    }
  • 相关阅读:
    RabbitMQ 工作图解
    RabbitMQ常用命令
    搭建 .Net RabbitMQ 开发环境
    不使用第三个变量交换两个变量的值
    WEB编程 入门简单 进阶难
    C# 字符串的长度问题
    C# 反射
    C# 拼接字符串的几种方式和性能
    ASP.NET MVC 教程汇总
    SSIS中循环遍历组件[Foreach Loop Container]
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4826769.html
Copyright © 2011-2022 走看看