Pianissimo
시간 제한1초메모리 제한2048 MB
연주된 세기 값과 마디별 셈여림 구간, 셈여림의 순서가 주어질 때, 더 센 셈여림의 음이 더 큰 세기로 연주되지 않은 음의 쌍 개수를 센다.
문제
Composers use dynamics in sheet music to indicate how loud or soft the notes shall be played. Consider an -scale dynamic system:
- ppp: pianississimo (the softest)
- pp: pianissimo (very soft)
- p: piano (soft)
- mp: mezzopiano (moderately soft)
- mf: mezzoforte (moderately loud)
- f: forte (loud)
- ff: fortissimo (very loud)
- fff: fortississimo (the loudest)
When a musician performs, it practically does not matter how absolutely loud or soft a note is played. The audience only hear their relative difference. Suppose we use numbers to describe the absolute power of a note, where larger numbers indicate larger absolute power. Consider a musician who plays all her notes with power up to . When she goes from power to , some audience may think that she goes from p to f, while some others may think that she goes from pp to mf.
The musician’s interpretation must be consistent throughout the entire piece. That is, between two notes of different dynamics, the note with a louder dynamic must always have a strictly larger absolute power. Between two notes of the same dynamic, their power can vary (usually slightly, but there is no strict requirement).
You just heard a musician perform a piece with notes. You know the piece very well and you remember all the dynamics that the composer wrote. How consistent is the musician’s performance according to the written dynamics? You would like to count the unordered pairs of notes that violate the dynamics. Such a pair of notes is not necessarily consecutive and could be far from each other in the sheet music.
입력
The first line of input contains two integers and (), the number of notes and the number of dynamic changes.
The next lines each have an integer between and , giving the absolute power of a note played by the musician. Larger numbers indicate larger absolute power.
The next lines each have a -based index and a dynamic , which mean the composer wrote that starting from note the dynamic should change to . Each dynamic is a string from the dynamics: ppp, pp, p, mp, mf, f, ff, fff. The dynamics have distinct indices and are given in increasing order of their index. The first dynamic always starts from note .
출력
Output a single integer, the number of unordered pairs of notes that violate the dynamics.