Advertisement
arfin97

ref - map (inserting+traversing:easy way) - Random Sort Gy

Jun 8th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define d(x)                cout << #x << " = " << (x) << endl;
  4. #define fr                  freopen("in.txt", "r", stdin);
  5. #define fw                  freopen("out.txt", "w", stdout);
  6. #define mem(x)              memset((x), 0, sizeof((x)));
  7. #define pb                  push_back
  8. #define LL                  long long
  9. #define fastIO              ios_base::sync_with_stdio(false)
  10. #define sf                  scanf
  11. #define pf                  printf
  12. #define sc1(x)              scanf("%d", &x)
  13. #define sc2(x, y)           scanf("%d %d", &x, &y)
  14. #define sc3(x, y, z)        scanf("%d %d %d", &x, &y, &z)
  15. #define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
  16. #define ROF(i, x, y)        for(int i=int(x-1); i>=int(y); i--)
  17. #define all(c)              c.begin(), c.end()
  18. #define unq(v)              sort(all(v)), (v).erase(unique(all(v)),v.end())
  19. #define siz 1000000
  20. #define MAX 100000
  21. vector<LL> edge[MAX];
  22. vector<LL> cost;
  23. vector<LL> visited(MAX);
  24. vector<LL> dist;
  25. LL ans = 0;
  26. LL taka = INT_MAX;
  27.  
  28. #define mod 7901
  29. map<int, int> mymap;
  30. int facto(int n){
  31.     int fact = 1;
  32.     for(int i = 1; i <= n; i++){
  33.         fact = (fact * i)%mod;
  34.     }
  35.     return fact%mod;
  36. }
  37.  
  38. main(){
  39.     fastIO;
  40.     fr; fw;
  41.     int tc;
  42.     cin >> tc;
  43.     for(int tr = 1; tr <= tc; tr++){
  44.         //clearing map in every iteration
  45.         mymap.clear();
  46.         int n;
  47.         cin >> n;
  48.         int ara[n];
  49.         //Global <int, int> maps has 0 decraled as default in value side of key-value pair
  50.         FOR(i, 0, n) {
  51.             cin >> ara[i];
  52.             mymap[ara[i]]++;
  53.         }
  54.  
  55.        int ans = 1;
  56.        //traversing through map using auto loop
  57.        for(auto p: mymap){
  58.            ans = (ans*facto(p.second))%mod;
  59.        }
  60.         cout << ans%mod << endl;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement