fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define MAX 900
  5. #define MAX1 13770000
  6. #define inf 1000000000
  7. #define mod 1000000007
  8. #define ll long long
  9.  
  10. int arr[MAX+5];
  11. struct node
  12. {
  13. int ptr[2];
  14. }buffer[MAX1+5];
  15. int nn,root[MAX+5];
  16.  
  17. int Insert(int a,int prev)
  18. {
  19. int i,ret=++nn,t;
  20. bool bit;
  21. t=ret;
  22. for(i=17;i>=0;--i)
  23. {
  24. bit=a&(1<<i);
  25. buffer[t]=buffer[prev];
  26. buffer[t].ptr[bit]=++nn;
  27. t=buffer[t].ptr[bit];
  28. prev=buffer[prev].ptr[bit];
  29. }
  30. return ret;
  31. }
  32. int Search(int a,int t)
  33. {
  34. int i,dir,ans=0;
  35. bool bit;
  36. for(i=17;i>=0;--i)
  37. {
  38. bit=a&(1<<i);
  39. dir=buffer[t].ptr[bit^1];
  40. if(dir)
  41. {
  42. t=dir;
  43. ans|=(1<<i);
  44. }
  45. else
  46. t=buffer[t].ptr[bit];
  47. }
  48. return ans;
  49. }
  50. int main()
  51. {
  52. ios::sync_with_stdio(false);
  53. //freopen("in.txt","r",stdin);
  54. //freopen("out.txt","w",stdout);
  55. int n,i,j,sum,cool,prev;
  56. cin>>n;
  57. for(i=1;i<=n;++i)
  58. cin>>arr[i];
  59. for(i=1;i<=n;++i)
  60. {
  61. sum=0;
  62. prev=root[i-1];
  63. for(j=i;j>=1;--j)
  64. {
  65. sum+=arr[j];
  66. root[i]=Insert(sum,prev);
  67. prev=root[i];
  68. }
  69. }
  70. cool=0;
  71. for(i=1;i<=n;++i)
  72. {
  73. sum=0;
  74. for(j=i;j<=n;++j)
  75. {
  76. sum+=arr[j];
  77. cool=max(cool,Search(sum,root[i-1]));
  78. }
  79. }
  80. cout<<cool;
  81. return 0;
  82. }
Runtime error #stdin #stdout 0.08s 110412KB
stdin
Standard input is empty
stdout
Standard output is empty