結果

問題 No.469 区間加算と一致検索の問題
ユーザー nebukuro09nebukuro09
提出日時 2016-12-19 20:13:58
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,474 ms / 5,000 ms
コード長 2,038 bytes
コンパイル時間 2,869 ms
コンパイル使用メモリ 112,868 KB
実行使用メモリ 52,880 KB
最終ジャッジ日時 2023-09-02 23:54:49
合計ジャッジ時間 71,746 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,160 ms
28,816 KB
testcase_01 AC 1,166 ms
28,420 KB
testcase_02 AC 1,171 ms
28,252 KB
testcase_03 AC 1,202 ms
30,720 KB
testcase_04 AC 1,177 ms
30,748 KB
testcase_05 AC 1,184 ms
29,532 KB
testcase_06 AC 1,166 ms
33,056 KB
testcase_07 AC 1,168 ms
32,240 KB
testcase_08 AC 1,174 ms
31,892 KB
testcase_09 AC 1,132 ms
29,792 KB
testcase_10 AC 1,154 ms
30,796 KB
testcase_11 AC 1,151 ms
29,772 KB
testcase_12 AC 1,168 ms
31,804 KB
testcase_13 AC 1,199 ms
29,788 KB
testcase_14 AC 1,170 ms
29,936 KB
testcase_15 AC 1,165 ms
29,264 KB
testcase_16 AC 1,176 ms
31,836 KB
testcase_17 AC 1,151 ms
30,488 KB
testcase_18 AC 1,170 ms
30,516 KB
testcase_19 AC 1,182 ms
29,996 KB
testcase_20 AC 1,210 ms
31,812 KB
testcase_21 AC 1,190 ms
31,044 KB
testcase_22 AC 1,193 ms
28,772 KB
testcase_23 AC 1,280 ms
47,140 KB
testcase_24 AC 1,257 ms
45,428 KB
testcase_25 AC 1,296 ms
45,164 KB
testcase_26 AC 1,249 ms
46,892 KB
testcase_27 AC 1,251 ms
46,184 KB
testcase_28 AC 1,249 ms
43,596 KB
testcase_29 AC 1,242 ms
45,976 KB
testcase_30 AC 1,261 ms
45,816 KB
testcase_31 AC 1,271 ms
44,908 KB
testcase_32 AC 1,253 ms
45,212 KB
testcase_33 AC 1,420 ms
49,236 KB
testcase_34 AC 1,435 ms
50,272 KB
testcase_35 AC 1,439 ms
51,092 KB
testcase_36 AC 1,474 ms
50,108 KB
testcase_37 AC 1,432 ms
52,880 KB
testcase_38 AC 1,417 ms
51,604 KB
testcase_39 AC 1,403 ms
50,352 KB
testcase_40 AC 1,434 ms
52,608 KB
testcase_41 AC 1,463 ms
51,520 KB
testcase_42 AC 1,452 ms
49,800 KB
testcase_43 AC 1,423 ms
50,824 KB
testcase_44 AC 1,408 ms
50,512 KB
testcase_45 AC 1,472 ms
49,228 KB
testcase_46 AC 1,443 ms
50,556 KB
testcase_47 AC 1,426 ms
52,348 KB
testcase_48 AC 1,138 ms
28,248 KB
testcase_49 AC 1,163 ms
28,748 KB
testcase_50 AC 1,434 ms
52,552 KB
testcase_51 AC 1,461 ms
52,080 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[3] MOD = [1000000009, 2000000357, 3000000821];
    immutable long BASE = uniform(0, MOD.reduce!(min));
    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