Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order.
The mainly used member functions of maps are:
map <key_type, data_type>
map<string,int> m; //Creates a map m where key_type is of type string and data_type is of type int.
int length = m.size(); //Gives the size of the map.
m.insert(make_pair("hello",9)); //Here the pair is inserted into the map where the key is "hello" and the value associated with it is 9.
m.erase(val); //Erases the pair from the map where the key_type is val.
map<string,int>::iterator itr=m.find(val); //Gives the iterator to the element val if it is found otherwise returns m.end() .
Ex: map<string,int>::iterator itr=m.find("Maps"); //If Maps is not present as the key value then itr==m.end().
To get the value stored of the key "MAPS" we can do m["MAPS"] or
we can get the iterator using the find function and then by itr->second we can access the value.
Try the following example in the editor below.
There are some boxes and each having a unique id. You are given Q queries of three types to be performed on the boxes.
Input Format
Constraints
1 <= Q <= 105
1 <= Y <= 104
1 <= X <= 109
Sample Input
7
1 3 5
1 2 1
2 4
3 3
2 3
3 3
3 2
Sample Output
5
0
1