博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
F.Cards with Numbers
阅读量:6874 次
发布时间:2019-06-26

本文共 1344 字,大约阅读时间需要 4 分钟。

链接:

题意:

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

你可能感兴趣的文章
我的友情链接
查看>>
WEB服务器错误代码信息对照
查看>>
POJ 3686 The Windy's 最小费用最大流
查看>>
RH124-13 软件包安装与升级
查看>>
我的友情链接
查看>>
1.python入门到精通
查看>>
通过vue-cli来学习修改Webpack多环境配置和发布问题
查看>>
Exchange Server 2013 高可用部署系列(四)邮箱服务器高可用——数据库可用性组(DAG)...
查看>>
和尚挑水的故事给我们带来的思想
查看>>
冯宝丹:终究是一个人。
查看>>
运行时动态改变类的技术
查看>>
Visual Studio的工程依赖
查看>>
ElasticSearch6.5.0 【Java客户端之REST Client】
查看>>
生产环境高并发MySQL SQL语句优化案例
查看>>
Zookeeper工作原理
查看>>
CentOS 7 上systemctl 的用法
查看>>
批量查找包含<?的文件
查看>>
redis使用率100%却还可以写入以及redisti
查看>>
redis 主从切换
查看>>
学会倾听-情商培养
查看>>