Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int n;
- map<int, pii> mg;
- int a[1 << 13];
- int xa[1 << 13];
- int dp[1 << 13];
- int main(int argc, char **argv)
- {
- scanf("%d", &n);
- // memset(lm, 0x3F, sizeof(lm));
- // memset(dp, -1, sizeof(dp));
- for (int i = 1; i <= n; ++i) {
- scanf("%d", a + i), xa[i] = xa[i - 1] ^ a[i];
- if (mg.count(a[i]))
- mg[a[i]].second = i;
- else
- mg[a[i]] = {i, i};
- }
- for (int i = 1; i <= n; ++i) {
- dp[i] = dp[i - 1];
- int v = a[i];
- int l = mg[v].first, r = mg[v].second;
- if (r == i) {
- int xor_val = 0;
- set<int> vis;
- for (int k = l; k <= r; ++k) {
- int ak = a[k];
- if (vis.count(ak) == 0) {
- vis.insert(ak);
- xor_val ^= ak;
- }
- }
- dp[i] = max(dp[i], dp[l - 1] + xor_val);
- // dbg(v, l, r, dp[i], dp[l - 1], (xa[l] ^ xa[r - 1]));
- // dp[i] = max(dp[i], dp[l - 1] + (xa[l] ^ xa[r - 1]));
- }
- }
- printf("%d\n", dp[n]);
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement