結果

問題 No.469 区間加算と一致検索の問題
ユーザー nebukuro09nebukuro09
提出日時 2016-12-19 19:25:09
言語 D
(dmd 2.106.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,479 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 111,628 KB
実行使用メモリ 18,504 KB
最終ジャッジ日時 2023-09-02 23:49:31
合計ジャッジ時間 28,269 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 406 ms
11,984 KB
testcase_01 AC 403 ms
11,080 KB
testcase_02 AC 404 ms
11,000 KB
testcase_03 AC 409 ms
13,304 KB
testcase_04 AC 407 ms
11,832 KB
testcase_05 AC 412 ms
12,052 KB
testcase_06 AC 414 ms
14,468 KB
testcase_07 AC 415 ms
14,652 KB
testcase_08 AC 414 ms
13,612 KB
testcase_09 AC 409 ms
11,680 KB
testcase_10 AC 413 ms
12,404 KB
testcase_11 AC 409 ms
12,144 KB
testcase_12 AC 416 ms
14,712 KB
testcase_13 AC 412 ms
13,528 KB
testcase_14 AC 408 ms
11,036 KB
testcase_15 AC 409 ms
12,036 KB
testcase_16 AC 414 ms
15,076 KB
testcase_17 AC 411 ms
13,336 KB
testcase_18 AC 412 ms
15,044 KB
testcase_19 AC 407 ms
12,352 KB
testcase_20 AC 416 ms
15,968 KB
testcase_21 AC 407 ms
12,552 KB
testcase_22 AC 407 ms
10,836 KB
testcase_23 AC 465 ms
17,688 KB
testcase_24 AC 465 ms
17,196 KB
testcase_25 AC 473 ms
18,008 KB
testcase_26 AC 466 ms
17,472 KB
testcase_27 WA -
testcase_28 AC 466 ms
17,208 KB
testcase_29 AC 466 ms
17,436 KB
testcase_30 AC 468 ms
17,148 KB
testcase_31 AC 463 ms
17,240 KB
testcase_32 AC 464 ms
17,436 KB
testcase_33 AC 557 ms
17,480 KB
testcase_34 AC 560 ms
18,504 KB
testcase_35 AC 556 ms
17,204 KB
testcase_36 AC 556 ms
17,448 KB
testcase_37 AC 555 ms
17,296 KB
testcase_38 AC 553 ms
17,448 KB
testcase_39 AC 549 ms
17,484 KB
testcase_40 AC 548 ms
17,476 KB
testcase_41 AC 550 ms
17,432 KB
testcase_42 AC 550 ms
17,716 KB
testcase_43 AC 551 ms
17,480 KB
testcase_44 AC 552 ms
17,216 KB
testcase_45 AC 552 ms
17,288 KB
testcase_46 AC 551 ms
17,292 KB
testcase_47 AC 556 ms
17,196 KB
testcase_48 AC 405 ms
10,692 KB
testcase_49 AC 404 ms
11,564 KB
testcase_50 AC 551 ms
17,424 KB
testcase_51 AC 552 ms
18,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

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 MOD = 3000000821;
    immutable long BASE = uniform(0, MOD);
    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