CF1849C.Binary String Copying
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
给你一个由 n 个字符组成的字符串 s,其中每个字符为 0 或 1。
你将该字符串复制 m 次,记第 i 次复制得到的字符串为 ti。然后,对每个副本恰好执行一次操作:对第 i 个副本 ti,将其子串 [li;ri](即从第 li 个字符到第 ri 个字符的子串,包含两端)进行排序。注意,每次操作仅影响一个副本,且每个副本仅受一次操作影响。
你的任务是计算 t1,t2,…,tm 中互不相同的字符串的个数。注意:初始字符串 s 只有在至少有一个副本经过操作后保持不变时,才被计入答案。
输入格式
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.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m≤2⋅105)—— 分别表示字符串 s 的长度和副本数量。
第二行包含 n 个字符,每个字符为 0 或 1 —— 即字符串 s。
接下来是 m 行。其中第 i 行包含两个整数 li 和 ri(1≤li≤ri≤n)—— 表示对第 i 个副本执行的操作区间。
所有测试用例中 n 的总和不超过 2⋅105;所有测试用例中 m 的总和不超过 2⋅105。
输出格式
Print one integer — the number of different strings among t1,t2,…,tm.
输出一个整数——即 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.
考虑第一个例子。下方的字符串按输入操作的顺序给出。带下划线的子串是被排序的子串:
- 101100 → 011100;
- 101100 → 011100;
- 101100 → 101100;
- 101100 → 101100;
- 101100 → 000111。
在 t1,t2,t3,t4,t5 中共有三个不同的字符串:000111、011100 和 101100。
考虑第二个例子:
- 100111 → 100111;
- 100111 → 001111;
- 100111 → 001111;
- 100111 → 010111。
在 t1,t2,t3,t4 中共有三个不同的字符串:001111、010111 和 100111。
输入解题思路,AI测评打分。不知道怎么写?