Submission #959403

# Submission time Handle Problem Language Result Execution time Memory
959403 2024-04-08T07:04:23 Z mansur XOR Sum (info1cup17_xorsum) C++17
45 / 100
1600 ms 16508 KB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#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;
	vector<int> vl(n + 1);
	for (int b = 0; b < 30; b++) {
		vector<int> s[2];
		for (int i = 1; i <= n; i++) {
			if (b && (a[i] >> (b - 1) & 1)) vl[i] += (1 << (b - 1));
			s[a[i] >> b & 1].push_back(vl[i]);
		}
		sort(all(s[0]));
		sort(all(s[1]));
		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:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 348 KB Output is correct
2 Correct 9 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1666 ms 16508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1666 ms 16508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 348 KB Output is correct
2 Correct 9 ms 348 KB Output is correct
3 Correct 251 ms 2036 KB Output is correct
4 Correct 254 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 348 KB Output is correct
2 Correct 9 ms 348 KB Output is correct
3 Execution timed out 1666 ms 16508 KB Time limit exceeded
4 Halted 0 ms 0 KB -