[Java] Segment Tree O(n log k)
Use a SegmentTree for the minimum with query operation to find the first index greater than l that has a value <= to arrival time.\nIf we can\'t find a server t
Use a SegmentTree for the minimum with query operation to find the first index greater than l that has a value <= to arrival time.\nIf we can\'t find a server that is not busy with index greater than the target index, search from index 0. If both searches fail drop the request.\n\nThis SegmentTree implementation is almost exactly the same as problems https://codeforces.com/edu/course/2/lesson/4/2/practice/contest/273278/problem/C and\nhttps://codeforces.com/edu/course/2/lesson/4/2/practice/contest/273278/problem/D\n\n```\n    private static class SegTree {\n        int leftMost, rightMost;\n        SegTree left, right;\n        int min;\n\n        SegTree(int leftMost, int rightMost, int[] arr) {\n            this.leftMost = leftMost;\n            this.rightMost = rightMost;\n            if (leftMost == rightMost) {\n                min = arr[leftMost];\n            } else {\n                final int mid = leftMost + rightMost >>> 1;\n                left = new SegTree(leftMost, mid, arr);\n                right = new SegTree(mid + 1, rightMost, arr);\n                recalc();\n            }\n        }\n\n        private void recalc() {\n            if (leftMost == rightMost) {\n                return;\n            }\n            min = Math.min(left.min, right.min);\n        }\n\n        private int query(int idx, int val) {\n            if (min > val || rightMost < idx) {\n                return -1;\n            }\n            if (leftMost == rightMost) {\n                return leftMost;\n            }\n            final int resL = left.query(idx, val);\n            return resL != -1 ? resL : right.query(idx, val);\n        }\n\n        private void update(int idx, int val) {\n            if (leftMost == rightMost) {\n                min = val;\n            } else {\n                final int mid = leftMost + rightMost >>> 1;\n                if (idx <= mid) {\n                    left.update(idx, val);\n                } else {\n                    right.update(idx, val);\n                }\n                recalc();\n            }\n        }\n    }\n    \n    public List<Integer> busiestServers(int k, int[] arrival, int[] load) {\n        final int[] handled = new int[k];\n        final List<Integer> res = new ArrayList<>();\n        final SegTree st = new SegTree(0, k - 1, new int[k]);\n        for (int i = 0; i < arrival.length; i++) {\n            final int target = i % k;\n            int pos = st.query(target, arrival[i]);\n            if (pos < target) {\n                pos = st.query(0, arrival[i]);\n            }\n            if (pos != -1) {\n                handled[pos]++;\n                st.update(pos, arrival[i] + load[i]);\n            }\n        }\n        int max = 0;\n        for (int i = 0; i < k; i++) {\n            max = Math.max(max, handled[i]);\n        }\n        for (int i = 0; i < k; i++) {\n            if (handled[i] == max) {\n                res.add(i);\n            }\n        }\n        return res;\n    }\n```
[]