Petr Permutation 987E
Petr Permutation 987E
|
ridwanultanvir | Logout
HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP ICPC CHALLENGE 10 YEARS!
Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×
PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION
Petr likes to come up with problems about randomly generated data. This time problem is → Virtual participation
about random permutation. He decided to generate a random permutation this way: he takes
Virtual contest is a way to take part in past
identity permutation of numbers from 1 to n and then 3n times takes a random pair of different contest, as close as possible to participation
elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex on time. It is supported only ICPC mode for
virtual contests. If you've seen these
has also come up with a problem about random permutation. He generates a random problems, a virtual contest is not for you -
permutation just like Petr but swaps elements 7n + 1 times instead of 3n times. Because it is solve these problems in the archive. If you
just want to solve some problem from a
more random, OK?! contest, a virtual contest is not for you -
solve this problem in the archive. Never use
You somehow get a test from one of these problems and now you want to know from which someone else's code, read the tutorials or
communicate with other person during a
one. virtual contest.
In the second line there are n distinct integers between 1 and n — the permutation of size n → Practice
from the test.
You are registered for practice. You can solve
It is guaranteed that all tests except for sample are generated this way: First we choose n — problems unofficially. Results can be found in
the contest status and in the bottom of
the size of the permutation. Then we randomly choose a method to generate a permutation — standings.
the one of Petr or the one of Alex. Then we generate a permutation using chosen method.
Clone Contest
Example
input Copy
5 → Submit?
2 4 5 1 3
Petr Choose
Choose File No file chosen
file:
Note Be careful: there is 50 points penalty for
Please note that the sample is not a valid test (because of limitations for n) and is given only submission which fails the pretests or
resubmission (except failure on the first test,
to illustrate input/output format. Your program still has to print correct answer to this test to denial of judgement or similar verdicts).
get AC. "Passed pretests" submission verdict doesn't
guarantee that the solution is absolutely
correct and it will pass system tests.
Due to randomness of input hacks in this problem are forbidden.
Submit
Each swap change the parity of permutation. 3n and 7n+1 always have different parities, so the solution is just to calculate the parity
of the given permutation and check if it is equal to parity of 3n or to parity of 7n+1.
→ Problem tags
To calculate the parity you can just calculate the number of inversions with your favorite
method (Fenwick tree, Segment tree, mergesort or whatever) in O(nlogn) time. But it is math *1800
easier to calculate the number of cycles in permutation in O(n) time.
https://codeforces.com/contest/987/problem/E 1/2