Gym 100685 A Ariel 位统计

4 篇文章 0 订阅
2 篇文章 0 订阅

A. Ariel
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

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 test(s)
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
output
1
1
1
1
2
1
1
1
3
1
2
2
input
3 2
100 0
10 0
100 0
3
1 0
2 0
3 0
output
1
3
1

题目链接:http://codeforces.com/gym/100685/problem/A

看似1e9,实际约1e8左右的复杂度,然而服务器快,AC= =,没什么好说的。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
#define pll pair<LL, LL>
#define pii pair<int, int>
#define X first
#define Y second
#define MAXN 1050//1e3
#define lson l, mid, (rt << 1)
#define rson mid + 1, r, (rt << 1 | 1)
const double eps = 1e-10;
int n, k, Q;
struct node {
    int score, flag;
    node(int score, int flag) : score(score), flag(flag) {}
    node() {}
} input[10010];
vector<int> vec[MAXN];
void init() {
    for(int i = 0; i < MAXN; i++) {
        vec[i].clear();
    }
}
int get_index(int x, int id) {
    return upper_bound(vec[id].begin(), vec[id].end(), x) - vec[id].begin();
}
int main() {
    while(~scanf("%d%d", &n, &k)) {
        init();
        int cnt, num;
        for(int i = 1; i <= n; i++) {
            scanf("%d%d", &input[i].score, &cnt);
            for(int j = 0; j < cnt; j++) {
                scanf("%d", &num);
                input[i].flag = input[i].flag | (1 << (num - 1));
            }
            vec[input[i].flag].push_back(input[i].score);
        }
        for(int i = 0; i < MAXN; i++) {
            sort(vec[i].begin(), vec[i].end());
        }
        scanf("%d", &Q);
        int id;
        while(Q--) {
            scanf("%d%d", &id, &cnt);
            int flag_sum = 0;
            for(int i = 0; i < cnt; i++) {
                scanf("%d", &num);
                flag_sum = flag_sum | (1 << (num - 1));
            }
            int ans = 0;
            int res = (flag_sum & input[id].flag);
            for(int i = 0; i < MAXN; i++) {
                if((i & flag_sum) == res) {
                    int len = vec[i].size();
                    ans += len - get_index(input[id].score, i);
                }
            }
            printf("%d\n", ans + 1);
        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值