链接: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. javascript类的简单定义

    在面向对象编程中,类(class)是对象(object)的模板,定义了同一组对象(又称"实例")共有的属性和方法. Javascript语言不支持"类",但是可 ...

  2. web项目的实质

    web项目的实质 web项目的实质其实也就是在用户发过来一个请求后,我们返回一个响应. 用户看到的页面就是我们响应中的响应体(里面是html代码). 所以,我们整个项目的所有操作都是围绕着怎么来写好这 ...

  3. 分享知识-快乐自己:IDEA 导入(web)项目并部署到 Tomcat

    IDEA 导入 (WEB)项目并部署到 Tomcat 1):导入 Web 项目 2):首先更改 JDK 环境  右键项目: 第一步:点击 Modules  第二步:点击 Libraries 第三步:点 ...

  4. CentOS 7编译安装Tengine+PHP+MariaDB全程笔记

    安装环境:CentOS7 3.10.0-693.5.2.el7.x86_64 准备源码包: pcre-8.41.tar.gz openssl-1.0.1h.tar.gz zlib-1.2.11.tar ...

  5. UOJ_21_【UR #1】缩进优化_数学

    UOJ_21_[UR #1]缩进优化_数学 题面:http://uoj.ac/problem/21 最小化$\sum\limits{i=1}^{n}a[i]/x+a[i]\;mod\;x$ =$\su ...

  6. bzoj 4278 Tasowanie 后缀数组+贪心

    题目大意 给定两个数字串A和B,通过将A和B进行二路归并得到一个新的数字串T,请找到字典序最小的T.\(len \leq 200000\) 题解 我们从归并排序的角度去想,每次把两者之一较小的取出来 ...

  7. windows下搭建绿色nodejs运行环境

    无意中在网上看到NodeJS的文章,发现最近还挺火的,正好我也是做技术的,那就下载个玩玩呗,试试它的魅力,也来亲自感受下. 网上nodejs的环境的搭建到处都是,我这里就不说了,今天我想通过我自己的环 ...

  8. CRC16算法之三:CRC16-CCITT-MODBUS算法的java实现

    CRC16算法系列文章: CRC16算法之一:CRC16-CCITT-FALSE算法的java实现 CRC16算法之二:CRC16-CCITT-XMODEM算法的java实现 CRC16算法之三:CR ...

  9. 闪回之 Flashback Data Archive

    背景:Oracle 11g 中 Flashback Data Archive 特性.将变化数据另外存储到创建的闪回归档区(Flashback Archive)中,以和 undo 区别开来,这样就可以为 ...

  10. HDU4348:To the moon

    浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227. ...