Problem · Segment Tree
Dynamic Wall Building and Range Query
Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.
Maintain a 1D line of length n with indices 0..n-1, initially with no walls. You are given a sequence of operations of two types:
build i: build a wall at indexi(idempotent).query l r: check whether there exists at least one wall in the inclusive range[l, r].
For each query operation, output 1 if the range contains at least one wall, otherwise 0.
Input Format (stdin):
- Line 1: Integer
n, the length of the wall line. - Line 2: Integer
q, the number of operations. - Next
qlines: Each line is eitherbuild iorquery l r.
Output Format: Return the query results as an array of lines, one result per query operation, in order. Each result is either 0 or 1.
Examples
01 · Example 1
input = "5\n1\nquery 0 4" return = ["0"]
Input stdin: '5\n1\nquery 0 4'. Line 1: n=5. Line 2: 1 operation. Line 3: 'query 0 4'. No walls have been built, so the range [0,4] contains no wall. Output is ["0"].
Constraints
1 <= n <= 2 * 1051 <= q <= 2 * 105(number of operations)- All indices
i,l,rsatisfy0 <= l <= r <= n - 1 - Each operation is either
build iorquery l r
More Capital One problems
- Compare Counts Around PivotOA · Seen Jun 2026
- Reconstruct Landmark JourneyOA · Seen Jun 2026
- Count House Segments After DestructionOA · Seen May 2026
- Count Numbers with Even Number of DigitsOA · Seen May 2026
- Laser Robot Safe PathOA · Seen May 2026
- Longest Same-Character SubstringOA · Seen May 2026
- Cyclic Shift to Strictly Descending ArrayOA · Seen May 2026
- Queue Check-in Simulation with Capacity LimitOA · Seen May 2026
public String[] solveOneDynamicWallRangeQuery(String input) {
// write your code here
}
input"5\n1\nquery 0 4"
expected["0"]
checking account