Changed the folder structure of codeforces problemsets

This commit is contained in:
2021-11-02 12:54:37 +01:00
parent 5c71f0bbdd
commit 7eaf59bb45
13 changed files with 448 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, q, xi, mi;
cin >> n;
vector<int> xs;
xs.reserve(n);
for(int i = 0; i < n; ++i){
cin >> xi;
xs.push_back(xi);
}
sort(xs.begin(), xs.end());
cin >> q;
for(int qi = 0; qi < q; ++qi){
cin >> mi;
if(mi >= xs.back()){
cout << n << "\n";
continue;
}
if(mi < xs.front()){
cout << "0\n";
continue;
}
int start = 0, end = n - 1;
int middle = (end + start) / 2;
while(middle != start && middle != end){
if(mi > xs[middle]){
start = middle + 1;
} else{
end = middle;
}
middle = (end + start) / 2;
}
if(mi < xs[middle]){
cout << middle << "\n";
} else{
cout << middle + 1 << "\n";
}
}
cout << flush;
return 0;
}