Codeforces gym 100685 A. Ariel 暴力

A. Ariel
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100685/problem/A

Description

King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton decides to set up a swimming competition in the kingdom Merfolk. Thousands of creatures come to take part in competition, that's why it is too difficult to take the first place.

For the King's beloved daughter Ariel this competition is the first in her life. Ariel is very kind, so she wants to give a lot of gold medals. Ariel says, that it is unfair to make a single ranking list for creatures that are so different. It is really a good result to be the fastest small fish without tail in Merfolk!

Ariel chooses k important traits (such as size, tailness, rapacity and so on). A creature can either possess a trait or not (there are no intermediate options).

A score is given for each creature (it doesn't matter how it was calculated) and the list of possessed traits f1, ..., fy is also given.

Ariel wants to know the place occupied by creature a in a competition among creatures, who have the same traits h1, ..., ht. So if creature a doesn't have a trait hi, then all creatures in the competition are without this trait. If creature a has a trait hi, then all creatures in the competition have this trait. Other traits doesn't matter. The winner of the competition is a creature with the maximum score.

Input

The first line contains n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 10). The next n lines contain information about creatures: score (1 ≤ score ≤ 109), y (0 ≤ y ≤ k) — the number of possessed traits, and y numbers fi (1 ≤ fi ≤ k) — ids of possessed traits. All fi in one line are different.

The next line contains m (1 ≤ m ≤ 105) — the number of queries from Ariel. The next m lines describe queries: a (1 ≤ a ≤ n) — the id of a creature, then t — the number of traits, then t numbers hi. All hi in one line are different.

 

Output

For each query output the place of a creature a in ranking list amount the corresponded creatures. If several creatures have the same score all of them take the same place.

Sample Input

3 2
100 1 1
50 1 2
30 2 1 2
12
1 2 1 2
1 1 1
1 1 2
1 0
2 0
2 1 1
2 1 2
2 2 2 1
3 0
3 2 1 2
3 1 2
3 1 1

Sample Output

1
1
1
1
2
1
1
1
3
1
2
2

HINT

 

题意

有物种,最多十个特征,并且有分数

然后每次查询,x num hi……hnum

然后问你满足这种特征的生物,这个x的分数排第几

题解

直接傻逼暴力就好了,不要想多了,出题人是懒的,数据是水的

代码

 

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#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 test freopen("test.txt","r",stdin)  
#define maxn 1501
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
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;
}
//**************************************************************************************

vector<int> G[maxn];

struct node
{
    int x,y;
};
node kiss[200001];

int main()
{
    int n=read(),k=read();
    for(int i=0;i<n;i++)
    {
        kiss[i+1].x=read();
        int tmp=0;
        int num=read();
        for(int j=0;j<num;j++)
        {
            int x=read();
            tmp=tmp|(1<<(x-1));
        }
        kiss[i+1].y=tmp;
        G[tmp].push_back(kiss[i+1].x);
    }
    for(int i=0;i<maxn;i++)
        sort(G[i].begin(),G[i].end());
    int m=read();
    for(int i=0;i<m;i++)
    {
        int id=read(),num=read();
        int tmp=0;
        for(int j=0;j<num;j++)
        {
            int x=read();
            tmp=tmp|(1<<(x-1));
        }
        int ans=0;
        for(int i=0;i<maxn;i++)
            if((i&tmp)==(kiss[id].y&tmp))   
                ans+=G[i].size()-(upper_bound(G[i].begin(),G[i].end(),kiss[id].x)-G[i].begin());
        printf("%d\n",ans+1);
    }
}

 

posted @ 2015-08-04 19:18  qscqesze  阅读(481)  评论(0编辑  收藏  举报