FastPrepFastPrep
Problem Brief

Dynamic Wall Building and Range Query

FULLTIMEOA

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.

Original prompt

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 index i (idempotent). query l r: check whether there exists at least one wall in the inclusive range [l, r].

For each query output:

1 if the range contains a wall otherwise 0

Return/output the list of query results in order.

Input

Integer n List of operations operations

Output

List of 0/1 (or printed space-separated) Constraints (suggested) 1 <= n <= 2e5 1 <= len(operations) <= 2e5 indices are valid

Examples

n=5, ops=[query 0 4] → 0 n=5, ops=[build 2, query 0 4] → 1 n=5, ops=[build 2, query 3 4] → 0 n=5, ops=[build 1, build 3, query 2 2, query 0 3] → 0 1 n=3, ops=[build 0, build 0, query 0 0, query 1 2] → 1 0

Function Description

Complete solveOneDynamicWallRangeQuery. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters.

1Example 1

Input
input = "5\n1\nquery 0 4"
Output
["0"]
Explanation

The returned string must match the expected standard output for the sample input.

Constraints

Limits and guarantees your solution can rely on.

Use the limits and requirements stated in the prompt.

public String[] solveOneDynamicWallRangeQuery(String input) {
    // write your code here
}
Input

input

"5\n1\nquery 0 4"

Output

["0"]

Sign in to submit your solution.