F.Cards with Numbers

链接:https://ac.nowcoder.com/acm/contest/908/F

题意:

AFei has many cards. Each card has a number written on it. Now he wants to takes some out of his card and puts them in a box. And he wants to know whether the card with the number x was in the box. So he has the following two operations:

  • 0 x (It means to put a card with the number x in the box.)
  • 1 x   (It means to query if there is a card with the number x in the box.

思路:

map超时。。离散化,离线处理。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
struct Node
{
    int v, pos;
    bool operator < (const Node& that) const
    {
        return this->v < that.v;
    }
}node[MAXN];
int a[MAXN];
int vis[MAXN];
int op[MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 1;i <= n;i++)
    {
        scanf("%d%d", &op[i], &node[i].v);
        node[i].pos = i;
    }
    sort(node+1, node+1+n);
    int cnt = 1;
    a[node[1].pos] = cnt;
    for (int i = 2;i <= n;i++)
    {
        if (node[i].v == node[i-1].v)
            a[node[i].pos] = cnt;
        else
            a[node[i].pos] = ++cnt;
    }
    for (int i = 1;i <= n;i++)
    {
        if (op[i] == 0)
            vis[a[i]] = 1;
        else
            if (vis[a[i]] == 1)
                printf("yes\n");
            else
                printf("no\n");
    }

    return 0;
}

  

原文地址:https://www.cnblogs.com/YDDDD/p/10960375.html

时间: 2024-08-02 19:19:44

F.Cards with Numbers的相关文章

Codeforces Round #490 (Div. 3) F - Cards and Joy

F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 i 张牌给 j 个人分最大的价值可以得到dp方程如下: dp[ i ][ j ] = max(dp[ i - u ][ j - 1 ] + f[ u ] )   u <= k 暴力转移就好了. #include<bits/stdc++.h> #define LL long long #def

F. Cards and Joy

F. Cards and Joy 题目大意: 给你n个人,每一个人恰好选k张牌. 第一行是 n 和 k 第二行有n*k个数,代表有n*k张牌,每张牌上的数字 第三行有n个数,代表第i个人喜欢的数字 第四行有k个数,代表有如果一个人可以拿到 i 张喜欢的牌,那么快乐值+h[i] 然后就是让你分配这些牌来找最大的欢乐值. 这个题目仔细想想就知道,因为这个h数组是递增的,所以我们就是要尽量把这个人喜欢的牌分配给她. 如果一种牌喜欢的人只有一个,那就把这个类型都给她,但是如果有很多人喜欢一样的牌,那就要

bear and five cards

#include<stdio.h>int main(){    int a[5],flag[2]={1,1},same[2]={0},ans=0;    for(int i=0;i<5;i++)    {        scanf("%d",&a[i]);        ans+=a[i];    }    for(int k=0,i=0;i<5;i++)    {        if(flag[k]>1) k++;        for(int

UVA 11582 Colossal Fibonacci Numbers! 数学

n比较小,最多n*n就回出现循环节.... Colossal Fibonacci Numbers! Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Problem F: Colossal Fibonacci Numbers! The i'th Fibonacci number f (i) is recursively defined in the

rancid install file

What is Rancid ? RANCID monitors a router's (or more generally a device's) configuration,including software and hardware (cards, serial numbers, etc) and uses CVS (Concurrent Version System) or Subversion to maintain history of changes. What RANCID D

codeforces401C

Team CodeForces - 401C Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each

Long Way To Go 之 Python 1

Python是啥? 动态解释性的强类型定义语言.(看球不懂,慢慢理解...以下) 编程语言又有些撒子类型:  编译型.解释型 静态语言.动态语言 强类型定义语言.弱类型定义语言 编译型:(C/C++) Complie:  有一个负责翻译的程序来对源代码进行转换,生成相对应的执行代码 Complier: 负责编译的程序 一次性把code转换成机器语言,然后写成可执行文件 解释型:(Java,Python) 如果说编译时一名书本翻译,解释更像一名同声传译 不断解释,不断执行... ... 动态类型语

python 命令行参数解析

本文是从我另一个博客转载过来的,欢迎大家点击进去看一下,帮我增加点人气^_^ ImPyy 选择模块 根据python参考手册的提示,optparse 已经废弃,应使用 argparse 教程 概念 argparse 模块使用 add_argument 来添加可选的命令行参数,原型如下: ArgumentParser.add_argument(name or flags...[, action][, nargs][, const][, default][, type][, choices][, r

【原创】Python第二章——字符串

字符串是一个字符序列,(提醒:序列是Python的一个重要的关键词),其中存放UNICODE字符.Python中的字符串是不可变的(immutable),即对字符串执行操作时,总是产生一个新的字符串而不是修改现有的字符串. 字符串常量的表示 1. 3种表示 1 #单引号 2 A = 'Python' 3 #引号 4 B = "Python" 5 #三引号 6 C = """Python""" 2. 为什么要这么麻烦? (1)当