답안 #959401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959401 2024-04-08T07:03:08 Z mansur XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 23180 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;
	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() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 564 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1578 ms 20900 KB Output is correct
2 Correct 1488 ms 20120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1578 ms 20900 KB Output is correct
2 Correct 1488 ms 20120 KB Output is correct
3 Execution timed out 1624 ms 23180 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 564 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 194 ms 2980 KB Output is correct
4 Correct 187 ms 3108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 564 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 1578 ms 20900 KB Output is correct
4 Correct 1488 ms 20120 KB Output is correct
5 Execution timed out 1624 ms 23180 KB Time limit exceeded
6 Halted 0 ms 0 KB -