結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 390 ms
10,884 KB
testcase_01 AC 383 ms
10,664 KB
testcase_02 AC 389 ms
10,932 KB
testcase_03 AC 382 ms
11,604 KB
testcase_04 AC 384 ms
13,116 KB
testcase_05 AC 405 ms
12,996 KB
testcase_06 AC 387 ms
14,196 KB
testcase_07 AC 400 ms
13,820 KB
testcase_08 AC 395 ms
13,992 KB
testcase_09 AC 397 ms
12,996 KB
testcase_10 AC 400 ms
14,576 KB
testcase_11 AC 405 ms
12,344 KB
testcase_12 AC 402 ms
15,712 KB
testcase_13 AC 389 ms
13,844 KB
testcase_14 AC 399 ms
12,584 KB
testcase_15 AC 399 ms
12,088 KB
testcase_16 AC 406 ms
14,492 KB
testcase_17 AC 393 ms
13,528 KB
testcase_18 AC 383 ms
13,576 KB
testcase_19 AC 392 ms
12,472 KB
testcase_20 AC 402 ms
13,516 KB
testcase_21 AC 405 ms
11,324 KB
testcase_22 AC 377 ms
10,748 KB
testcase_23 AC 436 ms
18,012 KB
testcase_24 AC 443 ms
17,240 KB
testcase_25 AC 434 ms
17,676 KB
testcase_26 AC 439 ms
17,276 KB
testcase_27 AC 432 ms
17,736 KB
testcase_28 AC 447 ms
17,240 KB
testcase_29 AC 440 ms
17,296 KB
testcase_30 AC 441 ms
17,236 KB
testcase_31 AC 441 ms
17,196 KB
testcase_32 AC 463 ms
17,420 KB
testcase_33 AC 538 ms
17,440 KB
testcase_34 AC 544 ms
17,272 KB
testcase_35 AC 531 ms
18,280 KB
testcase_36 WA -
testcase_37 AC 523 ms
17,348 KB
testcase_38 AC 536 ms
17,296 KB
testcase_39 AC 532 ms
17,472 KB
testcase_40 AC 523 ms
17,240 KB
testcase_41 AC 526 ms
17,436 KB
testcase_42 AC 515 ms
17,260 KB
testcase_43 AC 519 ms
17,468 KB
testcase_44 AC 533 ms
17,332 KB
testcase_45 AC 536 ms
17,296 KB
testcase_46 AC 526 ms
17,284 KB
testcase_47 WA -
testcase_48 AC 391 ms
12,360 KB
testcase_49 AC 401 ms
11,252 KB
testcase_50 AC 528 ms
18,296 KB
testcase_51 AC 531 ms
17,432 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) {
    a %= 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 = 2000000357;
    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