oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

gugdance Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

gugdance.html

Problem Description

Gug is having fun with a dance. In Gug Dance, there are a total of N dancing mats, numbered from 0 to N-1. There are N minions, with minion i standing on dance mat i. Each dance mat i has a number Ai written on it, between 0 to N-1 and the number on each dance mat is unique.

When Gug shouts 'banana', the minion standing on dance mat i will move to dance mat Ai. Peanut finds himself watching this Gug Dance, after Gug shouts 'banana' twice. The minion standing at dance mat i originally is at dance mat Bi after the two shouts of 'banana'. However, Peanut cannot see the numbers on the dance mats. Given B, construct the array A. It is guaranteed that there is at least one possible array.

Input

The first line of input will consist of one integer, N.

The second line of input will consist of N integers, representing the array B. B will be a permutation of 0...N-1.

Output

The output should contain one line with N integers, the array A satisfying the above conditions. A should also be a permutation of 0...N-1.

Limits

Subtask 1 (26%): 1 ≤ N ≤ 8.

Subtask 2 (30%): 1 ≤ N ≤ 500000, Bi = (i + 1) % N.

Subtask 3 (44%): 1 ≤ N ≤ 500000.

Subtask 4 (0%): Sample Testcases.

Sample Input 1

4
1 0 3 2

Sample Output 1

2 3 1 0

Sample Input 2

5
1 2 3 4 0

Sample Output 2

3 4 0 1 2

Tags

Graph Theory

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
126221s256MBMinimum
230211s256MBMinimum
344621s256MBMinimum
4021s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o gugdance -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.