結果

問題 No.469 区間加算と一致検索の問題
ユーザー nebukuro09nebukuro09
提出日時 2016-12-19 01:53:55
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,470 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 97,320 KB
実行使用メモリ 18,280 KB
最終ジャッジ日時 2023-09-02 23:41:40
合計ジャッジ時間 27,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 410 ms
11,112 KB
testcase_01 AC 410 ms
12,080 KB
testcase_02 WA -
testcase_03 AC 414 ms
13,160 KB
testcase_04 AC 415 ms
13,628 KB
testcase_05 AC 417 ms
13,860 KB
testcase_06 AC 418 ms
14,336 KB
testcase_07 AC 417 ms
14,420 KB
testcase_08 AC 420 ms
14,408 KB
testcase_09 AC 414 ms
12,272 KB
testcase_10 AC 420 ms
14,664 KB
testcase_11 AC 412 ms
12,404 KB
testcase_12 AC 418 ms
14,388 KB
testcase_13 AC 416 ms
11,884 KB
testcase_14 AC 412 ms
11,808 KB
testcase_15 AC 413 ms
12,876 KB
testcase_16 AC 419 ms
14,912 KB
testcase_17 AC 418 ms
13,872 KB
testcase_18 AC 418 ms
13,888 KB
testcase_19 WA -
testcase_20 AC 418 ms
13,808 KB
testcase_21 AC 414 ms
12,560 KB
testcase_22 AC 410 ms
10,888 KB
testcase_23 AC 472 ms
18,232 KB
testcase_24 AC 470 ms
17,248 KB
testcase_25 AC 470 ms
18,248 KB
testcase_26 AC 472 ms
17,424 KB
testcase_27 AC 471 ms
17,976 KB
testcase_28 AC 471 ms
17,308 KB
testcase_29 AC 470 ms
17,228 KB
testcase_30 AC 470 ms
17,964 KB
testcase_31 AC 471 ms
17,752 KB
testcase_32 AC 471 ms
17,296 KB
testcase_33 AC 566 ms
17,236 KB
testcase_34 AC 563 ms
17,496 KB
testcase_35 AC 562 ms
17,280 KB
testcase_36 AC 561 ms
17,768 KB
testcase_37 AC 562 ms
17,216 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 410 ms
11,212 KB
testcase_49 AC 410 ms
11,392 KB
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;


long powmod(long a, long x, long m) {
    long ret = 1;
    while (x >= 1) {
        if (x % 2 == 1)
            ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

void main() {
    immutable long BASE = 1234567891;
    immutable long MOD = 9997954969;
    auto powsum = new long[](10^^6+1);
    pragma(inline, true) {
        powsum[0] = 1;
        foreach (i; 0..10^^6)
            powsum[i+1] = (powsum[i] + powmod(BASE, i+1, MOD)) % MOD;
    }

    auto s = readln.split.map!(to!int);
    int N = s[0];
    int Q = s[1];
    long L, R, K;

    int[long] hash_table;
    hash_table[0] = 0;
    long prev = 0;

    foreach (i; 1..Q+1) {
        auto q = readln.split;
        if (q[0] == "!") {
            L = q[1].to!long;
            R = q[2].to!long;
            K = q[3].to!long;
            long plus = ((abs(K) * powmod(BASE, L, MOD)) % MOD * powsum[R-L-1]) % MOD;
            if (K >= 0)
                prev = (prev + plus) % MOD;
            else if (plus > prev)
                prev = (prev - plus) % MOD + MOD;
            else
                prev = (prev - plus) % MOD;
            if (!(prev in hash_table))
                hash_table[prev] = i;
        }
        else {
            hash_table[prev].writeln;
        }
    }
}
0