← 返回 capitalone 的题目列表Dynamic Wall Building and Range Query
类型:online_judge
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
Example
Input
5
1
query 0 4
Output
0