Substring
Time limit2sMemory limit512 MB
A window [l, r] over a string moves by changing one endpoint at a time, and after each of m queries you must count how many distinct substring values have appeared across all windows visited.
- Level
Hard8 of 10
- Topics
- String, Sorting, String matching, Implementation
- Solved
- No attempts yet
Problem
You are given a string of length and queries. Each query () is one of "L++", "L--", "R++", "R--". For the -th query , define and as follows.
- L++: ,
- L--: ,
- R++: ,
- R--: ,
Here .
Find the number of distinct strings among the substrings ().
Input
The input is given in the following format.
n m
s
q1
q2
…
qm
Output
Output the answer on one line.
Constraints
- The string consists of lowercase English letters.
- () is one of "L++", "L--", "R++", "R--".
- ()