Cards with Number题解

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

输入描述:

The first line of the input is an integer n (1 <= n <= 106), the number of operations. Next n lines represent n operations, and two integers k ( k∈{0,1}) and x (0<=x<=109) are separated by spaces on each line, as described above.

输出描述:

For each query, output one line “yes” if there is a card with the number x in the box, otherwise output one line “no”.

示例1

输入
5
0 1
1 2
0 2
1 3
1 2
输出
no
no
yes

分析:

题目意思很简单,但是数据范围很大,即便我们优化了查找还是会TLE,所以我们可以考虑快读,去加快速度。

#include<bits/stdc++.h>
 
using namespace std;
int Scan(){
    int res = 0, flag = 0;
    char ch;
    if ((ch = getchar()) == '-'){
        flag = 1;
    }
    else if(ch >= '0' && ch <= '9'){
        res = ch - '0';
    }
    while ((ch = getchar()) >= '0' && ch <= '9'){
        res = res * 10 + (ch - '0');
    }
    return flag ? -res : res;
}
unordered_map<int,int>mp;
int main(){
    int t;t=Scan();
     
    while(t--){
        int n,m;
        n=Scan();
        m=Scan();
        //cin>>n>>m;
        if(n==0){
            mp[m]=1;
             
        }else{
            if(mp[m]){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值