Genijalac
의견: 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}\)). |
4 1 5 0 1
1 3 4 227 3 8 1 2
2 3 1 6 4 7 506 2 11 3 0
6 3 5 4 2 11평가 및 의견
Genijalac
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Genijalac