CF163E.e-Government
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis.
We know that any of the k citizens can become a member of the Embezzland government. The citizens' surnames are _a_1, _a_2, ..., a__k. All surnames are different. Initially all k citizens from this list are members of the government. The system should support the following options:
- Include citizen a__i to the government.
- Exclude citizen a__i from the government.
- Given a newspaper article text, calculate how politicized it is. To do this, for every active government member the system counts the number of times his surname occurs in the text as a substring. All occurrences are taken into consideration, including the intersecting ones. The degree of politicization of a text is defined as the sum of these values for all active government members.
Implement this system.
Embezzland 最优秀的程序员们正竞相开发一个名为“电子政务”(e-Government)的项目模块——该系统用于自动化地收集统计数据并分析新闻报道。
已知共有 k 位公民可能成为 Embezzland 政府的成员。这些公民的姓氏分别为 a1,a2,…,ak,且所有姓氏互不相同。初始状态下,上述 k 位公民全部为政府成员。该系统需支持以下三种操作:
- 将公民 ai 加入政府;
- 将公民 ai 从政府中移除;
- 给定一篇报纸文章的文本,计算其政治化程度(politicization)。具体方法是:对每一位当前在任的政府成员,统计其姓氏在该文本中作为子串出现的次数(所有出现均被计入,包括相互重叠的 occurrences);该文本的政治化程度即为所有当前在任政府成员对应出现次数之和。
请实现该系统。
输入格式
The first line contains space-separated integers n and k (1 ≤ n, k ≤ 105) — the number of queries to the system and the number of potential government members.
Next k lines contain the surnames _a_1, _a_2, ..., a__k, one per line. All surnames are pairwise different.
Next n lines contain queries to the system, one per line. Each query consists of a character that determines an operation and the operation argument, written consecutively without a space.
Operation "include in the government" corresponds to the character "+", operation "exclude" corresponds to "-". An argument of those operations is an integer between 1 and k — the index of the citizen involved in the operation. Any citizen can be included and excluded from the government an arbitrary number of times in any order. Including in the government a citizen who is already there or excluding the citizen who isn't there changes nothing.
The operation "calculate politicization" corresponds to character "?". Its argument is a text.
All strings — surnames and texts — are non-empty sequences of lowercase Latin letters. The total length of all surnames doesn't exceed 106, the total length of all texts doesn't exceed 106.
第一行包含两个以空格分隔的整数 n 和 k(1≤n,k≤105)——分别表示系统查询次数和潜在政府成员人数。
接下来的 k 行每行包含一个姓氏 a1, a2, …, ak。所有姓氏两两不同。
接下来的 n 行每行包含一条对系统的查询。每条查询由一个表示操作类型的字符及其参数组成,二者连续书写、中间无空格。
操作“加入政府”对应字符 +,操作“移出政府”对应字符 -。这些操作的参数为介于 1 到 k 之间的整数——即参与该操作的公民编号。任意公民均可被任意多次、以任意顺序加入或移出政府。若对已在政府中的公民执行“加入”操作,或对不在政府中的公民执行“移出”操作,则系统状态不变。
操作“计算政治化程度”对应字符 ?。其参数为一段文本。
所有字符串(包括姓氏与文本)均为非空的小写拉丁字母序列。所有姓氏的总长度不超过 106,所有文本的总长度不超过 106。
输出格式
For any "calculate politicization" operation print on a separate line the degree of the politicization of the given text. Print nothing for other operations.
对于任何“计算政治化程度”操作,在单独一行中输出给定文本的政治化程度。对于其他操作,不输出任何内容。
输入输出样例
输入#1
7 3 a aa ab ?aaab -2 ?aaab -3 ?aaab +2 ?aabbaa
输出#1
6 4 3 6
输入解题思路,AI测评打分。不知道怎么写?