There is an endless straight line populated with some robots and walls. You are given integer arrays robots, distance, and walls:
robots[i] is the position of the ith robot.
distance[i] is the maximum distance the ith robot’s bullet can travel.
walls[j] is the position of the jth wall.
Every robot has one bullet that can either fire to the left or the right at mostdistance[i] meters.
A bullet destroys every wall in its path that lies within its range. Robots are fixed obstacles: if a bullet hits another robot before reaching a wall, it immediately stops at that robot and cannot continue.
Return the maximum number of unique walls that can be destroyed by the robots.
Notes:
A wall and a robot may share the same position; the wall can be destroyed by the robot at that position.
publicclassSolution { privatestaticclassSeg { int mi, ma, cnt; Seg left, right; Seg(int[] A, int l, int r) { this.mi = A[l]; this.ma = A[r]; this.cnt = r - l + 1; if (l < r) { intm= l + (r - l) / 2; left = newSeg(A, l, m); right = newSeg(A, m+1, r); } } intquery(int l, int r) { if (l > r) return0; if (l <= mi && ma <= r) return cnt; if (r < mi || l > ma) return0; return left.query(l, r) + right.query(l, r); } }