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

Lista

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
Platinum V 플래티넘 V
난이도
0.600s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
4
제출 수
25.0%
정답률
레이팅

의견: 0

설명

Mirko received a birthday present from his aunt in the US – a brand-new doubly-linked list (an example of which is shown in the figure below). The list contains \(N\) nodes numbered \(1\) through \(N\). Two types of moves can be done on the list:

A) Move node \(X\) in front of node \(Y\).
B) Move node \(X\) after node \(Y\).

An example of a list with \(N\) nodes.

The list after the move A 1 4.

The list after another move, B 3 5.

Mirko played with his new toy for hours, writing down each move on a piece of paper so that he can reconstruct the list's initial state (nodes \(1\) through \(N\) in order from left to right).

When he decided to reconstruct the list, Mirko was astonished to find that there is no easy way to invert the moves and restore the list's initial state. Mirko cannot know where node \(X\) was prior to each move, only where it ended up.

Seeing how Mirko is still recovering from the shock, write a program that finds a minimal sequence of moves that restored the list's initial state from Mirko's logs.

제약
입력 형식

The first line of input contains two integers \(N\) and \(M\) (\(1 \le N, M \le 100000\)), the number of nodes and the number of moves made by Mirko.

Each of the next \(M\) rows contains a description of a single move made by Mirko – the type of move (A or B) and two integers \(X\) and \(Y\).

출력 형식

Output the minimum number of moves (call this number \(R\)) on the first line.

Each of the next \(R\) lines should contain a description of a single move in the same format as in the input.

Note: The sequence need not be unique.

Scoring

If both the number \(R\) and the sequence of moves are correct, your program will score full points on the test case. If your program outputs the correct number \(R\) and does not output the sequence of moves, or the sequence of moves is incorrect, you will get half of the points for that test case.

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

Subtask 1

90점
예제 1
입력
2 1
A 2 1
출력
1
A 1 2
예제 2
입력
4 3
B 1 2
A 4 3
B 1 4
출력
2
A 1 2
B 4 3
예제 3
입력
6 5
A 1 4
B 2 5
B 4 2
B 6 3
A 3 5
출력
3
A 4 5
B 6 5
A 2 3
문제 정보

riseoj 작성

출처 COCI 2006/2007 Contest 3

평가 및 의견

Lista

개요
출제자 난이도 Platinum V 플래티넘 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Lista

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