Submission #649380

# Submission time Handle Problem Language Result Execution time Memory
649380 2022-10-10T07:00:07 Z dozer XOR Sum (info1cup17_xorsum) C++14
45 / 100
1477 ms 9416 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define sp " "
//#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define N 100005
#define LOGN 30
#define int long long
int arr[N];

int32_t main()
{
	//fileio();
	fastio();

	int n;
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin>>arr[i];

	int ans = 0;
	for (int i = 0; i <= LOGN; i++)
	{
		//cout<<ans<<endl;
		vector<int> v;
		map<int, int> cnt;
		int m = (int)1<<(i + 1);
		int k = (1<<i);
		for (int j = 1; j <= n; j++)
			v.pb(arr[j] % m), cnt[arr[j] % m]++;
		sort(v.begin(), v.end());
		int sum = 0, tmp = 0;
		for (int j = 1; j <= n; j++)
		{
			int l = ((k - arr[j]) % m + m) % m;
			int r = m - 1 - (arr[j] % m);
			int curr = arr[j] % m;
			//cout<<curr<<sp<<l<<sp<<r<<sp;
			if (l <= r)
			{
				sum += lower_bound(v.begin(), v.end(), r + 1) - lower_bound(v.begin(), v.end(), l);
				//if (cnt[l]) sum++;
				if (curr >= l && curr <= r) sum++;
			}
			else
			{
				sum += n - (lower_bound(v.begin(), v.end(), l) - upper_bound(v.begin(), v.end(), r));
				//if (cnt[r + 1]) sum--;
				if (curr >= l || curr <= r) sum++;
			}
			//cout<<sum<<endl;
		}
		//cout<<sum<<endl;
		sum /= 2;
		ans += (sum % 2) * k;
	}

	cout<<ans<<endl;
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}

Compilation message

xorsum.cpp: In function 'int32_t main()':
xorsum.cpp:37:16: warning: unused variable 'tmp' [-Wunused-variable]
   37 |   int sum = 0, tmp = 0;
      |                ^~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 680 KB Output is correct
2 Correct 39 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 2004 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 2004 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 680 KB Output is correct
2 Correct 39 ms 672 KB Output is correct
3 Correct 1477 ms 8332 KB Output is correct
4 Correct 1463 ms 9416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 680 KB Output is correct
2 Correct 39 ms 672 KB Output is correct
3 Runtime error 8 ms 2004 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -