Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define forn(i,n) for (int i = 0; (i) < (n); ++i)
- #define forab(i,a,b) for (int i = (a); (i) < (b); ++i)
- typedef long long LL;
- #define FNAME ""
- const int MAXN = 1e4, MAX = 64;
- int a[MAXN], b[MAXN], c[MAXN], d[MAXN], cnt[MAXN], cur[MAXN], cur2[MAXN];
- LL ans[MAXN];
- inline int add(int a, int m)
- {
- if (a >= m)
- a -= m;
- return a;
- }
- int main()
- {
- #ifdef LOCAL
- freopen(FNAME".in", "r", stdin);
- freopen(FNAME".out", "w", stdout);
- #endif
- int n, m;
- scanf("%d%d", &n, &m);
- forn (i, n)
- scanf("%d", &a[i]);
- forn (i, n)
- scanf("%d", &b[i]), c[i] = a[i] ^ b[i];
- forn (i, n)
- d[i + 1] = d[i] ^ a[i];
- forn (i, n)
- {
- forn (j, MAX)
- cnt[j] = 0, cur[j] = 0, cur2[j] = 0;
- cur[0] = 1;
- int two = 1;
- forab (j, i, n)
- {
- cnt[c[j]]++;
- if (cnt[c[j]] == 1)
- {
- forn (g, MAX)
- cur[g] = (cur[g] * 1ll * two) % m;
- forn (g, MAX)
- cur2[g] = add(cur[g] + cur[g ^ c[j]], m);
- forn (g, MAX)
- cur[g] = cur2[g], cur2[g] = 0;
- ans[j - i + 1] += cur[d[j + 1] ^ d[i]];
- two = 1;
- }
- else
- {
- two = add(two * 2, m);
- ans[j - i + 1] = (ans[j - i + 1] + two * 1ll * cur[d[j + 1] ^ d[i]]);
- }
- }
- }
- forab (i, 1, n + 1)
- printf("%d\n", (int) (ans[i] % m));
- return 0;
- }
Add Comment
Please, Sign In to add comment