题目描述
思路很简单,各位小伙伴自行查看
思路
前缀和
时间复杂度
O(n)
C++ 代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
int n;
int t;
int k;
int a[N];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t;
a[t]++;
}
for (int i = 1; i <= t; i++) {
a[i] = a[i] + a[i - 1];
}
for (int i = 0; i < k; i++) {
cin >> t;
if (a[t - 1] == a[t] || a[t] == 0) cout << "-1 -1" << endl;
else cout << a[t - 1] << " " << a[t] - 1 << endl;;
}
return 0;
}