포럼
문제 COCI00450

Deda

설명

Little Marica is making up a nonsensical unusual fairy tale and is telling to her grandfather
who keeps interrupting her and asking her stupid intriguing questions.
In Marica’s fairy tale, \(N\) children, denoted with numbers from 1 to \(N\) by their age (from the
youngest denoted with 1, to the oldest denoted with \(N\)), embarked on a train ride. The train
leaves from the station 0 and stops in order at stations 1, 2, 3 ... to infinity.
Each of the following Marica’s statements is of the form: “At stop \(X\), child \(A\) got out”,
where the order of these statements is completely arbitrary. In other words, it does not
depend on the station order. Her grandfather sometimes asks a question of the form:
“Based on the statements so far, of the children denoted with a number greater than
or equal to \(B\), who is the youngest child that rode for \(Y\) or less stops?” If at the
moment the grandfather asks the question it hasn’t been said so far that a child is getting off
the train, we assume that the child is riding for an infinite amount of stops.
Marica must give a correct answer to each of her grandfather’s questions, otherwise the
grandfather will get mad and go to sleep. The answer must be correct in the moment when
the grandfather asks the question, while it can change later given Marica’s new statements,
but that doesn’t matter. Write a program that tracks Marica’s statements and answers her
grandfather’s questions.

제약
입력 형식

The first line of input contains the positive integers \(N\) and \(Q\) (\(2 \le N\), \(Q \le 200\,000\)), the
number of children and the number of statements. Each of the following Q lines describes:

either Marica’s statement of the form “M” \(X\) \(A\), where “M” denotes Marica, and \(X\) and
\(A\) are positive integers (\(1 \le X \le 1\,000\,000\,000\), \(1 \le A \le N\)) from the task,

or her grandfather’s question of the form “D” Y B, where “D” denotes the grandfather,
and \(Y\) and \(B\) are positive integers (\(1 \le Y \le 1\,000\,000\,000\), \(1 \le B \le N\)) from the task.
All of Marica’s statements correspond to different children and at least one line in the input is
her grandfather’s question.

출력 형식

For each grandfather’s question, output the number of the required child in its own line. If no
such child exists, output -1.

예제 1
입력
3 4
M 10 3
M 5 1
D 20 2
D 5 1
출력
3
1
예제 2
입력
10 10
M 20 10
D 1 9
M 2 3
D 17 10
M 20 2
D 8 2
M 40 1
D 25 2
M 33 9
D 37 9
출력
-1
-1
3
2
9
문제 정보

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

출처 COCI 2017/2018 Contest 1

평가 및 의견

Deda

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

Log in to rate problems.

개별 의견

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

풀이 제출

Deda

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