fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25. vector<int> a;
  26. void consistency(int n) {
  27.  
  28. int s = 0, e=n-1;
  29. while(s<e){
  30. int mid = s+(e-s)/2;
  31. if(a[mid] == a[mid^1]){
  32. s = mid+1;
  33. }
  34. else{
  35. e = mid;
  36. }
  37. }
  38.  
  39. cout << e << endl;
  40.  
  41. }
  42.  
  43. void solve() {
  44.  
  45. a = {1,1,2,3,3,4,4,8,8};
  46. int n = a.size();
  47. consistency(n) ;
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55. int32_t main() {
  56. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  57.  
  58. int t = 1;
  59. while (t--) {
  60. solve();
  61. }
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
2