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, int k) {
  27.  
  28. int s = 0, e=n-1;
  29.  
  30. int first = -1, last=-1;
  31. while(s<e){
  32. int mid = s+(e-s)/2;
  33. if(a[mid]>=k){
  34. e = mid;
  35. }
  36. else{
  37. s = mid+1;
  38. }
  39. }
  40. first = e;
  41.  
  42. s=0, e=n-1;
  43. while(s<e){
  44. int mid = s+(e-s+1)/2;
  45. if(a[mid]<=k){
  46. s = mid;
  47. }
  48. else e = mid-1;
  49. }
  50. last = s;
  51.  
  52. if(a[first] == k && a[last] == k) cout << first << " " << last << endl;
  53. else cout << -1 << " " << -1 << endl;
  54.  
  55. }
  56.  
  57. void solve() {
  58.  
  59. a = {1};
  60. int n = a.size();
  61. int k = 1;
  62. consistency(n, k) ;
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. int32_t main() {
  71. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  72.  
  73. int t = 1;
  74. while (t--) {
  75. solve();
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0 0