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

Genijalac

Platinum II 플래티넘 II
난이도
5s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

Mirko is a genius. But the purpose of his inventions is not always obvious. His latest invention, the Shuffle-o-matic 3175, is one of those.

The Shuffle-o-matic is used in a very special way. First Mirko places \(N\) paper cards, with the numbers \(1\) to \(N\) printed on them, on the Shuffle-o-matic working surface. Then he inputs the shuffle sequence in the special input console and hits the go button. The machine then reads the paper cards and outputs the read sequence of numbers on its output tape. It then shuffles the cards according to the shuffle sequence. After that it reads the newly obtained sequence and writes it onto a new line on its output tape. Then it proceeds to shuffle the cards again according to the same shuffle sequence, scans and writes the output to the tape. The machine does this until it runs out of tape.

After experimenting with the machine Mirko decided to rest a bit on the floor. There he noticed a piece of output tape. The piece is neatly cut just before the \(A\)-th output row and just after the \(B\)-th output row. It is also missing the first \(C\) numbers and the last \(D\) numbers in all rows.

He now wonders how many rows on that piece of paper have the property that all the numbers in the row that are still on the paper are in the exact same spot they were in before all the shuffling began.

제약

Test cases worth 40% total points have A, B, C, D, \(N \le 2000\).

입력 형식

The first line of input contains the integers \(N\), \(A\), \(B\), \(C\) and \(D\) in that order (\(1 \le N \le 500\,000\), \(A \le B \le 10^{12}\), \(0 \le C, D \le N\), \(C + D < N\)).

The second line contains the shuffle sequence, given as a permutation of the numbers \(1\) to \(N\). If the \(k\)-th number in the shuffle sequence is \(x\), then after each shuffle the \(k\)-th element in the resulting sequence is the \(x\)-th element of the previous sequence.

출력 형식

In the first and only line of output, print the number of rows that have the property Mirko is looking for.

Scoring: Test cases worth \(40\%\) of total points have \(A, B, C, D, N \le 2000\).

First sample description: the Shuffle-o-matic outputs the rows 1 2 3 4, 1 3 4 2, 1 4 2 3, 1 2 3 4, 1 3 4 2, 1 4 2 3, 1 2 3 4, … On the cut piece (rows \(1\) to \(5\), with the last number of each row missing) Mirko sees 1 2 3, 1 3 4, 1 4 2, 1 2 3, 1 3 4. Only the first and fourth of these rows keep every visible number in its original place.

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

Subtask 1

48점

\(A, B, C, D, N \le 2000\)

Subtask 2

72점

No additional constraints (\(N \le 500\,000\), \(B \le 10^{12}\)).

예제 1
입력
4 1 5 0 1
1 3 4 2
출력
2
예제 2
입력
7 3 8 1 2
2 3 1 6 4 7 5
출력
0
예제 3
입력
6 2 11 3 0
6 3 5 4 2 1
출력
1
문제 정보

riseoj 작성

출처 COCI 2009/2010 Contest 1

평가 및 의견

Genijalac

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

Log in to rate problems.

개별 의견

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

풀이 제출

Genijalac

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