include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 100010;
int q[N];
int Binarysearch_L(int x, int l, int r) {
while (l < r) {
int mid = l+r>>1; // Avoid potential overflow
if (q[mid] >= x)
r = mid; // Move left
else
l = mid + 1; // Move right
}
return l;
}
int Binarysearch_R(int x, int l, int r) {
while (l < r) {
int mid = l+r+1>>1; // Avoid potential overflow
if (q[mid] <= x)
l = mid; // Move right
else
r = mid - 1; // Move left
}
return l;
}
int main() {
int n, m;
scanf(“%d %d”, &n, &m);
for (int i = 0; i < n; i++) {
scanf(“%d”, &q[i]); // Changed to scanf for consistency
}
sort(q, q + n); // Ensure the array is sorted
while (m--) {
int x;
scanf("%d", &x);
int l = Binarysearch_L(x, 0, n-1);
if (l < n && q[l] == x) { // Ensure l is in bounds
int r = Binarysearch_R(x, 0, n-1) ; // Get the last occurrence
cout << l << " " << r << endl;
} else {
cout << "-1 -1" << endl;
}
}
return 0;
}