포럼
문제 COCI00189

Gitara

설명

Darko has a new imaginary extraterrestrial friend with a billion fingers. The extraterrestrial soon took hold of his guitar, found a simple melody online, and started playing it.

The guitar, as usual, has six strings denoted by numbers \(1\) through \(6\). Each string is divided into \(P\) frets denoted by numbers \(1\) through \(P\).

A melody is a sequence of tones, where each tone is produced by picking a string pressed on a specific fret (e.g. the 4th string pressed on the 8th fret). If a string is pressed on several frets, the produced tone will be the one corresponding to the highest of those frets.

For instance, if the 3rd string is already pressed on the 5th fret, and the tone which corresponds to the 7th fret is to be produced, the string can be pressed on the 7th fret and picked without releasing the 5th fret, since only the highest one affects the tone produced (7th in this case). Similarly, if a tone that corresponds to the 2nd fret on the same string is next to be produced, it is necessary to release both the 5th and 7th frets.

Write a program which computes the minimum number of finger movements needed to produce the given melody. Note that pressing or releasing a single fret counts as one finger move. String picking does not count as a finger move.

제약
입력 형식

The first line of input contains two positive integers separated by a single space, \(N\) (\(N \le 500\,000\)) and \(P\) (\(2 \le P \le 300\,000\)). They represent the number of tones in the melody and the number of frets, respectively.

The following \(N\) lines describe the tones — the ordinal of the string and the ordinal of the fret, respectively, in the same order as the extraterrestrial plays them.

출력 형식

In a single line of output, print the minimum number of finger movements.

First sample description: all the tones are produced by picking the 2nd string. First, the frets \(8\), \(10\), \(12\) are pressed, in order (three movements). Then, the 12th fret is released to produce the second tone again (fourth movement). Finally, the 5th fret is pressed followed by the release of frets \(10\) and \(12\) (a total of seven movements).

서브태스크
서브태스크점수설명

Test 1

10점

None

Test 2

10점

None

Test 3

10점

None

Test 4

10점

None

Test 5

10점

None

Test 6

10점

None

Test 7

10점

None

Test 8

10점

None

Test 9

10점

None

Test 10

10점

None

예제 1
입력
5 15
2 8
2 10
2 12
2 10
2 5
출력
7
예제 2
입력
7 15
1 5
2 3
2 5
2 7
2 4
1 5
1 3
출력
9
문제 정보

riseoj 작성

출처 COCI 2010/2011 Contest 7

평가 및 의견

Gitara

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Gitara

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8