Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define mp make_pair
  4. #define e1 first
  5. #define e2 second
  6. #define pb push_back
  7. typedef pair <int, int> PII;
  8. typedef unsigned int ui;
  9. typedef unsigned long long int ull;
  10. typedef long long int ll;
  11. typedef double ld;
  12. typedef pair <int, ll> PIL;
  13. typedef pair <ll, int> PLI;
  14. typedef pair <ll, ll> PLL;
  15. const int mod = 1e9+7;
  16. const int inf = 1e9+9;
  17. const ll MOD = 1e9+696969;
  18. const ll INF = ll(1e18) + 3;
  19. #define maxn (1 << 17) + 7
  20. #define maxpot 18
  21. int n, a;
  22. int tab[maxn], pot[maxn], start[maxn];
  23. int dp[maxn];
  24. ll wyn[maxn];
  25. long long swyn;
  26. int stab;
  27. ll w;
  28. void moduluj(int &a)
  29. {
  30.     while (a >= mod) a -= mod;
  31. }
  32. inline int readint()
  33. {
  34.     int x = 0; char zn;
  35.     while (1)
  36.     {
  37.         zn = getchar();
  38.         if (isspace(zn)) return x;
  39.         x = (x << 1) + (x << 3) + zn - '0';
  40.     }
  41. }
  42.  
  43. void rec(int x, int j) {
  44.     for (; j<17 && !(x & pot[j]); j++);
  45.     if (j==17) {
  46.         swyn += wyn[x];
  47.         stab += start[x];
  48.         return;
  49.     }
  50.     rec(x, j + 1);
  51.     rec(x ^ pot[j], j + 1);
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.     n = readint();
  58.     ll DUZO = mod;
  59.     DUZO *= DUZO;
  60.     pot[0] = 1;
  61.     int maks = 0;
  62.     for (int i=1; i<maxn; ++i) pot[i] = (pot[i-1] << 1), moduluj(pot[i]);
  63.  
  64.     for (int i=1; i<=n; ++i)
  65.     {
  66.         int a;
  67.         a = readint();
  68.         tab[a]++;
  69.         start[a]++;
  70.         maks = max(maks, a);
  71.     }
  72.  
  73.     ll wynall = 0;
  74.     wyn[0] = 1;
  75.     for (int i=1; i<pot[17]; ++i)
  76.     {
  77.         swyn = stab = 0;
  78.         rec(i, 0);
  79.         swyn %= mod;
  80.         tab[i] = stab;
  81.         wyn[i] -= swyn;
  82.         wyn[i] += pot[tab[i]];
  83.         wyn[i] += mod;
  84.         wyn[i] %= mod;
  85.         ll w = i;
  86.         ll POMOC = w * w * w  % mod;
  87.         POMOC *= wyn[i];
  88.         wynall += POMOC;
  89.         wynall %= mod;
  90.     }
  91.  
  92.     cout << wynall;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement