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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<bitset> #include<set> using namespace std;
typedef long long ll; #define MAXN 8388610 #define MAXV 8388610 #define pb push_back #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define inf 0x3f3f3f3f #define cmx( a , b ) a = max( a , b ) #define cmn( a , b ) a = min( a , b ) #define upd( a , b ) ( a = ( a + b ) % P ) #define swap( a , b ) a = a ^ b , b = a ^ b , a = a ^ b #define P 1000000007 int n , q; int A[MAXN];
namespace fwt { inline void FWT1(ll a[], int len) { for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j + (mid >> 1)] += a[j]; } inline void IFWT1(ll a[], int len) { for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j + (mid >> 1)] -= a[j]; } inline void FWT2(ll a[], int len) { for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j] += a[j + (mid >> 1)]; } inline void IFWT2(ll a[], int len) { for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j] -= a[j + (mid >> 1)]; } inline void FWT3(ll a[], int len) { for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) { ll x = a[j], y = a[j + (mid >> 1)]; a[j] = x + y, a[j + (mid >> 1)] = x - y; } } inline void IFWT3(ll a[], int len) { for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) { ll x = a[j], y = a[j + (mid >> 1)]; a[j] = (x + y) >> 1, a[j + (mid >> 1)] = (x - y) >> 1; } } ll a[MAXN], b[MAXN]; int input[400010]; int main() { int mx = 0, len = 1; for (int i = 1, x; i <= n; i++) a[A[i]]++, b[A[i]]++, mx = max(mx, A[i]), input[i] = A[i]; while (len <= mx) len <<= 1; if (q == 1) { FWT2(a, len); for (int i = 0; i < len; i++) a[i] = a[i] * a[i]; IFWT2(a, len); for (int i = len - 1; i >= 0; i--) if (a[i]) { ll res = (a[i] - b[i]) >> 1; if (res) return printf("%d %lld", i, res), 0; } } else if (q == 2) { bool flag = true; for (int i = 2; i <= n; i++) if (input[i] != input[1]) { flag = false; break; } if (flag) return printf("0 %lld", (ll)n * (n + 1) / 2), 0; FWT3(a, len); for (int i = 0; i < len; i++) a[i] = a[i] * a[i]; IFWT3(a, len); for (int i = len - 1; i >= 0; i--) if (a[i]) return printf("%d %lld", i, a[i] >> 1), 0; } else { FWT1(a, len); for (int i = 0; i < len; i++) a[i] = a[i] * a[i]; IFWT1(a, len); for (int i = len - 1; i >= 0; i--) if (a[i]) { ll res = (a[i] - b[i]) >> 1; if (res) return printf("%d %lld", i, res), 0; } } }
}
int main() { cin >> n >> q; int mx = 0; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]) , mx = max(A[i] , mx); fwt::main(); }
|