問題一覧 > 通常問題

No.2281 K → K-1 01 Flip

レベル : / AI推定難易度 : 2100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 20
作問者 : magsta / テスター : miscalc
お気に入りにしたユーザー ProblemId : 9190 / 自分の提出
問題文最終更新日: 2023-04-21 18:59:16
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 385 (順位表) の他の問題:

Problem Statement

You are given a string $S$ of length $N$ consisting only of 0 and 1.

You are given $Q$ queries. The $i$-th query is as follows.


Let $X$ be the substring of $S$ whose left end is the $L_i$-th character from the left and whose right end is the $R_i$-th character from the left. You may perform the following operation on it $0$ or more times. Find the minimum possible length of the string $X$ after the sequence of operations.

  • Replace a part consisting of $K_i$ consecutive 0s with $K_i-1$ 1s, or replace a part consisting of $K_i$ consecutive 1s with $K_i-1$ 0s.

Input

$N\ \ Q$
$S$
$L_1\ \ R_1\ \ K_1$
$L_2\ \ R_2\ \ K_2$
$:$
$L_Q\ \ R_Q\ \ K_Q$

  • $2 \leq N \leq 2×10^5$
  • $1 \leq Q \leq 2×10^5$
  • $1 \leq L_i < R_i \leq N$
  • $2 \leq K_i \leq R_i - L_i + 1$
  • $S$ is a string of length $N$ consisting of 0 and 1
  • All numbers in the input are integers

Output

On line $i \ (1 \leq i \leq Q)$, output the answer to the $i$-th query, and print a newline at the end.

Sample

Sample 1
Input
7 3
0100010
3 5 2
1 5 3
1 7 2
Output
2
2
2

In query $1$, performing the operation 000$→$01 makes the length of the string $2$. There is no way to make the length of the string $1$ or less, so the answer is $2$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。