#P3560. [POI 2013] LAN-Colorful Chain
[POI 2013] LAN-Colorful Chain
Description
Little Bytie loves to play with colorful chains. Each chain consists of a certain number of colorful links. Bytie finds a contiguous fragment of a chain nice if it contains exactly links of color for every in , and moreover contains no links of any other colors. The appeal of a chain is the number of its contiguous fragments that are nice.
Given a sequence of length representing the colors of the chain and conditions (each condition gives a color and a required count ), count how many contiguous substrings are nice, that is:
- For every among the conditions, the substring contains exactly occurrences of .
- For any color not listed among the conditions, the substring contains none of it.
Input Format
- The first line contains two integers and (). These are the length of the chain and the number of conditions.
- The second line contains integers ().
- The third line contains integers (). These define that a nice fragment must contain exactly links of color for each and no links of any other colors.
- The fourth line contains integers (), the colors of successive links of the chain.
Output Format
Print a single integer, the number of nice contiguous fragments in the chain.
7 3
2 1 1
1 2 3
4 2 1 3 1 2 5
2
Hint
Constraints:
For of the testdata, and .
Translated by ChatGPT 5
京公网安备 11011102002149号