#include <iostream>
#include <set>
using namespace std;
int main() {
int q;
cin >> q;
set s;
for (int i = 0; i < q; i++) {
int type, num;
cin >> type >> num;
if (type == 1) {
s.insert(num);
} else if (type == 2) {
s.erase(num);
} else if (type == 3) {
set::iterator itr = s.find(num);
if (itr != s.end()) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
return 0;
}
Code Explanation
We start by declaring a set s of integers to store the elements.
The variable q is used to store the number of queries.
We iterate q times to process each query.
For each query, we read the type (type) and number (num) using cin.
If the type is 1, we insert the number into the set using s.insert(num).
If the type is 2, we erase the number from the set using s.erase(num).
If the type is 3, we use s.find(num) to find the iterator to the number in the set.
If the iterator is not equal to s.end(), it means the number is present in the set, so we print "Yes".
If the iterator is equal to s.end(), it means the number is not present in the set, so we print "No".
Finally, we return 0 to indicate successful execution of the program.
Input:
8
1 9
1 6
1 10
1 4
3 6
3 14
2 6
3 6
Output:
Yes
No
No