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

Tornjevi

설명

Dominik is truly a special student and he constantly enjoys playing with blue and
red cubes of different sizes.
He decided to build towers while following two peculiar rules:
• A cube directly above another cube can never be the same color as that cube.
• All cubes in the tower above some cube must be smaller in size than that
cube.
Dominik opened his toy box which contains exactly \(n\) cubes. For each \(i\) (\(1 \le i \le n\)),
Dominik has exactly one cube of size \(i\), and it is either red or blue.
Dominik got bored of stacking towers, so he came up with \(q\) difficult questions. In each question, Dominik
thinks of two numbers \(l\) and \(r\). He wants to know the minimum number of towers he must build so that
they contain only cubes whose sizes are between \(l\) and \(r\) (inclusive), and such that every tower follows his
peculiar rules. Every cube of a size between \(l\) and \(r\) must be used, i.e., placed in some tower.
Dominik has to study a lot because it’s time for midterms at the university, so he asks you for help in
answering his \(q\) questions.

제약
입력 형식

In the first line, there are two natural numbers \(n\) and \(q\) (\(1 \le n\), \(q \le 1 \cdot 10^{5}\)), the number of cubes and the
number of questions.
In the second line, there is a string \(s\), where the character \(s_{i}\) represents the color of the cube of size \(i\).
Each character of the string will be either "P" or "C".
In each of the following \(q\) lines, there are two numbers \(l_{i}\) and \(r_{i}\) (\(1 \le l_{i} \le r_{i} \le n\)), the left and right
boundaries of Dominik’s query.

출력 형식

In \(q\) lines, print the answers to Dominik’s questions from the problem statement.

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

1

23점

\(1 \le n\), \(q \le 10\)

2

38점

\(1 \le n\), \(q \le 1000\)

3

25점

There will be at most 20 blue cubes.

4

24점

No additional constraints.

예제 1
입력
7 4
PPCPPCC
1 7
1 5
3 7
4 5
출력
3
3
2
2
예제 2
입력
6 2
CCCCCC
1 6
2 5
출력
6
4
예제 3
입력
16 1
PPPCPCCCCCCPPPPP
1 16
출력
6
설명

Clarification of the second example: All the cubes are red, so any tower that contains at least 2
cubes does not follow Dominik’s rules. It follows that each tower contains exactly 1 cube, and the answer
to each question is the number of cubes between l and r, i.e., r −l + 1.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 2

평가 및 의견

Tornjevi

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

Log in to rate problems.

개별 의견

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

풀이 제출

Tornjevi

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