結果

問題 No.469 区間加算と一致検索の問題
ユーザー nebukuro09nebukuro09
提出日時 2016-12-19 02:15:40
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 1,555 ms / 5,000 ms
コード長 2,014 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 97,424 KB
実行使用メモリ 52,704 KB
最終ジャッジ日時 2023-09-02 23:47:18
合計ジャッジ時間 75,489 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,247 ms
28,464 KB
testcase_01 AC 1,247 ms
29,472 KB
testcase_02 AC 1,248 ms
27,640 KB
testcase_03 AC 1,255 ms
30,724 KB
testcase_04 AC 1,258 ms
30,096 KB
testcase_05 AC 1,258 ms
30,032 KB
testcase_06 AC 1,262 ms
30,720 KB
testcase_07 AC 1,262 ms
31,620 KB
testcase_08 AC 1,265 ms
32,552 KB
testcase_09 AC 1,255 ms
29,756 KB
testcase_10 AC 1,259 ms
29,560 KB
testcase_11 AC 1,250 ms
29,568 KB
testcase_12 AC 1,263 ms
31,032 KB
testcase_13 AC 1,257 ms
30,412 KB
testcase_14 AC 1,250 ms
28,480 KB
testcase_15 AC 1,250 ms
30,788 KB
testcase_16 AC 1,263 ms
32,124 KB
testcase_17 AC 1,258 ms
30,300 KB
testcase_18 AC 1,260 ms
31,340 KB
testcase_19 AC 1,248 ms
29,308 KB
testcase_20 AC 1,266 ms
31,500 KB
testcase_21 AC 1,253 ms
29,556 KB
testcase_22 AC 1,248 ms
28,408 KB
testcase_23 AC 1,360 ms
46,828 KB
testcase_24 AC 1,361 ms
46,452 KB
testcase_25 AC 1,364 ms
46,776 KB
testcase_26 AC 1,362 ms
48,028 KB
testcase_27 AC 1,361 ms
46,608 KB
testcase_28 AC 1,361 ms
46,720 KB
testcase_29 AC 1,362 ms
46,340 KB
testcase_30 AC 1,362 ms
46,960 KB
testcase_31 AC 1,362 ms
50,320 KB
testcase_32 AC 1,361 ms
48,728 KB
testcase_33 AC 1,555 ms
52,124 KB
testcase_34 AC 1,553 ms
50,968 KB
testcase_35 AC 1,549 ms
49,672 KB
testcase_36 AC 1,546 ms
51,484 KB
testcase_37 AC 1,553 ms
52,060 KB
testcase_38 AC 1,545 ms
51,256 KB
testcase_39 AC 1,542 ms
51,764 KB
testcase_40 AC 1,540 ms
52,704 KB
testcase_41 AC 1,534 ms
51,512 KB
testcase_42 AC 1,541 ms
50,356 KB
testcase_43 AC 1,541 ms
51,284 KB
testcase_44 AC 1,536 ms
52,112 KB
testcase_45 AC 1,538 ms
50,592 KB
testcase_46 AC 1,541 ms
49,268 KB
testcase_47 AC 1,546 ms
51,828 KB
testcase_48 AC 1,246 ms
29,192 KB
testcase_49 AC 1,248 ms
29,252 KB
testcase_50 AC 1,542 ms
52,556 KB
testcase_51 AC 1,541 ms
50,028 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[3] MOD = [1000000009, 2000000357, 3000000821];
    auto powsum = new long[][](3, 10^^6+1);
    pragma(inline, true) {
        powsum[0][0] = powsum[1][0] = powsum[2][0] = 1;
        foreach (j; 0..3)
            foreach (i; 0..10^^6)
                powsum[j][i+1] = (powsum[j][i] + powmod(BASE, i+1, MOD[j])) % MOD[j];
    }

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

    int[long][] hash_table = new int[long][](3);
    hash_table[0][0] = hash_table[1][0] = hash_table[2][0] = 0;
    long[3] prev = [0, 0, 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;
            foreach (j; 0..3) {
                long plus = ((abs(K) * powmod(BASE, L, MOD[j])) % MOD[j] *
                             powsum[j][R-L-1]) % MOD[j];
                if (K >= 0)
                    prev[j] = (prev[j] + plus) % MOD[j];
                else if (plus > prev[j])
                    prev[j] = (prev[j] - plus) % MOD[j] + MOD[j];
                else
                    prev[j] = (prev[j] - plus) % MOD[j];
                if (!(prev[j] in hash_table[j]))
                    hash_table[j][prev[j]] = i;
            }
        }
        else {
            foreach (j; 0..3) {
                if (hash_table[j][prev[j]] == hash_table[(j+1)%3][prev[(j+1)%3]]) {
                    hash_table[j][prev[j]].writeln;
                    break;
                }
            }
        }
    }
}
0