Submission #1026107

# Submission time Handle Problem Language Result Execution time Memory
1026107 2024-07-17T15:14:58 Z Tob XOR Sum (info1cup17_xorsum) C++14
0 / 100
206 ms 17760 KB
#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==1||k==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;
}

Compilation message

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: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 time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 17760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 17760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -