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