제출 #45673

#제출 시각아이디문제언어결과실행 시간메모리
45673aomeXOR Sum (info1cup17_xorsum)C++17
100 / 100
1317 ms56396 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n; int res; int a[N]; int b[N]; bool p[35][N]; int arr[N]; int f[2][N]; int buf[2][N]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); for (int j = 0; j < 30; ++j) { p[j][i] = a[i] >> j & 1; } } for (int i = 0; i < n; ++i) arr[i] = i; for (int i = 0; i <= 30; ++i) { // cout << "#\n"; // for (int j = 0; j < n; ++j) cout << arr[j] << ' ' << b[arr[j]] << '\n'; for (int j = n - 1; j >= 0; --j) { f[0][j] = f[0][j + 1], f[1][j] = f[1][j + 1]; f[p[i][arr[j]]][j]++; } int cur = 0, ptr = n; int cnt[2]; cnt[0] = cnt[1] = 0; for (int j = 0; j < n; ++j) { if (ptr < j) { cnt[p[i][arr[ptr]]]--, ptr++; } while (ptr > j && b[arr[ptr - 1]] + b[arr[j]] >= (1 << i)) { ptr--, cnt[p[i][arr[ptr]]]++; } int cnt2[2]; cnt2[0] = f[0][j] - cnt[0]; cnt2[1] = f[1][j] - cnt[1]; cur ^= cnt[p[i][arr[j]]] & 1; cur ^= cnt2[p[i][arr[j]] ^ 1] & 1; } res += cur << i; if (i == 30) break; int sz[2]; sz[0] = sz[1] = 0; for (int j = 0; j < n; ++j) { b[j] += p[i][j] << i; } for (int j = 0; j < n; ++j) { bool x = p[i][arr[j]]; buf[x][sz[x]++] = arr[j]; } for (int j = 0; j < sz[0]; ++j) { arr[j] = buf[0][j]; } for (int j = 0; j < sz[1]; ++j) { arr[j + sz[0]] = buf[1][j]; } } cout << res; }

컴파일 시 표준 에러 (stderr) 메시지

xorsum.cpp: In function 'int main()':
xorsum.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
xorsum.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...