Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MOD
- vector < pair < int , int > > Hash[MOD];
- void Insert (int x) {
- int key = x % MOD;
- for (size_t it = 0; it < Hash[key].size(); ++it)
- if (Hash[key][it].first == x) {
- Hash[key][it].second ++;
- return;
- }
- Hash[key].push_back({x, 1});
- }
- void Erase (int x) {
- int key = x % MOD;
- vector < pair < int , int > > :: iterator it;
- for (it = Hash[key].begin(); it != Hash[key].end(); ++it)
- if (it -> first == x) {
- it -> second --;
- if (it -> second == 0)
- Hash[key].erase (it);
- return;
- }
- }
- int Search (int x) {
- int key = x % MOD;
- for (auto it : Hash[key])
- if (it.first == x)
- return it.second;
- return 0;
- }
Add Comment
Please, Sign In to add comment