結果

問題 No.2568 列辞書順列列
ユーザー tentententen
提出日時 2023-12-04 18:12:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 585 ms / 3,000 ms
コード長 2,108 bytes
コンパイル時間 2,685 ms
コンパイル使用メモリ 90,996 KB
実行使用メモリ 79,268 KB
最終ジャッジ日時 2023-12-04 18:12:28
合計ジャッジ時間 20,178 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,980 KB
testcase_01 AC 52 ms
53,976 KB
testcase_02 AC 288 ms
64,036 KB
testcase_03 AC 307 ms
62,088 KB
testcase_04 AC 460 ms
66,440 KB
testcase_05 AC 406 ms
64,480 KB
testcase_06 AC 410 ms
66,484 KB
testcase_07 AC 422 ms
66,604 KB
testcase_08 AC 413 ms
64,544 KB
testcase_09 AC 472 ms
68,700 KB
testcase_10 AC 496 ms
68,784 KB
testcase_11 AC 470 ms
68,624 KB
testcase_12 AC 502 ms
68,688 KB
testcase_13 AC 487 ms
68,656 KB
testcase_14 AC 498 ms
68,652 KB
testcase_15 AC 485 ms
68,632 KB
testcase_16 AC 498 ms
69,048 KB
testcase_17 AC 585 ms
74,892 KB
testcase_18 AC 575 ms
79,268 KB
testcase_19 AC 463 ms
68,632 KB
testcase_20 AC 484 ms
68,860 KB
testcase_21 AC 456 ms
68,640 KB
testcase_22 AC 494 ms
68,756 KB
testcase_23 AC 483 ms
68,920 KB
testcase_24 AC 483 ms
69,112 KB
testcase_25 AC 476 ms
68,664 KB
testcase_26 AC 473 ms
69,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        long[] dp = new long[n + 1];
        long[] pows = new long[n + 1];
        pows[0] = 1;
        for (int i = 1; i <= n; i++) {
            dp[i] = (dp[i - 1] * m % MOD + sc.nextInt() - 1) % MOD;
            pows[i] = pows[i - 1] * m % MOD;
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int left = sc.nextInt() - 1;
            int right = sc.nextInt();
            sb.append((dp[right] - (dp[left] * pows[right - left] % MOD) + MOD + 1) % MOD).append("\n");
        }
        
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0