Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- typedef pair<int, int> pi;
- #define f first
- #define s second
- #define pb push_back
- #define endl "\n"
- #define yes cout << "YES" << endl
- #define no cout << "NO" << endl
- #define init(x, a) memset(x, a, sizeof(x))
- const int mod1 = 1e9 + 7, mod2 = 998244353, INF = 2e18, N = 2e5 + 5, L = 19;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- // -----------------------------------------------------------------------------
- void solve()
- {
- int n;
- cin >> n;
- vi a(n);
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- int sum = 0;
- // sum of (r-l+1) = r * (cnt[different bit]) - summation of idxs(where different bit is there)
- for (int i = 0; i < 31; i++)
- {
- vi cnt(2, 0), sumidx(2, 0);
- cnt[0] = 1; // else starting from 1 wont be counted
- int cur = 0, pref = 0;
- for (int j = 0; j < n; j++)
- {
- int bit = (a[j] >> i) & 1;
- pref ^= bit; // prefix bit
- int contriR = (cnt[pref ^ 1] * (j + 1)) % mod2;
- cur = (cur + contriR - sumidx[pref ^ 1] + mod2) % mod2;
- cnt[pref]++;
- sumidx[pref] = (sumidx[pref] + (j + 1)) % mod2;
- }
- sum = (sum + ((1LL << i) * cur) % mod2) % mod2;
- }
- cout << sum << endl;
- return;
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment