fork download
  1. #include <math.h>
  2. #include <bits/stdc++.h>
  3. typedef long long ll;
  4. using namespace std;
  5. using ull = unsigned long long;
  6. void Code_By_Mohamed_Khaled() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. cout.tie(nullptr);
  10. #ifndef ONLINE_JUDGE
  11. freopen("input.txt", "r", stdin);
  12. freopen("output.txt", "w", stdout);
  13. #endif
  14. }
  15. const ll mod=1e9+7;
  16. ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
  17. ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
  18. ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
  19. ll fast_power(ll base,ll power) {
  20. ll res=1;
  21. while (power>0) {
  22. if (power&1)res=mul(res,base);
  23. base=mul(base,base),power>>=1;
  24. }
  25. return res;
  26. }
  27. int main() {
  28. Code_By_Mohamed_Khaled();
  29. ll t;cin>>t;
  30. while (t--) {
  31. ll n;cin>>n;
  32. vector<ll>v(n);map<ll,ll>mp;
  33. for (auto &it:v)cin>>it,mp[it]++;
  34. if (n==1) {
  35. cout<<0<<"\n";
  36. continue;
  37. }
  38. // cout<<fast_power(2,mp.size())<<"\n";
  39. ll ans=add(fast_power(2,mp.size()),mod-1);
  40. for (auto it:mp) {
  41. if (it.second>1)ans=mul(ans,it.second-1);
  42. }
  43. cout<<add(ans,mod-mp.size())<<"\n";
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5332KB
stdin
3
1
11
3
2 3 5
5
2 2 2 2 2
stdout
0
4
3