F.Cards with Numbers
链接:https://ac.nowcoder.com/acm/contest/908/F
题意:
- 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的更多相关文章
- Codeforces Round #490 (Div. 3) F - Cards and Joy
F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...
- F. Cards and Joy
F. Cards and Joy 题目大意: 给你n个人,每一个人恰好选k张牌. 第一行是 n 和 k 第二行有n*k个数,代表有n*k张牌,每张牌上的数字 第三行有n个数,代表第i个人喜欢的数字 第 ...
- AtCoder Beginner Contest 247 F - Cards // dp + 并查集
原题链接:F - Cards (atcoder.jp) 题意: 给定N张牌,每张牌正反面各有一个数,所有牌的正面.反面分别构成大小为N的排列P,Q. 求有多少种摆放方式,使得N张牌朝上的数字构成一个1 ...
- Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)
题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...
- CF254A Cards with Numbers 题解
Content 有 \(2n\) 个数,让你找出两两相等的 \(n\) 对数的编号,或者方案不存在. 数据范围:\(1\leqslant n\leqslant 3\times 10^5,1\leqsl ...
- 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 ...
- Cards and Joy CodeForces - 999F (贪心+set)
There are nn players sitting at the card table. Each player has a favorite number. The favorite numb ...
- uva10392 Factoring Large Numbers
uva10392 Factoring Large Numbers 本文涉及的知识点是,使用线性筛选法得到素数表. Table of Contents 1 题目 2 思路 3 参考 1 题目 ===== ...
- hdu 4722 Good Numbers 规律 数位dp
#include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...
随机推荐
- ORA-00600: internal error code, arguments: [6749], [3], [12602196]
环境信息:Linux5.8 oracle10.2.0.4 问题现象: 现象1:alert日志有大量下面的错误信息: Wed Aug 27 21:01:27 2014Errors in file /u0 ...
- 使用OGNL表达式
OGNL表达式(#号的用法) 用法1:访问OGNL上下文和Action上下文,#相当于ActionContext.getContext() 1.如果访问其他Context中的对象,由于他们不是根对象, ...
- javaScript运算符之in运算符
- Laravel的三种安装方法总结
Laravel号称巨匠级PHP框架,越来越多的PHPer选择它作为开发框架,作为一个Laravel初学者相信很多人向我一样被安装挡在了门外.所以今天结合文档和自己的学习经历总结一下Laravel的安装 ...
- python下setuptools安装
python下的setuptools带有一个easy_install的工具,在安装python的每三方模块.工具时很有用,也很方便.安装setuptools前先安装pip,请参见<pytho ...
- AtCoder Grand Contest 009 D:Uninity
题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_d 题目翻译 定义只有一个点的树权值为\(0\),若干棵(可以是\(0\)棵)权值为\(k\) ...
- Linq to Object 延迟标准查询操作符
1.Where 操作符用于限定输入集合中的元素,将符合条件的元素组织声称一个序列结果.2.Select 操作符用于根据输入序列中的元素创建相应的输出序列中的元素,输出序列中的元素类型可以与输入序列中 ...
- [poj3450]Corporate Identity(后缀数组)
题意:多个字符串的最长公共子串. 解题关键:字符串的任何一个子串都是这个字符串的某个后缀的前缀.求A和B的最长公共子串等价于求A的后缀和B的后缀的最长公共前缀的最大值. 后缀数组的经典例题,连接在一起 ...
- POJ-3262
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7923 Accepted: ...
- Elasticsearch中提升大文件检索性能的一些总结
笔者在实际生产环境中经常遇到一些大文件的检索,例如一些书籍内容,PDF文件等.今天这篇博客主要来探讨下如何提升ES在检索大文件的一些性能,经验有限,算是一个小小的总结吧! 1.大文件是多大? E ...