RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0451

No Time to Paint

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie has recently received a painting set, and she wants to paint the long
fence at one end of her pasture. The fence consists of \(N\) consecutive 1-meter
segments (\(1\le N\le 10^5\)). Bessie has 26 different colors available, which
she labels with the letters 'A' through 'Z' in increasing order of darkness ('A'
is a very light color, and 'Z' is very dark). She can therefore describe the
desired color she wants to paint each fence segment as a length-\(N\) string where
each character is a letter.

Initially, all fence segments are uncolored. Bessie can color any contiguous
range of segments with a single color in a single brush stroke as long as she
never paints a lighter color over a darker color (she can only paint darker
colors over lighter colors).

For example, an initially uncolored segment of length four can be colored as
follows:

.... -> BBB. -> BBLL -> BQQL

Running short on time, Bessie thinks she may need to leave some consecutive
range of fence segments unpainted! Currently, she is considering \(Q\) candidate
ranges (\(1\le Q\le 10^5\)), each described by by two integers \((a,b)\) with
\(1 \leq a \leq b \leq N\) giving the indices of endpoints of the range
\(a \ldots b\) of segments to be left unpainted.

For each candidate range, what is the minimum number of strokes needed to paint
every fence segment outside those in the range with its desired color while
leaving all fence segments inside the range uncolored? Note that Bessie does
not actually do any painting during this process, so the answers for each
candidate range are independent.

Problem credits: Andi Qu and Brian Dean

제약

SCORING

  • Test cases 1-4 satisfy \(N,Q\le 100\).
  • Test cases 5-7 satisfy \(N,Q\le 5000\).
  • Test cases 8-13 satisfy no additional constraints.

Problem credits: Andi Qu and Brian Dean

입력 형식

The first line contains \(N\) and \(Q\).

The next line contains a string of length \(N\) characters representing the
desired color for each fence segment.

The next \(Q\) lines each contain two space-separated integers \(a\) and \(b\)
representing a candidate range to possibly leave unpainted.

출력 형식

For each of the \(Q\) candidates, output the answer on a new line.

예제 1
입력
8 2
ABBAABCB
3 6
1 4
출력
4
3
설명

In this example, excluding the sub-range corresponding to the desired pattern
\(\texttt{BAAB}\) requires four strokes to paint while excluding \(\texttt{ABBA}\)
requires only three.

.... -> AA.. -> ABBB -> ABCB
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2020-2021 > January > Silver

태그

평가 및 의견

No Time to Paint

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

No Time to Paint

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