#define LL long long #define N 100005 #define Q 10005 #define K 10005
int ans[Q][2], nums[N];
intbin_search_r(int nums[], int left, int right, int target){ int i = left, j = right; while (i < j) { int k = (i + j) >> 1; if (nums[k] < target) i = k + 1; elseif (target < nums[k]) j = k; else { if (j - i == 1) return k; i = k; } // printf("%d %d\n", i, j); } return-1; }
intbin_search_l(int nums[], int left, int right, int target){ int i = left, j = right; while (i < j) { int k = (i + j) >> 1; if (nums[k] < target) i = k + 1; elseif (target < nums[k]) j = k; else { if (j - i == 1) return k; j = k; } } if (nums[i] == target) return i; return-1; }
intmain(){ int n, q; scanf("%d %d", &n, &q); for (int i = 0; i < n; i++) { scanf("%d", &nums[i]); } int tmp; for (int i = 0; i < q; i++) { scanf("%d", &tmp); int l = bin_search_l(nums, 0, n, tmp); int r = bin_search_r(nums, 0, n, tmp); ans[i][0] = l; ans[i][1] = r; } for (int i = 0; i < q; i++) { printf("%d %d\n", ans[i][0], ans[i][1]); } return0; }