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. for(int i=1;i<n;i++)
  40. {
  41. orr|=arr[i];
  42. while(i>l && (arr[l]&arr[i])==arr[l])
  43. {
  44. l++;
  45. }
  46. if(orr==or2) {
  47. mnlen=min(mnlen,i-l+1);
  48. }
  49. }
  50. cout<<mnlen;
  51. }
  52.  
  53. }
  54. int32_t main()
  55. {
  56.  
  57. Arwa
  58. int t=1;
  59. //cin>>t;
  60. for(int i=1;i<=t;i++)
  61. {
  62. HereWeGoAgain();
  63. }
  64. return 0;
  65. }
  66.  
  67.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1