답안 #959408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959408 2024-04-08T07:12:32 Z mansur XOR Sum (info1cup17_xorsum) C++17
0 / 100
412 ms 41176 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];
	vector<pii> vl;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		vl.push_back({0, a[i]});
	}
	int ans = 0;
	for (int b = 0; b < 30; b++) {
		vector<int> s[2];
		vector<pii> h, nv;
		for (int i = 0; i < n; i++) {
			if (b && (vl[i].s >> (b - 1) & 1)) {
				vl[i].f += (1 << (b - 1));
				h.push_back(vl[i]); 
			}else {
			    nv.push_back(vl[i]);
				s[vl[i].s >> b & 1].push_back(vl[i].f);
			}
		}
		for (auto x: h) {
			nv.push_back(x);
			s[x.s >> b & 1].push_back(x.f);
		}
		int pos = sz(s[0]) - 1;
		for (int i = 0; i < sz(s[0]); i++) {
			int vl = (1 << b) - s[0][i];
			while (pos >= i && s[0][pos] >= vl) pos--;
			while (pos < i - 1) pos++;
			int cnt = sz(s[0]) - pos - 1;
			if (cnt & 1) ans ^= (1 << b);
		}
		pos = sz(s[1]) - 1;
		for (int i = 0; i < sz(s[1]); i++) {
			int vl = (1 << b) - s[1][i];
			while (pos >= i && s[1][pos] >= vl) pos--;
			while (pos < i - 1) pos++;
			int cnt = sz(s[1]) - pos - 1;
			if (cnt & 1) ans ^= (1 << b);
		}
		pos = 0;
		for (int i = sz(s[1]) - 1; i >= 0; i--) {
			int vl = (1 << b) - s[1][i];
			while (pos < sz(s[0]) && s[0][pos] < vl) pos++;
			if (pos & 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:83:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   83 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 412 ms 41176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 412 ms 41176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -