Parenthesis Checking

AtCoder
IDabc223_f
Time3000ms
Memory256MB
Difficulty
Let us define a **correct parenthesis sequence** as a string that satisfies one of the following conditions. * It is an empty string. * It is a concatenation of `(`, $A$, `)`, in this order, for some **correct parenthesis sequence** $A$. * It is a concatenation of $A$, $B$, in this order, for some **correct parenthesis sequences** $A$ and $B$. We have a string $S$ of length $N$ consisting of `(` and `)`. Given $Q$ queries $\text{Query}_1,\text{Query}_2,\ldots,\text{Query}_Q$, process them in order. There are two kinds of queries, with the following formats and content. * `1 l r`: Swap the $l$\-th and $r$\-th characters of $S$. * `2 l r`: Determine whether the contiguous substring from the $l$\-th through the $r$\-th character is a **correct parenthesis sequence**. ## Constraints * $1 \leq N,Q \leq 2 \times 10^5$ * $S$ is a string of length $N$ consisting of `(` and `)`. * $1 \leq l < r \leq N$ * $N,Q,l,r$ are all integers. * Each query is in the format `1 l r` or `2 l r`. * There is at least one query in the format `2 l r`. ## Input Input is given from Standard Input in the following format: $N$ $Q$ $S$ $\text{Query}_1$ $\text{Query}_2$ $\vdots$ $\text{Query}_Q$ [samples]
Samples
Input #1
5 3
(())(
2 1 4
2 1 2
2 4 5
Output #1
Yes
No
No

In the first query, `(())` is a **correct parenthesis sequence**.
In the second query, `((` is not a **correct parenthesis sequence**.
In the third query, `)(` is not a **correct parenthesis sequence**.
Input #2
5 3
(())(
2 1 4
1 1 4
2 1 4
Output #2
Yes
No

In the first query, `(())` is a **correct parenthesis sequence**.
In the second query, $S$ becomes `)()((`.
In the third query, `)()(` is not a **correct parenthesis sequence**.
Input #3
8 8
(()(()))
2 2 7
2 2 8
1 2 5
2 3 4
1 3 4
1 3 5
1 1 4
1 6 8
Output #3
Yes
No
No
API Response (JSON)
{
  "problem": {
    "name": "Parenthesis Checking",
    "description": {
      "content": "Let us define a **correct parenthesis sequence** as a string that satisfies one of the following conditions. *   It is an empty string. *   It is a concatenation of `(`, $A$, `)`, in this order, for ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc223_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let us define a **correct parenthesis sequence** as a string that satisfies one of the following conditions.\n\n*   It is an empty string.\n*   It is a concatenation of `(`, $A$, `)`, in this order, for ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments