列表

详情


NC25592. Cards with Numbers

描述

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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 883ms, 内存消耗: 40944K, 提交时间: 2019-06-01 19:19:51

#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int>p;
int main(){
	int n,a,b;
	scanf("%d",&n);
	while(n--){
		scanf("%d %d",&a,&b); 
		if(a==0) p[b]=1;
		 else  printf("%s\n",(p[b])?"yes":"no");
	}
} 

上一题