GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — code-library/Math/FWHT.cpp at master · SuckSolace/code-library Expand file tree/ Copy pathFWHT.cppMore file actions 76 lines (74 loc) · 2.37 KB / Copy pathFWHT.cppFile metadata and controls76 lines (74 loc) · 2.37 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 #include<bits/stdc++.h> using namespace std; const int N = 3e5 + 9, mod = 1e9 + 7; int POW(long long n, long long k) { int ans = 1 % mod; n %= mod; if (n < 0) n += mod; while (k) { if (k & 1) ans = (long long) ans * n % mod; n = (long long) n * n % mod; k >>= 1; } return ans; } const int inv2 = (mod + 1) >> 1; #define M (1 << 20) #define OR 0 #define AND 1 #define XOR 2 struct FWHT{ int P1[M], P2[M]; void wt(int *a, int n, int flag = XOR) { if (n == 0) return; int m = n / 2; wt(a, m, flag); wt(a + m, m, flag); for (int i = 0; i < m; i++){ int x = a[i], y = a[i + m]; if (flag == OR) a[i] = x, a[i + m] = (x + y) % mod; if (flag == AND) a[i] = (x + y) % mod, a[i + m] = y; if (flag == XOR) a[i] = (x + y) % mod, a[i + m] = (x - y + mod) % mod; } } void iwt(int* a, int n, int flag = XOR) { if (n == 0) return; int m = n / 2; iwt(a, m, flag); iwt(a + m, m, flag); for (int i = 0; i < m; i++){ int x = a[i], y = a[i + m]; if (flag == OR) a[i] = x, a[i + m] = (y - x + mod) % mod; if (flag == AND) a[i] = (x - y + mod) % mod, a[i + m] = y; if (flag == XOR) a[i] = 1LL * (x + y) * inv2 % mod, a[i + m] = 1LL * (x - y + mod) * inv2 % mod; // replace inv2 by >>1 if not required } } vector<int> multiply(int n, vector<int> A, vector<int> B, int flag = XOR) { assert(__builtin_popcount(n) == 1); A.resize(n); B.resize(n); for (int i = 0; i < n; i++) P1[i] = A[i]; for (int i = 0; i < n; i++) P2[i] = B[i]; wt(P1, n, flag); wt(P2, n, flag); for (int i = 0; i < n; i++) P1[i] = 1LL * P1[i] * P2[i] % mod; iwt(P1, n, flag); return vector<int> (P1, P1 + n); } vector<int> pow(int n, vector<int> A, long long k, int flag = XOR) { assert(__builtin_popcount(n) == 1); A.resize(n); for (int i = 0; i < n; i++) P1[i] = A[i]; wt(P1, n, flag); for(int i = 0; i < n; i++) P1[i] = POW(P1[i], k); iwt(P1, n, flag); return vector<int> (P1, P1 + n); } }t; int32_t main() { int n; cin >> n; vector<int> a(M, 0); for(int i = 0; i < n; i++) { int k; cin >> k; a[k]++; } vector<int> v = t.pow(M, a, n, AND); int ans = 1; for(int i = 1; i < M; i++) ans += v[i] > 0; cout << ans << '\n';; return 0; } // https://csacademy.com/contest/archive/task/and-closure/statement/ |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |