fork download
  1. #include <bits/stdc++.h>
  2. #include <bitset>
  3. using namespace std;
  4. #define int long long
  5. #define dd double
  6. #define ld long double
  7. #define ull unsigned long long
  8. #define yes cout << "YES\n"
  9. #define no cout << "NO\n"
  10. #define el "\n"
  11. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  12. #define fix(x) cout << fixed << setprecision(x)
  13. #define all(v) v.begin(),v.end()
  14. #define dpp(arr,val) memset(arr,val,sizeof(arr))
  15. #define mod 1e9+7
  16. const int N = 1e5 + 5;
  17. // First power of two ≥ n
  18. int powerOf2GreaterThanOrEqual(int n)
  19. {
  20. int indx = 0;
  21. while ((1 << indx) < n)
  22. indx++;
  23. return (1 << indx);
  24. }
  25. //todo اى ويل بريبير ماى بيبرز تو بى ذا بيست ان زيس وورلد
  26. void HereWeGoAgain()
  27. {
  28. int n;
  29. cin>>n;
  30. int arr[n];
  31. for(int i=0;i<n;i++) cin>>arr[i];
  32. if(n<=1)
  33. cout<<n<<el;
  34. else
  35. {
  36. int or2=arr[0];
  37. for(int i=0;i<n;i++) or2|=arr[i];
  38. int mnlen=n,l=0,orr=arr[0];
  39. // cout<<or2<<el;
  40. for(int i=1;i<n;i++)
  41. {
  42. orr|=arr[i];
  43. if(orr==or2) {
  44. while(i>l && (arr[l]&arr[i])==arr[l]) l++;
  45. mnlen=min(mnlen,i-l+1);
  46. }
  47. while(i>l && (arr[l]&arr[i])==arr[l]) l++;
  48. }
  49. cout<<mnlen;
  50. }
  51.  
  52. }
  53. int32_t main()
  54. {
  55.  
  56. Arwa
  57. int t=1;
  58. //cin>>t;
  59. for(int i=1;i<=t;i++)
  60. {
  61. HereWeGoAgain();
  62. }
  63. return 0;
  64. }
  65.  
  66.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1