Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(vec) for(auto& i : vec) cin >> i
- #define cin_2d(vec, n, m) for(int i=0; i<n; i++) for(int j=0; j<m && cin >> vec[i][j]; j++);
- #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
- #define cout_2d(vec, r, c) for(int i=0; i<r; i++, cout << "\n") for(int j=0; j<c && cout << vec[i][j] << " "; j++);
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " : " << s << "\n"
- #define matrix(grid, n, m) vector < vector <ll> > grid(n, vector <ll> (m));
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
- #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define fixed(n) cout << fixed << setprecision(n)
- #define Num_of_Digits(n) ((int)log10(n)+1)
- #define getline(s) getline(cin >> ws, s)
- #define to_decimal(bin) stoi(bin, nullptr, 2)
- #define TC int t; cin >> t; while(t--)
- #define rall(s) s.rbegin(), s.rend()
- #define all(s) s.begin(), s.end()
- #define sz(x) int(x.size())
- #define Pair pair <int, int>
- #define fi first
- #define se second
- #define pb(x) push_back(x)
- #define ll long long
- #define PI acos(-1)
- #define Mod 1'000'000'007
- #define INF 2'000'000'000
- #define EPS 1e-9
- void Anwar_Rizk(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE // Anwar Rizk 🥇🖤
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- Time
- }
- int main()
- { Anwar_Rizk();
- int n, q, x;
- cin >> n >> q;
- vector < int > nums(n);
- cin(nums);
- sort(all(nums));
- while(q--){
- string bin;
- cin >> bin >> x;
- if(bin == "binary_search"){
- cout << (binary_search(all(nums), x) ? "found" : "not found") << "\n";
- }
- if(bin == "lower_bound"){
- auto it = lower_bound(all(nums), x);
- cout << (it != nums.end() ? *it : -1) << "\n";
- }
- if(bin == "upper_bound"){
- auto it = upper_bound(all(nums), x);
- cout << (it != nums.end() ? *it : -1) << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement