답안 #649449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649449 2022-10-10T08:38:26 Z dozer XOR Sum (info1cup17_xorsum) C++14
0 / 100
11 ms 596 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 1000005
#define LOGN 30
#define int long long
int arr[N];

const int INF = 1e9 + 7;

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

	int n;
	cin>>n;
	int maks = 0;
	for (int i = 1; i <= n; i++)
	{
		cin>>arr[i];
		maks = max(maks, arr[i]);
	}

	int ans = 0;
	for (int i = 0; ((int)1<<(i - 1)) <= maks ; i++)
	{
		//cout<<ans<<endl;
		int m = (int)1<<(i + 1);
		int k = (1<<i);
		map<int ,int> cnt;
		for (int j = 1; j <= n; j++)
		{
			cnt[arr[j] % m]++;
		}
		vector<pii> v(cnt.begin(), cnt.end());
		vector<int> pre(v.size() + 1, 0);
		for (int j = 1; j <= v.size(); j++)
			pre[j] = pre[j - 1] + v[j - 1].nd;
		/*
		for (auto j : pre) cout<<j<<sp;
			cout<<endl;
			*/
		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)
			{
				int x = upper_bound(v.begin(), v.end(), make_pair(r, (int)INF)) - v.begin();
				int y = lower_bound(v.begin(), v.end(), make_pair(l, (int)0)) - v.begin();
				sum += pre[x] - pre[y];
				
				if (curr >= l && curr <= r) sum++;
			}
			else
			{
				int x = upper_bound(v.begin(), v.end(), make_pair(l - 1, (int)INF)) - v.begin();
				int y = lower_bound(v.begin(), v.end(), make_pair(r + 1, (int)0)) - v.begin();
				sum += n - (pre[x] - pre[y]);
				
				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:45:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int j = 1; j <= v.size(); j++)
      |                   ~~^~~~~~~~~~~
xorsum.cpp:51:16: warning: unused variable 'tmp' [-Wunused-variable]
   51 |   int sum = 0, tmp = 0;
      |                ^~~
xorsum.cpp:3:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:20:2: note: in expansion of macro 'fileio'
   20 |  fileio();
      |  ^~~~~~
xorsum.cpp:3:59: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
      |                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:20:2: note: in expansion of macro 'fileio'
   20 |  fileio();
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -