結果

問題 No.2568 列辞書順列列
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-02 16:40:40
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 214 ms / 3,000 ms
コード長 1,514 bytes
コンパイル時間 12,909 ms
コンパイル使用メモリ 157,948 KB
実行使用メモリ 223,920 KB
最終ジャッジ日時 2023-12-02 16:41:10
合計ジャッジ時間 15,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
32,548 KB
testcase_01 AC 70 ms
32,548 KB
testcase_02 AC 138 ms
62,116 KB
testcase_03 AC 133 ms
61,732 KB
testcase_04 AC 190 ms
81,260 KB
testcase_05 AC 187 ms
81,256 KB
testcase_06 AC 188 ms
81,376 KB
testcase_07 AC 187 ms
81,260 KB
testcase_08 AC 189 ms
81,256 KB
testcase_09 AC 192 ms
76,712 KB
testcase_10 AC 199 ms
76,712 KB
testcase_11 AC 200 ms
76,712 KB
testcase_12 AC 210 ms
77,084 KB
testcase_13 AC 214 ms
77,084 KB
testcase_14 AC 209 ms
77,084 KB
testcase_15 AC 210 ms
77,084 KB
testcase_16 AC 207 ms
77,084 KB
testcase_17 AC 197 ms
76,980 KB
testcase_18 AC 197 ms
76,984 KB
testcase_19 AC 196 ms
76,980 KB
testcase_20 AC 192 ms
76,980 KB
testcase_21 AC 201 ms
76,980 KB
testcase_22 AC 197 ms
76,984 KB
testcase_23 AC 196 ms
77,108 KB
testcase_24 AC 198 ms
76,980 KB
testcase_25 AC 199 ms
76,980 KB
testcase_26 AC 195 ms
223,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (89 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, q) = (c[0], c[1], c[2]);
        var a = NList;

        var mod = 998_244_353;
        var mul = new long[n + 1];
        mul[n] = 1;
        for (var i = n - 1; i >= 0; --i) mul[i] = mul[i + 1] * m % mod;
        var hash = new long[n + 1];
        for (var i = 0; i < n; ++i) hash[i + 1] = (hash[i] + mul[i + 1] * (a[i] - 1) % mod) % mod;
        var rev = new long[n + 1];
        rev[0] = Exp(mul[0], mod - 2, mod);
        for (var i = 1; i < rev.Length; ++i) rev[i] = rev[i - 1] * m % mod;

        var ans = new long[q];
        for (var i = 0; i < q; ++i)
        {
            c = NList;
            ans[i] = ((hash[c[1]] + mod - hash[c[0] - 1]) % mod * rev[c[1]] % mod + 1) % mod;
        }
        WriteLine(string.Join("\n", ans));
    }
    static long Exp(long n, long p, int mod)
    {
        long _n = n % mod;
        var _p = p;
        var result = 1L;
        if ((_p & 1) == 1) result *= _n;
        while (_p > 0)
        {
            _n = _n * _n % mod;
            _p >>= 1;
            if ((_p & 1) == 1) result = result * _n % mod;
        }
        return result;
    }
}
0