Mehulcoder

Confluent2019IITGA

Oct 8th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. /*
  2. Author: Mehul Chaturvedi
  3. Time Taken: 5min 21 sec
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11. using pll = pair<ll, ll>;
  12.  
  13. #define mp make_pair
  14. #define all(x) (x).begin(), (x).end()
  15. #define f first
  16. #define s second
  17. #define vll vector<long long>
  18. #define vvll vector<vector<ll>>
  19. #define vset(v, n, val) v.clear(); v.resize(n, val)
  20. #define INF 4557430888798830399ll
  21. #define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
  22. #define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
  23. #define repr(i, n) for (int i = n; i >= 0; i--)
  24. #define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
  25. #define trav(a, x) for(auto& a : x)
  26. #define fil(ar, val) memset(ar, val, sizeof(ar))
  27. const ll MOD = 1e9 + 7;
  28.  
  29.  
  30. void solve() {
  31.     ll n; cin >> n;
  32.     vll a(n, 0);
  33.  
  34.     rep(i, n) cin >> a[i];
  35.     ll h; cin >> h;
  36.  
  37.     ll ind1 = lower_bound(all(a), h) - a.begin();
  38.     if (ind1 == n || a[ind1] != h) {
  39.         cout << 0 << '\n';
  40.         return;
  41.     }
  42.  
  43.  
  44.     ll ind2 = upper_bound(all(a), h) - a.begin();
  45.  
  46.     cout << ind2 - ind1 << '\n';
  47.     return;
  48.  
  49. }
  50.  
  51. int main(int argc , char ** argv) {
  52.     ios_base::sync_with_stdio(false) ;
  53.     cin.tie(NULL) ;
  54.  
  55.     ll t = 1;
  56.  
  57.     while (t--) {
  58.         solve();
  59.     }
  60.  
  61.     return 0 ;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment