Submission #3017198


Source Code Expand

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int M;
    static int D;
    static int[] A;

    static int D_MAX_BIT;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        D = sc.nextInt();
        A = sc.nextIntArray(M);

        PrintWriter pw = new PrintWriter(System.out);
        for (int each : solve()) {
            pw.println(each);
        }
        pw.flush();
    }

    static int[] solve() {
        D_MAX_BIT = Integer.toBinaryString(D).length();

        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = i;
        }
        for (int a : A) {
            int t = B[a];
            B[a] = B[a-1];
            B[a-1] = t;
        }

        int[] T = new int[N];
        for (int i = 0; i < N; i++) {
            int b = B[i];
            T[b] = i;
        }

        int[][] TS = new int[D_MAX_BIT][];
        TS[0] = T;
        for (int b = 1; b < D_MAX_BIT; b++) {
            int[] prev = TS[b-1];
            int[] curr = new int[N];

            for (int i = 0; i < N; i++) {
                // i -> prev[i] -> prev[prev[i]]
                curr[i] = prev[prev[i]];
            }
            TS[b] = curr;
        }

        int[] TT = new int[N];
        for (int i = 0; i < N; i++) {
            TT[i] = i;
        }
        for (int b = 0; b < D_MAX_BIT; b++) {
            if( (D & 1 << b) == 0 ) continue;

            for (int i = 0; i < N; i++) {
                TT[i] = TS[b][TT[i]];
            }
        }

        int[] ANS = new int[N];
        for (int i = 0; i < N; i++) {
            ANS[i] = TT[i] + 1;
        }
        return ANS;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}

Submission Info

Submission Time
Task D - 阿弥陀
User kusomushi
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 3427 Byte
Status AC
Exec Time 316 ms
Memory 54056 KB

Judge Result

Set Name Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 10 / 10 20 / 20 20 / 20 50 / 50
Status
AC × 9
AC × 18
AC × 18
AC × 29
Set Name Test Cases
Subtask1 sample_1.txt, 01_i.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt
Subtask2 sample_1.txt, sample_2.txt, sample_3.txt, 02_i.txt, 02_p.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_rp01.txt, 02_rp02.txt, 02_rp03.txt, 02_rp04.txt, 02_rp05.txt
Subtask3 sample_1.txt, sample_2.txt, 03_i.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt
Subtask4 sample_1.txt, sample_2.txt, sample_3.txt, 04_i.txt, 04_p1.txt, 04_p2.txt, 04_random01.txt, 04_random02.txt, 04_random03.txt, 04_random04.txt, 04_random05.txt, 04_random06.txt, 04_random07.txt, 04_random08.txt, 04_random09.txt, 04_random10.txt, 04_random11.txt, 04_random12.txt, 04_random13.txt, 04_rp01.txt, 04_rp02.txt, 04_rp03.txt, 04_rp04.txt, 04_rp05.txt, 04_rp06.txt, 04_rp07.txt, 04_rp08.txt, 04_rp09.txt, 04_rp10.txt
Case Name Status Exec Time Memory
01_i.txt AC 260 ms 42280 KB
01_random01.txt AC 69 ms 20564 KB
01_random02.txt AC 69 ms 21204 KB
01_random03.txt AC 69 ms 17876 KB
01_random04.txt AC 91 ms 20180 KB
01_random05.txt AC 185 ms 31972 KB
01_random06.txt AC 236 ms 40856 KB
01_random07.txt AC 259 ms 41640 KB
02_i.txt AC 94 ms 19284 KB
02_p.txt AC 80 ms 19156 KB
02_random01.txt AC 68 ms 17748 KB
02_random02.txt AC 70 ms 18772 KB
02_random03.txt AC 94 ms 19156 KB
02_random04.txt AC 73 ms 20564 KB
02_random05.txt AC 112 ms 22100 KB
02_random06.txt AC 152 ms 33620 KB
02_random07.txt AC 188 ms 41172 KB
02_random08.txt AC 192 ms 41652 KB
02_rp01.txt AC 88 ms 21716 KB
02_rp02.txt AC 79 ms 18644 KB
02_rp03.txt AC 91 ms 21716 KB
02_rp04.txt AC 87 ms 19028 KB
02_rp05.txt AC 79 ms 18644 KB
03_i.txt AC 71 ms 23252 KB
03_random01.txt AC 98 ms 18772 KB
03_random02.txt AC 156 ms 35412 KB
03_random03.txt AC 140 ms 31700 KB
03_random04.txt AC 150 ms 34004 KB
03_random05.txt AC 121 ms 22484 KB
03_random06.txt AC 107 ms 20820 KB
03_random07.txt AC 113 ms 21844 KB
03_random08.txt AC 79 ms 19540 KB
03_random09.txt AC 123 ms 23636 KB
03_random10.txt AC 161 ms 26760 KB
03_random11.txt AC 156 ms 33776 KB
03_random12.txt AC 158 ms 33752 KB
03_random13.txt AC 149 ms 33620 KB
03_random14.txt AC 144 ms 28756 KB
03_random15.txt AC 115 ms 24532 KB
04_i.txt AC 316 ms 48456 KB
04_p1.txt AC 258 ms 44728 KB
04_p2.txt AC 248 ms 45912 KB
04_random01.txt AC 226 ms 43868 KB
04_random02.txt AC 188 ms 34728 KB
04_random03.txt AC 168 ms 31188 KB
04_random04.txt AC 195 ms 42328 KB
04_random05.txt AC 203 ms 41976 KB
04_random06.txt AC 219 ms 48140 KB
04_random07.txt AC 238 ms 40272 KB
04_random08.txt AC 234 ms 40828 KB
04_random09.txt AC 289 ms 43276 KB
04_random10.txt AC 209 ms 36060 KB
04_random11.txt AC 290 ms 47636 KB
04_random12.txt AC 292 ms 49656 KB
04_random13.txt AC 298 ms 54056 KB
04_rp01.txt AC 281 ms 43304 KB
04_rp02.txt AC 246 ms 42184 KB
04_rp03.txt AC 268 ms 43536 KB
04_rp04.txt AC 267 ms 44240 KB
04_rp05.txt AC 262 ms 45136 KB
04_rp06.txt AC 252 ms 41956 KB
04_rp07.txt AC 262 ms 45004 KB
04_rp08.txt AC 264 ms 44136 KB
04_rp09.txt AC 266 ms 43592 KB
04_rp10.txt AC 263 ms 41296 KB
sample_1.txt AC 70 ms 19028 KB
sample_2.txt AC 71 ms 20948 KB
sample_3.txt AC 70 ms 17492 KB