Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
27416622 Practice:
ironsoul
811C - 32 GNU C++14 Accepted 31 ms 92 KB 2017-05-28 19:31:26 2017-05-28 19:31:27
 
 
→ Source
#include <bits/stdc++.h>
  
using namespace std;
 
const int N = (int) 5e3 + 7;
const int MOD = (int) 2e9 + 7;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int dp[N], a[N], l[N], f[N], used[N];
	for (int i = 0; i < N; i++)
		l[i] = f[i] = -1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (l[a[i]] == -1)
			l[a[i]] = i;
		f[a[i]] = i;
		dp[i] = 0;
	}
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1];
		if (f[a[i]] != i) continue;
		int result = 0;
		for (int i = 0; i < N; i++)
			used[i] = 0;
		int left = l[a[i]], right = f[a[i]];
		for (int t = f[a[i]]; t >= l[a[i]]; t--) {
			if (!used[a[t]]) result ^= a[t];
			used[a[t]] = 1;
			left = min(left, l[a[t]]), right = max(right, f[a[t]]);
		}
		for (int t = l[a[i]] - 1; t >= left; t--) {
			if (!used[a[t]]) result ^= a[t];
			used[a[t]] = 1;
		}
		if (f[a[i]] >= right) {
			dp[i] = max(dp[i], dp[left - 1] + result);
		}
	}
	cout << dp[n];
	return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details