CF710F.String Set Queries
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:768MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You should process m queries over a set D of strings. Each query is one of three kinds:
- Add a string s to the set D. It is guaranteed that the string s was not added before.
- Delete a string s from the set D. It is guaranteed that the string s is in the set D.
- For the given string s find the number of occurrences of the strings from the set D. If some string p from D has several occurrences in s you should count all of them.
Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query of the third type. Use functions fflush in C++ and BufferedWriter.flush in Java languages after each writing in your program.
你需要处理关于字符串集合 D 的 m 个查询。每个查询属于以下三种类型之一:
- 将字符串 s 加入集合 D。保证字符串 s 之前未被加入过。
- 从集合 D 中删除字符串 s。保证字符串 s 当前存在于集合 D 中。
- 对于给定的字符串 s,求集合 D 中所有字符串在 s 中的出现次数之和。若集合 D 中某字符串 p 在 s 中出现了多次,则每次出现均需单独计数。
注意:本题要求在线处理。这意味着你不能一次性读入全部输入;你只能在输出上一个第 3 类查询的答案之后,才能读取下一个查询。请在每次输出后,使用 C++ 中的 fflush 函数或 Java 中的 BufferedWriter.flush 方法刷新输出缓冲区。
输入格式
The first line contains integer m (1 ≤ m ≤ 3·105) — the number of queries.
Each of the next m lines contains integer t (1 ≤ t ≤ 3) and nonempty string s — the kind of the query and the string to process. All strings consist of only lowercase English letters.
The sum of lengths of all strings in the input will not exceed 3·105.
第一行包含一个整数 m(1≤m≤3⋅105)—— 查询的数量。
接下来的 m 行中,每行包含一个整数 t(1≤t≤3)和一个非空字符串 s —— 查询的类型以及待处理的字符串。所有字符串仅由小写英文字母组成。
输入中所有字符串的长度总和不超过 3⋅105。
输出格式
For each query of the third kind print the only integer c — the desired number of occurrences in the string s.
对于每种第三类查询,输出唯一的整数 c——即字符串 s 中目标子串的出现次数。
输入输出样例
输入#1
5 1 abc 3 abcabc 2 abc 1 aba 3 abababc
输出#1
2 2
输入#2
10 1 abc 1 bcd 1 abcd 3 abcd 2 abcd 3 abcd 2 bcd 3 abcd 2 abc 3 abcd
输出#2
3 2 1 0
输入解题思路,AI测评打分。不知道怎么写?