Logo
(追記) (追記ここまで)

10006번 - Colorful Chain 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB214574628.221%

문제

Little Bytie loves to play with colorful chains. He already has quite an impressive collection, and some of them he likes more than the others. Each chain consists of a certain number of colorful links. Byteasar has noticed that Bytie's sense of aesthetics is very precise. It turns out that Bytie finds a contiguous fragment of a chain nice if it contains exactly l1 links of color c1,l2 links of color c2,…,lm links of color cm, and moreover it contains no links of other colors. A chain's appeal is its number of (contiguous) fragments that are nice. By trial and error, Byteasar has determined the values c1,…,cm and lm,…,lm. Now he would like to buy a new chain, and therefore asks you to write a program to aid him in shopping.

입력

The first line of the standard input gives two integers, n and m (1 ≤ m ≤ n ≤ 1,000,000), separated by a single space. These are the length of the chain and the length of a nice fragment's description. The second line gives m integers, l1,…,lm (1 ≤ li ≤ n), separated by single spaces. The third line gives m integers, c1,…,cm (1 ≤ ci ≤ n, ci≠cj for i≠j), also separated by single spaces. The sequences l1,…,lm and c1,…,cm define a nice fragment of a chain - it has to contain exactly li links of color ci. The fourth line gives n integers, a1,…,an(1 ≤ ai ≤ n), separated by single spaces, that are the colors of successive links of the chain.

출력

Your program is to print a single integer, the number of nice contiguous fragments in the chain, to the first and only line of the standard output.

제한

예제 입력 1

7 3
2 1 1
1 2 3
4 2 1 3 1 2 5

예제 출력 1

2

힌트

The two nice fragments of this chain are 2, 1, 3, 1 and 1, 3, 1, 2.

출처

Olympiad > Polish Olympiad in Informatics > POI 2012/2013 > Stage 3 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /