Editorial
In this task, you must simulate the operations with the set. Let be the number thought of by Yuri. If is already present in the set, print "Yes" and the size of the set. Otherwise, add to the set, print "No", and the size of the set.
Algorithm realization
Declare a set .
set<int> s;
Read the number of queries .
scanf("%d",&n);
Process the queries sequentially.
for(i = 1; i <= n; i++) {
Read the number that Yuri has thought of.
scanf("%d",&x);
If the number is not in the set , add it to the set, print "No", and the size of the set.
if(s.find(x) == s.end()) { s.insert(x); printf("No %d\n",s.size()); } else
If the number is present in the set , print "Yes" and the size of the set.
printf("Yes %d\n",s.size()); }
Java realization
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); TreeSet<Integer> s = new TreeSet<Integer>(); int n = con.nextInt(); for(int i = 0; i < n; i++) { int x = con.nextInt(); if (s.contains(x)) System.out.println("Yes " + s.size()); else { s.add(x); System.out.println("No " + s.size()); } } con.close(); } }
Python realization
Read the number of queries .
n = int(input())
Declare a set .
s = set({})
Process the queries sequentially.
for _ in range(n):
Read the number that Yuri has thought of.
x = int(input())
If the number is present in the set , print "Yes" and the size of the set.
if x in s: print("Yes", end = ' ') else:
If the number is not in the set , add it to the set, print "No", and the size of the set.
s.add(x) print("No", end = ' ')
After the message "Yes" or "No", print the size of the set.
print(len(s))