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

Stogovi

Unrated 레이팅 미적용
난이도
1s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

\(3^{rd}\) round, November \(29^{th}\), 2014
Mirko is playing with stacks. In the beginning of the game, he has an empty stack denoted with number 0. In the
i^{th} step of the game he will choose an existing stack denoted with v, copy it and do one of the following actions:
a. place number i on top of the new stack
b. remove the number from the top of the new stack
c. choose another stack denoted with w and count how many different numbers exist that are in the new stack
and in the stack denoted with w
The newly created stack is denoted with i.
Mirko doesn’t like to work with stacks so he wants you to write a programme that will do it for him. For each
operation of type \(b\) output the number removed from stack and for each operation of type \(c\) count the required
numbers and output how many of them there are.

제약
입력 형식

The first line of input contains the integer N (1 ⩽N ⩽300 000), the number of steps in Mirko’s game.
The steps of the game are chronologically denoted with the first N integers.
The i^{th} of the following N lines contains the description of the i^{th} step of the game in one of the following three
forms:
• "a v" for operation of type \(a\).
• "b v" for operation of type \(b\).
• "c v w" for operation of type \(c\).
The first character in the line denotes the type of operation and the following one or two denote the accompanying
stack labels that will always be integers from the interval [0, \(i - 1\)].
For each operation of type \(b\), the stack we’re removing the element from will not be empty.

출력 형식

For each operation type \(b\) or \(c\) output the required number, each in their own line, in the order the operations
were given in the input.

예제 1
입력
5
a 0
a 1
b 2
c 2 3
b 4
11
a 0
a 1
a 2
a 3
a 2
c 4 5
a 5
a 6
c 8 7
b 8
b 8
출력
output
2
1
2
2
2
8
8
설명

Clarification of the first example: In the beginning, we have the stack S0 = {}. In the first step, we copy S0 and place
number 1 on top, so S1 = {1}. In the second step, we copy S1 and place 2 on top of it, S2 = {1, 2}. In the third step we
copy S2 and remove number 2 from it, S3 = {1}. In the fourth step we copy S2 and denote the copy with S4, then count
the numbers appearing in the newly created stack S4 and stack S3, the only such number is number 1 so the solution is 1.
In the fifth step we copy S4 and remove number 2 from it, S5 = {1}.

문제 정보

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

출처 COCI 2014/2015 Contest 3

평가 및 의견

Stogovi

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

Log in to rate problems.

개별 의견

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

풀이 제출

Stogovi

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