Loading...
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
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define long long long int
  5.  
  6. signed main(){
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n;
  10. cin >> n;
  11. vector<int> a(n);
  12. for(int i = 0; i < n; i++)cin >> a[i];
  13. vector<int> lft(n, 0), rgt(n, n);
  14. stack<int> st;
  15. st.push(-1);
  16. for(int i = 0; i < n; i++){
  17. while(st.top() != -1 and a[i] > a[st.top()]){
  18. st.pop();
  19. }
  20. lft[i] = st.top() + 1;
  21. st.push(i);
  22. }
  23. while(!st.empty())st.pop();
  24. st.push(n);
  25. for(int i = n - 1; i >= 0; i--){
  26. while(st.top() != n and a[i] >= a[st.top()]){
  27. st.pop();
  28. }
  29. rgt[i] = st.top() + 1;
  30. st.push(i);
  31. }
  32. int ans = 0;
  33. for(int i = 0; i < n; i++){
  34. long count = 1LL * (i - lft[i] + 1) * (rgt[i] - i + 1);
  35. if(count & 1){
  36. ans ^= a[i];
  37. }
  38. }
  39. lft.assign(n, 0);
  40. rgt.assign(n, n);
  41. while(!st.empty())st.pop();
  42. st.push(-1);
  43. for(int i = 0; i < n; i++){
  44. while(st.top() != -1 and a[i] < a[st.top()]){
  45. st.pop();
  46. }
  47. lft[i] = st.top() + 1;
  48. st.push(i);
  49. }
  50. while(!st.empty())st.pop();
  51. st.push(n);
  52. for(int i = n - 1; i >= 0; i--){
  53. while(st.top() != n and a[i] <= a[st.top()]){
  54. st.pop();
  55. }
  56. rgt[i] = st.top() + 1;
  57. st.push(i);
  58. }
  59. for(int i = 0; i < n; i++){
  60. long count = 1LL * (i - lft[i] + 1) * (rgt[i] - i + 1);
  61. if(count & 1){
  62. ans ^= a[i];
  63. }
  64. }
  65. cout << ans;
  66. return 0;
  67. }