Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <unordered_set>
- #include <unordered_map>
- #include <queue>
- #include <ctime>
- #include <cassert>
- #include <complex>
- #include <string>
- #include <cstring>
- #include <chrono>
- #include <random>
- #include <bitset>
- #include <array>
- using namespace std;
- #ifdef LOCAL
- #define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
- #else
- #define eprintf(...) 42
- #endif
- using ll = long long;
- using ld = long double;
- using uint = unsigned int;
- using ull = unsigned long long;
- template<typename T>
- using pair2 = pair<T, T>;
- using pii = pair<int, int>;
- using pli = pair<ll, int>;
- using pll = pair<ll, ll>;
- mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
- ll myRand(ll B) {
- return (ull)rng() % B;
- }
- #define pb push_back
- #define mp make_pair
- #define all(x) (x).begin(),(x).end()
- #define fi first
- #define se second
- clock_t startTime;
- double getCurrentTime() {
- return (double)(clock() - startTime) / CLOCKS_PER_SEC;
- }
- const int N = 500500;
- const int LOG = 20;
- int cnt[N + 1];
- int a[LOG][N];
- inline int solve(int l, int r) {
- int len = r - l;
- int res = 0;
- for (int k = LOG - 1; k >= 0; k--) if ((len >> k) & 1) {
- res ^= a[k][l];
- l += 1 << k;
- res ^= (cnt[l] ^ cnt[r]) << k;
- }
- return res;
- }
- int main()
- {
- startTime = clock();
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int n, m, x;
- scanf("%d%d", &n, &m);
- while(n--) {
- scanf("%d", &x);
- cnt[x + 1] ^= 1;
- }
- for (int i = 1; i <= N; i++)
- cnt[i] ^= cnt[i - 1];
- for (int k = 0; k < LOG - 1; k++)
- for (int i = 0; i < N; i++) {
- a[k + 1][i] = a[k][i];
- x = i + (1 << k);
- if (x >= N) continue;
- a[k + 1][i] ^= a[k][x];
- a[k + 1][i] ^= (cnt[x] ^ cnt[min(x + (1 << k), N)]) << k;
- }
- for (int k = 1; k <= m; k++) {
- int ans = 0;
- int l = 0;
- while(l < N) {
- ans ^= solve(l, min(N, l + k));
- l += k;
- }
- printf("%d ", ans);
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment