import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型ArrayList 
     * @param target int整型 
     * @return int整型ArrayList
     */
    public ArrayList<Integer> searchRange(ArrayList<Integer> nums, int target) {
        // write code here
        int l = 0;
        int r = nums.size() - 1;
        int index = 0;
        ArrayList<Integer> res = new ArrayList<>();
        while (l <= r) {
            int mid = l + ((r - l) >> 1);
            if (nums.get(mid) < target) {
                l = mid + 1;
            } else if (nums.get(mid) > target) {
                r = mid - 1;
            } else {
                int p1 = mid;
                int p2 = mid;
                while (p1 >= 0 && nums.get(p1) == target) {
                    p1--;
                }
                p1++;
                while (p2 < nums.size() && nums.get(p2) == target) {
                    p2++;
                }
                p2--;
                res.add(p1);
                res.add(p2);
                break;
            }
        }
        if (res.size() == 0) {
            res.add(-1);
            res.add(-1);
        }
        return res;
    }
}