답안 #959396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959396 2024-04-08T06:58:57 Z mansur XOR Sum (info1cup17_xorsum) C++17
45 / 100
1600 ms 17416 KB
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
 
#include<bits/stdc++.h>	
 
using namespace std;
 
#define all(a) a.begin(), a.end()                                                   
#define rall(a) a.rbegin(), a.rend()                 
#define sz(a) (int)a.size()
#define s second
#define f first
 
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
     
vector<pii> rid = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pii> dir = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
 
const int N = 2e5 + 1, mod = 1e9 + 7;
 
const ll inf = 2e18;
 
double eps = 1e-15;
                                                
bool flg = 0;
 
void slv() {
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 1; i <= n; i++) cin >> a[i];
	int ans = 0;
	for (int b = 0; b < 30; b++) {
		vector<int> s[2];
		for (int i = 1; i <= n; i++) {
			int vl = 0;
			for (int j = 0; j < b; j++) {
			 	if (a[i] >> j & 1) vl += (1 << j);
			}	
			s[a[i] >> b & 1].push_back(vl);
		}
		sort(all(s[0]));
		sort(all(s[1]));
		for (int i = 0; i < sz(s[0]); i++) {
			int vl = (1 << b) - s[0][i];
			int l = i, r = sz(s[0]) - 1;
			while (l <= r) {
				int m = (l + r) / 2;
				if (s[0][m] >= vl) r = m - 1;
				else l = m + 1;
			}
			int cnt = sz(s[0]) - r - 1;
			if (cnt & 1) ans ^= (1 << b);
		}
		for (int i = 0; i < sz(s[1]); i++) {
			int vl = (1 << b) - s[1][i];
			int l = i, r = sz(s[1]) - 1;
			while (l <= r) {
				int m = (l + r) / 2;
				if (s[1][m] >= vl) r = m - 1;
				else l = m + 1;
			}
			int cnt = sz(s[1]) - r - 1;
			if (cnt & 1) ans ^= (1 << b);
		}
		for (int i = 0; i < sz(s[1]); i++) {
			int vl = (1 << b) - s[1][i];
			int l = 0, r = sz(s[0]) -1;
			while (l <= r) {
				int m = (l + r) / 2;
				if (s[0][m] < vl) l = m + 1;
				else r = m - 1;
			}   	
			if (l & 1) ans ^= (1 << b);
		}
	}	
	cout << ans;
}
 
main() {
	//freopen("input.txt", "r", stdin);                                                                                     
	//freopen("output.txt", "w", stdout);                                                                                     
	ios_base::sync_with_stdio(0);	                                                                                       
	cin.tie(0);
	int tp = 1;
	if (flg) cin >> tp;
	while (tp--) {  	
		slv();
	}
}
//wenomechainsama      

Compilation message

xorsum.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 344 KB Output is correct
2 Correct 17 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1664 ms 17416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1664 ms 17416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 344 KB Output is correct
2 Correct 17 ms 552 KB Output is correct
3 Correct 447 ms 2592 KB Output is correct
4 Correct 447 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 344 KB Output is correct
2 Correct 17 ms 552 KB Output is correct
3 Execution timed out 1664 ms 17416 KB Time limit exceeded
4 Halted 0 ms 0 KB -