Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define forn(i, n) for (int i = 0; i < (int)(n); ++i)
- struct randomSet {
- unordered_map<int> m;
- vector<int> v;
- void add(int x) {
- if (m.find(x) != m.end()) {
- return;
- }
- m[x] = v.size();
- v.push_back(x);
- }
- void del(int x) {
- if (m.find(x) == m.end()) {
- return;
- }
- int i = m[x];
- v[i] = v.back();
- v.pop_back();
- m[v[i]] = i;
- }
- int getRand() {
- return v[rand() % v.size()];
- }
- };
- int main() {
- }
Advertisement
Add Comment
Please, Sign In to add comment