#P5460. [BJOI2016] IP地址

    ID: 6198 远端评测题 2000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串2016各省省选北京O2优化字典树 Trie

[BJOI2016] IP地址

Problem Description

Each entry in the routing table corresponds to a rule of the form 1011101?????????????????????????, which matches an ip\texttt{ip} whose prefix fits the given pattern.

When multiple rules match, the one with the longest prefix takes effect. At any time, there will not be multiple matching rules with the same prefix length. At each moment, either a rule is added, or some previously added rule expires.

Given a list of ip\texttt{ip} addresses, for each ip\texttt{ip}, ask how many times the effective matched rule changes within a given time interval.

For example, suppose there is a sequence of events:

Add\texttt{Add} 110110
Add\texttt{Add} 1111
Del\texttt{Del} 110110
Del\texttt{Del} 1111
Add\texttt{Add} 110110

Then, for the ip\texttt{ip} address 11011101001001010101011101000010, the effective matched rules after these five moments are:

110110 (the first one),
110110 (the first one),
1111 (the second one),
empty,
110110 (the third one).

During the period from after the second event to after the fifth event, it changes a total of 33 times.

Input Format

The first line contains two positive integers n,qn,q, representing the number of events and the number of queries.

The next nn lines each describe an event in the following format:

Add\texttt{Add} ss means creating a new rule that matches all ip\texttt{ip} addresses with prefix ss.
Del\texttt{Del} ss means deleting (expiring) the current rule corresponding to prefix ss. It is guaranteed that such a rule exists and has not been deleted before.

The next qq lines each contain an ip\texttt{ip} and two positive integers a,ba,b, meaning: during the time period from after the aa-th event to the bb-th event, how many times does the effective rule matched by this ip\texttt{ip} change? The ip\texttt{ip} is given as a binary string of 0 and 1.

Output Format

For each query, output one line with an integer representing the answer.

5 1
Add 110
Add 11
Del 110
Del 11
Add 110
11011101001001010101011101000010 2 5
3

Hint

Constraints

  • 1n,q1051\le n,q \le 10^5.
  • s32|s|\le32.
  • Each ip\texttt{ip} has length 3232.

Translated by ChatGPT 5