DatabricksOA #6
Number Line — Obstacles + Block Fit
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchIterators
On the integer number line, process in order operations that either place an obstacle or ask whether an interval of length size can be placed. 1 x places an obstacle at x (it is guaranteed that there is no obstacle there yet); 2 x size checks integer coordinates x-size through x-1 (inclusive) without actually placing the interval.
Standard input/output, this site's supplementary ranges, and the examples follow this problem's description.
Input
The first line contains q (1≤q≤60000), followed by q lines of operations 1 x or 2 x size. −10⁹≤x≤10⁹, 1≤size≤10⁹. Inserted coordinates are guaranteed not to be occupied already; the upper bound on q is a site supplement that keeps the output length within the judge's limit.
Output
Concatenate the results of every 2 x size in order into a single string of 0s and 1s: 1 if the interval has no obstacle, otherwise 0.
Example 1
Input:
6
1 2
1 5
2 5 2
2 6 3
2 2 1
2 3 2
Output:
1010
Example 2
Input:
3
2 0 1
1 0
2 0 1
Output:
11
Example 3
Input:
3
1 -2
2 -3 1
2 -3 2
Output:
11
Editorial
Loading solution…