結果

問題 No.469 区間加算と一致検索の問題
ユーザー nebukuro09nebukuro09
提出日時 2016-12-19 01:43:35
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,469 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 95,248 KB
実行使用メモリ 17,392 KB
最終ジャッジ日時 2023-09-02 23:39:09
合計ジャッジ時間 28,086 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 386 ms
10,548 KB
testcase_01 AC 388 ms
10,608 KB
testcase_02 AC 384 ms
10,592 KB
testcase_03 AC 393 ms
11,528 KB
testcase_04 AC 395 ms
11,788 KB
testcase_05 AC 390 ms
12,056 KB
testcase_06 AC 387 ms
12,628 KB
testcase_07 AC 382 ms
12,828 KB
testcase_08 AC 399 ms
12,916 KB
testcase_09 AC 397 ms
11,304 KB
testcase_10 AC 398 ms
12,364 KB
testcase_11 AC 395 ms
11,252 KB
testcase_12 AC 393 ms
13,112 KB
testcase_13 AC 394 ms
11,768 KB
testcase_14 AC 397 ms
10,732 KB
testcase_15 AC 383 ms
11,268 KB
testcase_16 AC 394 ms
12,832 KB
testcase_17 AC 401 ms
12,040 KB
testcase_18 AC 390 ms
12,560 KB
testcase_19 AC 386 ms
10,736 KB
testcase_20 AC 380 ms
12,784 KB
testcase_21 AC 393 ms
10,972 KB
testcase_22 AC 396 ms
10,652 KB
testcase_23 WA -
testcase_24 AC 444 ms
17,288 KB
testcase_25 AC 443 ms
17,372 KB
testcase_26 AC 444 ms
17,272 KB
testcase_27 AC 431 ms
17,368 KB
testcase_28 AC 448 ms
17,312 KB
testcase_29 AC 437 ms
17,340 KB
testcase_30 AC 436 ms
17,276 KB
testcase_31 AC 436 ms
17,324 KB
testcase_32 AC 431 ms
17,276 KB
testcase_33 WA -
testcase_34 AC 522 ms
17,324 KB
testcase_35 AC 523 ms
17,300 KB
testcase_36 AC 524 ms
17,284 KB
testcase_37 AC 527 ms
17,328 KB
testcase_38 AC 531 ms
17,324 KB
testcase_39 AC 531 ms
17,320 KB
testcase_40 AC 525 ms
17,360 KB
testcase_41 AC 519 ms
17,356 KB
testcase_42 AC 519 ms
17,280 KB
testcase_43 AC 528 ms
17,276 KB
testcase_44 AC 535 ms
17,264 KB
testcase_45 AC 526 ms
17,324 KB
testcase_46 AC 530 ms
17,268 KB
testcase_47 AC 519 ms
17,392 KB
testcase_48 AC 380 ms
10,680 KB
testcase_49 AC 377 ms
10,592 KB
testcase_50 AC 516 ms
17,256 KB
testcase_51 AC 520 ms
17,196 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 10^^9 + 7;
    immutable long MOD = 1234567891;
    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