CF1849C.Binary String Copying
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ti . Then you perform exactly one operation on each of the copies: for the i -th copy, you sort its substring [li;ri] (the substring from the li -th character to the ri -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,…,tm . 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≤t≤104 ) — the number of test cases.
The first line of each test case contains two integers n and m ( 1≤n,m≤2⋅105 ) — 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 li and ri ( 1≤li≤ri≤n ) — the description of the operation applied to the i -th copy.
The sum of n over all test cases doesn't exceed 2⋅105 . The sum of m over all test cases doesn't exceed 2⋅105 .
输出格式
Print one integer — the number of different strings among t1,t2,…,tm .
输入输出样例
输入#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:
- 101100 → 011100;
- 101100 → 011100;
- 101100 → 101100;
- 101100 → 101100;
- 101100 → 000111.
There are three different strings among t1,t2,t3,t4,t5 : 000111, 011100 and 101100.
Consider the second example:
- 100111 → 100111;
- 100111 → 001111;
- 100111 → 001111;
- 100111 → 010111.
There are three different strings among t1,t2,t3,t4 : 001111, 010111 and 100111.