题库练习 Binary String Copying
← 上一题 下一题 →

A15970 | Binary String Copying

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given a string $s$ consisting of $n$ characters 0 and/or 1.

You make $m$ copies of this string, let the $i$ -th copy be the string $t_i$ . Then you perform exactly one operation on each of the copies: for the $i$ -th copy, you sort its substring $[l_i; r_i]$ (the substring from the $l_i$ -th character to the $r_i$ -th character, both endpoints inclusive). Note that each operation affects only one copy, and each copy is affected by only one operation.

Your task is to calculate the number of different strings among $t_1, t_2, \ldots, t_m$ . Note that the initial string $s$ should be counted only if at least one of the copies stays the same after the operation.

输入格式

The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ( $1 \le n, m \le 2 \cdot 10^5$ ) — the length of $s$ and the number of copies, respectively.

The second line contains $n$ characters 0 and/or 1 — the string $s$ .

Then $m$ lines follow. The $i$ -th of them contains two integers $l_i$ and $r_i$ ( $1 \le l_i \le r_i \le n$ ) — the description of the operation applied to the $i$ -th copy.

The sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$ . The sum of $m$ over all test cases doesn't exceed $2 \cdot 10^5$ .

输出格式

Print one integer — the number of different strings among $t_1, t_2, \ldots, t_m$ .

输入输出样例

输入 #1
3
6 5
101100
1 2
1 3
2 4
5 5
1 6
6 4
100111
2 2
1 4
1 3
1 2
1 1
0
1 1
输出 #1
3
3
1
C++ 编辑器
输入
输出