Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

# Set and Multiset

#### Set

Sets are containers that store unique elements following a specific order. Here are some of the frequently used member functions of sets:

• Declaration

`set<int>s; //Creates a set of integers.`
• Size:

`int length=s.size(); //Gives the size of the set.`
• insert:

`s.insert(x); //Inserts an integer x into the set s.`
• Erasing an element:

`s.erase(val); //Erases an integer val from the set s.`
• Finding an element:

```set::iterator itr=s.find(val); //Gives the iterator to the element val if it is found otherwise returns s.end() .
Ex: set::iterator itr=s.find(100); //If 100 is not present then it==s.end().```
• Iterating through set
`for(set::iterator itr = s.begin(); itr != s.end(); itr++){    cout<<*itr<<endl; // prints the element in the set  }`

#### Multiset

Multisets are a type of associative containers similar to set, with an exception that multiple elements can have same values.

`multiset<int> ms;`

Removing Element from multiset which have a value multiple times

`ms.erase(val) – Remove all instance of val from multisetms.erase(ms.find(val)) – Remove only one instance of val from multiset`

Example

`#include <bits/stdc++.h>using namespace std; int main(){    multiset<int> ms;    ms.insert(10);    ms.insert(10);    ms.insert(10);     // it will give output 3    cout << ms.count(10) << endl;      // removing single instance from multiset       // it will remove only one value of 10 from multiset    ms.erase(a.find(10));         // it will give output 2    cout << ms.count(10) << endl;      // removing all instance of element from multiset it will remove all instance of value 10    ms.erase(10);        // it will give output 0 because all instance of value is removed from mulitset    cout << a.count(10) << endl;     return 0;}`

All the member function of the multisets are same as sets.

Try the following example in the editor below.

You will be given `Q` queries. Each query is one of the following three types:

• 1 x : Add an element x to the set.
• 2 x : Delete an element `x` from the set. (If the number `x` is not present in the set, then do nothing).
• 3 x : If the number `x` is present in the set, then print "Yes"(without quotes) else print "No"(without quotes).

Alfter processing all queries, if the size of set is greater than 0, print each element (sorted order) in the new line.

Input Format:

First line of the input contains an integer Q denoting the number of queries.
Next Q lines consists of two integers y and x where y is the type of the query and x is an integer.

Constraints

```1 <= Q <= 105
1 <= y <= 31 <= x <= 109```

Sample Input

```7
1 51 41 61 53 42 43 4```

Sample Output

```YesNo
56```
Hints
• Complete Solution

## Discussion

Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer