fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //#define int long long
  4. #define dd double
  5. #define ld long double
  6. #define ull unsigned long long
  7. #define yes cout << "YES\n"
  8. #define no cout << "NO\n"
  9. #define el "\n"
  10. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11. #define fix(x) cout << fixed << setprecision(x)
  12. #define all(v) v.begin(),v.end()
  13. #define mod 1000000007
  14. //Here We Go Again
  15. void Done()
  16. {
  17. int n;
  18. cin>>n;
  19. int arr[n];
  20. for(int i=0;i<n;i++)
  21. cin>>arr[i];
  22. int l=0,r=0,mxlength=n,l2=0,r2=0,mxor=0;
  23. int orr=arr[l];
  24. while(r+1<n)
  25. {
  26. r++;
  27. //cout<<r<<el;
  28. if((orr|arr[r])>=orr)
  29. {
  30. orr|=arr[r]; //cout<<orr<<el;
  31. if((orr|arr[l])==arr[r])
  32. l++;
  33. }
  34. else
  35. {
  36. orr=arr[r];
  37. l=r;
  38. }
  39. mxor=max(mxor,orr);
  40. }
  41. // cout<<mxor<<el;
  42. orr=arr[l2];
  43. while(r2+1<n)
  44. {
  45. r2++;
  46. //cout<<r<<el;
  47. if((orr|arr[r2])>=orr)
  48. {
  49. orr|=arr[r2]; //cout<<orr<<el;
  50. if((orr|arr[l2])==arr[r2])
  51. l2++;
  52. }
  53. else
  54. {
  55. orr=arr[r2];
  56. l2=r2;
  57. }
  58. if(orr==mxor)
  59. mxlength=min(mxlength,r2-l2+1);
  60. }
  61. cout<<mxlength;
  62. }
  63. //اى ويل بريبير ماى بيبرز تو بى ذا بيست ان زيس وورلد
  64. int32_t main()
  65. {
  66. Arwa
  67. int t=1;
  68. //cin>>t;
  69. while(t--)
  70. {
  71. Done();
  72. }
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty