I used 600B - Запросы о количестве не превосходящих элементов to test those and used the same code but with change in input and output streams.
Cin And Cout | Scanf And Printf | |
GNU C++ 5.1.0 | 358ms Submission:35214275 | 155ms Submission:35214230 |
GNU C++11 5.1.0 | 343ms Submission:35214311 | 156ms Submission:35214295 |
GNU C++14 6.4.0 | 187ms Submission:35214315 | 186ms Submission:35214352 |
GNU C++17 7.2.0 | 187ms Submission:35214359 | 187ms Submission:35214322 |
Looks like that scanf&printf is almost the same but cin&cout is slower under c++14.
Don't use cin&cout under c++14 to avoid TLE.
Scanf And Printf Code
#include <bits/stdc++.h>
using namespace std;
int n,m,val;
vector<int> a;
int main() {
scanf("%d%d",&n,&m);
for(int i = 0;i < n;i++){
scanf("%d",&val);
a.push_back(val);
}
sort(a.begin(),a.end());
for(int i = 0;i < m;i++){
int b;
scanf("%d",&b);
printf("%d ",upper_bound(a.begin(),a.end(),b)-a.begin());
}
return 0;
}
Cin And Cout Code
#include <bits/stdc++.h>
using namespace std;
int n,m,val;
vector<int> a;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0;i < n;i++){
cin >> val;
a.push_back(val);
}
sort(a.begin(),a.end());
for(int i = 0;i < m;i++){
int b;
cin >> b;
cout << upper_bound(a.begin(),a.end(),b)-a.begin() << " ";
}
return 0;
}