#include <iostream>
#include <map>
using namespace std;
void print(map<int,int>& s)
{
cout << "\nmp = {";
for(auto p = s.begin(); p!= s.end();)
cout << p->first << "->" << p->second << ",}"[++p==s.end()];
}
void print(multimap<int,int>& s)
{
cout << "\nmmp = {";
for(auto p = s.begin(); p!= s.end();)
cout << p->first << "->" << p->second << ",}"[++p==s.end()];
}
int main()
{
map<int,int> s;
s[1]=1, s[2]=4, s[3]=9, s[4]=16, s[5]=25, s[6]=36, s[7]=49;
print(s);
map<int,int> s2 = {{1,11},{2,12},{3,13}};
print(s2);
s.erase(3);
print(s);
map<int,int>::iterator ix = s.find(4);
s.erase(ix);
print(s);
s.erase(s.find(5), s.find(9));
print(s);
cout << "\nCount of 1: " << s.count(1);
cout << "\nCount of 2: " << s.count(2);
print(s);
auto it = s.lower_bound(5);
cout << "\nThe lower bound of 5 is " << it->first << ".";
auto it_pair = s.equal_range(1);
cout << "\nThe bounds of 1 are " << it_pair.first->first << " and " << it_pair.second->first << ".";
multimap<int,int> ms;
ms.insert({1,1});
ms.insert({2,4});
ms.insert({2,9});
ms.insert({2,16});
ms.insert({5,25});
print(ms);
it_pair = ms.equal_range(2);
ms.erase(it_pair.first, it_pair.second);
print(ms);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgcHJpbnQobWFwPGludCxpbnQ+JiBzKQp7CiAgICBjb3V0IDw8ICJcbm1wID0geyI7CiAgICBmb3IoYXV0byBwID0gcy5iZWdpbigpOyBwIT0gcy5lbmQoKTspCiAgICAgICAgY291dCA8PCBwLT5maXJzdCA8PCAiLT4iIDw8IHAtPnNlY29uZCA8PCAiLH0iWysrcD09cy5lbmQoKV07Cn0KCnZvaWQgcHJpbnQobXVsdGltYXA8aW50LGludD4mIHMpCnsKICAgIGNvdXQgPDwgIlxubW1wID0geyI7CiAgICBmb3IoYXV0byBwID0gcy5iZWdpbigpOyBwIT0gcy5lbmQ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ydCh7Miw5fSk7CiAgICBtcy5pbnNlcnQoezIsMTZ9KTsKICAgIG1zLmluc2VydCh7NSwyNX0pOwoJcHJpbnQobXMpOwoJCglpdF9wYWlyID0gbXMuZXF1YWxfcmFuZ2UoMik7CiAgICBtcy5lcmFzZShpdF9wYWlyLmZpcnN0LCBpdF9wYWlyLnNlY29uZCk7CiAgICBwcmludChtcyk7Cn0=
mp = {1->1,2->4,3->9,4->16,5->25,6->36,7->49}
mp = {1->11,2->12,3->13}
mp = {1->1,2->4,4->16,5->25,6->36,7->49}
mp = {1->1,2->4,5->25,6->36,7->49}
mp = {1->1,2->4}
Count of 1: 1
Count of 2: 1
mp = {1->1,2->4}
The lower bound of 5 is 2.
The bounds of 1 are 1 and 2.
mmp = {1->1,2->4,2->9,2->16,5->25}
mmp = {1->1,5->25}