제출 #1026109

#제출 시각아이디문제언어결과실행 시간메모리
1026109TobXOR Sum (info1cup17_xorsum)C++14
0 / 100
205 ms17972 KiB
#include <bits/stdc++.h> #define F first #define S second #define all(x) x.begin(), x.end() #define pb push_back #define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const int N = 1e6 + 7, B = 30; int n, res; int a[N]; int main () { FIO; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; if (n % 2 == 0) for (int i = 0; i < n; i++) res ^= a[i]; for (int i = 1; i < B; i++) { vector <int> v[2]; for (int j = 0; j < n; j++) v[(a[j] >> i-1) & 1].pb(a[j]); int k = v[1].size(); int o = (k&4==1||k&4==2); k--; for (int j = 0; j < v[0].size(); j++) { while (k >= 0 && (v[0][j] & (1 << i)-1) + (v[1][k] & (1 << i)-1) >= (1 << i)) k--; o ^= (int(v[1].size())-k-1)&1; a[j] = v[0][j]; } for (int j = 0; j < v[1].size(); j++) a[v[0].size()+j] = v[1][j]; res ^= (o << i); } cout << res << "\n"; return 0; }

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

xorsum.cpp: In function 'int main()':
xorsum.cpp:26:43: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   26 |   for (int j = 0; j < n; j++) v[(a[j] >> i-1) & 1].pb(a[j]);
      |                                          ~^~
xorsum.cpp:28:15: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   28 |   int o = (k&4==1||k&4==2); k--;
      |              ~^~~
xorsum.cpp:28:23: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   28 |   int o = (k&4==1||k&4==2); k--;
      |                      ~^~~
xorsum.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int j = 0; j < v[0].size(); j++) {
      |                   ~~^~~~~~~~~~~~~
xorsum.cpp:30:40: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |    while (k >= 0 && (v[0][j] & (1 << i)-1) + (v[1][k] & (1 << i)-1) >= (1 << i)) k--;
      |                                ~~~~~~~~^~
xorsum.cpp:30:65: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |    while (k >= 0 && (v[0][j] & (1 << i)-1) + (v[1][k] & (1 << i)-1) >= (1 << i)) k--;
      |                                                         ~~~~~~~~^~
xorsum.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for (int j = 0; j < v[1].size(); j++) a[v[0].size()+j] = v[1][j];
      |                   ~~^~~~~~~~~~~~~
#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...