CF1849C.Binary String Copying

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss consisting of nn characters 0 and/or 1.

You make mm copies of this string, let the ii -th copy be the string tit_i . Then you perform exactly one operation on each of the copies: for the ii -th copy, you sort its substring [li;ri][l_i; r_i] (the substring from the lil_i -th character to the rir_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 t1,t2,,tmt_1, t_2, \ldots, t_m . Note that the initial string ss should be counted only if at least one of the copies stays the same after the operation.

输入格式

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

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

The second line contains nn characters 0 and/or 1 — the string ss .

Then mm lines follow. The ii -th of them contains two integers lil_i and rir_i ( 1lirin1 \le l_i \le r_i \le n ) — the description of the operation applied to the ii -th copy.

The sum of nn over all test cases doesn't exceed 21052 \cdot 10^5 . The sum of mm over all test cases doesn't exceed 21052 \cdot 10^5 .

输出格式

Print one integer — the number of different strings among t1,t2,,tmt_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

说明/提示

Consider the first example. Copies below are given in order of the input operations. Underlined substrings are substrings that are sorted:

  1. 101100 \rightarrow 011100;
  2. 101100 \rightarrow 011100;
  3. 101100 \rightarrow 101100;
  4. 101100 \rightarrow 101100;
  5. 101100 \rightarrow 000111.

There are three different strings among t1,t2,t3,t4,t5t_1, t_2, t_3, t_4, t_5 : 000111, 011100 and 101100.

Consider the second example:

  1. 100111 \rightarrow 100111;
  2. 100111 \rightarrow 001111;
  3. 100111 \rightarrow 001111;
  4. 100111 \rightarrow 010111.

There are three different strings among t1,t2,t3,t4t_1, t_2, t_3, t_4 : 001111, 010111 and 100111.

首页