Ankit_132

D

Nov 17th, 2023
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.  
  12.     _test
  13.     {
  14.         int n;
  15.         cin>>n;
  16.  
  17.         vector<ll int> a(n);
  18.         for(auto &e: a)     cin>>e;
  19.  
  20.         ll int ans = 0;
  21.  
  22.         map<int, int> mp;
  23.  
  24.         for(auto e: a)
  25.         {
  26.             ans += mp[e];
  27.             mp[e]++;
  28.  
  29.             if(e == 1)      ans += mp[2];
  30.             if(e == 2)      ans += mp[1];
  31.         }
  32.  
  33.         cout<<ans<<"\n";
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment