链接: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;
}

  

F.Cards with Numbers的更多相关文章

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

    F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...

  2. F. Cards and Joy

    F. Cards and Joy 题目大意: 给你n个人,每一个人恰好选k张牌. 第一行是 n 和 k 第二行有n*k个数,代表有n*k张牌,每张牌上的数字 第三行有n个数,代表第i个人喜欢的数字 第 ...

  3. AtCoder Beginner Contest 247 F - Cards // dp + 并查集

    原题链接:F - Cards (atcoder.jp) 题意: 给定N张牌,每张牌正反面各有一个数,所有牌的正面.反面分别构成大小为N的排列P,Q. 求有多少种摆放方式,使得N张牌朝上的数字构成一个1 ...

  4. Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)

    题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...

  5. CF254A Cards with Numbers 题解

    Content 有 \(2n\) 个数,让你找出两两相等的 \(n\) 对数的编号,或者方案不存在. 数据范围:\(1\leqslant n\leqslant 3\times 10^5,1\leqsl ...

  6. A- Bear and Five Cards(codeforces ROUND356 DIV2)

    A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. Cards and Joy CodeForces - 999F (贪心+set)

    There are nn players sitting at the card table. Each player has a favorite number. The favorite numb ...

  8. uva10392 Factoring Large Numbers

    uva10392 Factoring Large Numbers 本文涉及的知识点是,使用线性筛选法得到素数表. Table of Contents 1 题目 2 思路 3 参考 1 题目 ===== ...

  9. hdu 4722 Good Numbers 规律 数位dp

    #include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...

随机推荐

  1. Mac安装 Storm 小结

    Strom 安装&部署 本地执行:Storm Topology是可进行本地运行的, 必须在发布前进行本地测试, 以确保代码本身业务逻辑没有问题( Windows也可执行, 但是由于权限等原因, ...

  2. python列表切片

    Python中符合序列的有序序列都支持切片(slice),例如列表,字符串,元组. 格式:[start:end:step] start:起始索引,从0开始,-1表示结束 end:结束索引 step:步 ...

  3. selenium中类名不能与方法名相同

    不要将selenium中的类名命名成需要用到的方法名,不然会报错!

  4. L85

    Surgical Never Events Happen Nevertheless Surgeons call them "never events", because they ...

  5. Confd 配置指导

    Quick Start Guide Before we begin be sure to download and install confd. Select a backend confd supp ...

  6. syslog-ng 配置(tcp协议)

    一.概况 两台服务器,都安装syslog-ng,一台服务端,一台客户端: server:192.168.209.19 client:192.168.209.18 二.安装 采用yum安装,执行: yu ...

  7. 14 vue学习 postcssrc eslintrc.js babelrc

    一  .postcssrc.js 众所周知为兼容所有浏览器,有的CSS属性需要对不同的浏览器加上前缀,然而有时添加一条属性,需要添加3~4条类似的属性只是为了满足浏览器的兼容,这不仅会增加许多的工作量 ...

  8. 虚拟机 Linux

    VBox ubuntu安装增强功能

  9. 【239】◀▶IEW-Unit04

    Unit 4 Youth Issues: Computer Use 1 Model1题目及范文分析 Some teenagers spend a lot of time playing compute ...

  10. poi 导出excel 生成等比例图片

    poi 导出的带等比例图片方法 /** * * <p>Description: 将一物一码列表导出到excel</p> * @param response * @param l ...