-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayfind.cpp
More file actions
41 lines (26 loc) · 904 Bytes
/
Copy patharrayfind.cpp
File metadata and controls
41 lines (26 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
using namespace std;
int length;
int numbers[1000001];
int main()
{
cin >> length;
for ( int i = 0; i < length; i++ )
{
cin >> numbers[i];
}
// process array
sort( numbers, numbers + length );
// receive queries & solve
int numberOfQueries; cin >> numberOfQueries;
for ( int i = 0; i < numberOfQueries; i++ )
{
int q; cin >> q; // get query
// get index of LAST number SMALLER THAN OR EQUAL to query (this also tells you how many numbers are before it)
int smaller = lower_bound( numbers, numbers + length, q ) - numbers; // working
// vice versa
int bigger = length - (upper_bound( numbers, numbers + length, q ) - numbers); // working
// gei ni da an
cout << "Smaller: " << smaller << ", Greater: " << bigger << "\n";
}
}