Submission
# | When | Author | Problem | Language | CPU | Memory | |
---|---|---|---|---|---|---|---|
20908 | 2024-08-10 01:00:16 | heisenberg_120 | Find MinMaxXoR Number | C++ 17 | 376 ms | 10892 kb | Accepted |
Test Cases
# | CPU | Memory | Points | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2 ms | 3312 kb | 1 | Accepted | |||||||
2 | 1 ms | 3340 kb | 1 | Accepted | |||||||
3 | 1 ms | 3276 kb | 1 | Accepted | |||||||
4 | 1 ms | 3412 kb | 1 | Accepted | |||||||
5 | 2 ms | 3412 kb | 1 | Accepted | |||||||
6 | 2 ms | 3416 kb | 1 | Accepted | |||||||
7 | 9 ms | 3512 kb | 1 | Accepted | |||||||
8 | 9 ms | 3400 kb | 1 | Accepted | |||||||
9 | 76 ms | 4016 kb | 1 | Accepted | |||||||
10 | 375 ms | 8856 kb | 1 | Accepted | |||||||
11 | 375 ms | 8724 kb | 1 | Accepted | |||||||
12 | 264 ms | 10892 kb | 1 | Accepted | |||||||
13 | 375 ms | 8860 kb | 1 | Accepted | |||||||
14 | 360 ms | 9176 kb | 1 | Accepted | |||||||
15 | 376 ms | 8768 kb | 1 | Accepted | |||||||
16 | 337 ms | 9492 kb | 1 | Accepted | |||||||
Source Code
#include<bits/stdc++.h> using namespace std; #define long long long int signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++)cin >> a[i]; vector<int> lft(n, 0), rgt(n, n); stack<int> st; st.push(-1); for(int i = 0; i < n; i++){ while(st.top() != -1 and a[i] > a[st.top()]){ st.pop(); } lft[i] = st.top() + 1; st.push(i); } while(!st.empty())st.pop(); st.push(n); for(int i = n - 1; i >= 0; i--){ while(st.top() != n and a[i] >= a[st.top()]){ st.pop(); } rgt[i] = st.top() + 1; st.push(i); } int ans = 0; for(int i = 0; i < n; i++){ long count = 1LL * (i - lft[i] + 1) * (rgt[i] - i + 1); if(count & 1){ ans ^= a[i]; } } lft.assign(n, 0); rgt.assign(n, n); while(!st.empty())st.pop(); st.push(-1); for(int i = 0; i < n; i++){ while(st.top() != -1 and a[i] < a[st.top()]){ st.pop(); } lft[i] = st.top() + 1; st.push(i); } while(!st.empty())st.pop(); st.push(n); for(int i = n - 1; i >= 0; i--){ while(st.top() != n and a[i] <= a[st.top()]){ st.pop(); } rgt[i] = st.top() + 1; st.push(i); } for(int i = 0; i < n; i++){ long count = 1LL * (i - lft[i] + 1) * (rgt[i] - i + 1); if(count & 1){ ans ^= a[i]; } } cout << ans; return 0; }