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

E. Exchange Students

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
설명

A group of \(n\) exchange students at Reykjavik University is lining up to get their group photo taken. From left to right, the heights of the students are \(g_1, g_2, \ldots, g_n\). However, the photographer would like to rearrange the students such that the order of their heights becomes \(h_1, h_2, \ldots, h_n\). In order to do this, the photographer will repeatedly exchange two exchange students. Two exchange students can only be exchanged if they can see each other, that is, if every student in between them has strictly smaller height than the two students to be exchanged.

Determine the minimum number of exchanges needed to arrange the students in the photographer's preferred order, and find a suitable sequence of exchanges of this minimal length. The photographer only has time for at most \(2\cdot 10^5\) exchanges. If more are needed, you only need to determine the first \(2\cdot 10^5\) exchanges.

제약
입력 형식

The input consists of:
- One line with an integer \(n\) (\(1\leq n \leq 3\cdot 10^5\)), the number of students.
- One line with \(n\) integers \(g_1, g_2, \ldots, g_n\) (\(1\leq g_i\leq 10^9\)), the heights of the students.
- One line with \(n\) integers \(h_1, h_2, \ldots, h_n\) (\(1\leq h_i\leq 10^9\)), the order of heights the photographer prefers.

It is guaranteed that \((h_1, \ldots, h_n)\) is a permutation of \((g_1, \ldots, g_n)\).

출력 형식

First output an integer \(s\), the minimum number of exchanges needed. Then print \(\min(s, 2\cdot 10^5)\) exchanges, each consisting of two integers \(i\) and \(j\), the one-based positions of the students that must be exchanged in this step.

If there are multiple valid solutions, you may print any one of them.

예제 1
입력
3
2 1 3
3 1 2
출력
1
1 3
예제 2
입력
5
6 7 5 9 6
9 6 7 6 5
출력
4
3 4
4 5
1 2
1 3
문제 정보

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

출처 ICPC NWERC 2021

평가 및 의견

E. Exchange Students

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

Log in to rate problems.

개별 의견

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

풀이 제출

E. Exchange Students

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