結果

問題 No.469 区間加算と一致検索の問題
ユーザー uenokuuenoku
提出日時 2017-02-10 11:04:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,759 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 89,664 KB
実行使用メモリ 14,636 KB
最終ジャッジ日時 2023-08-29 05:44:14
合計ジャッジ時間 16,368 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 15 ms
4,380 KB
testcase_04 AC 19 ms
4,376 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 24 ms
4,388 KB
testcase_07 AC 27 ms
4,380 KB
testcase_08 AC 29 ms
4,420 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 31 ms
4,420 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 26 ms
4,380 KB
testcase_17 AC 24 ms
4,384 KB
testcase_18 AC 26 ms
4,380 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 29 ms
4,396 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 209 ms
8,968 KB
testcase_24 AC 212 ms
9,012 KB
testcase_25 AC 210 ms
9,008 KB
testcase_26 AC 210 ms
8,964 KB
testcase_27 AC 213 ms
8,972 KB
testcase_28 AC 209 ms
8,972 KB
testcase_29 AC 216 ms
8,960 KB
testcase_30 AC 209 ms
8,964 KB
testcase_31 AC 209 ms
9,044 KB
testcase_32 AC 209 ms
9,024 KB
testcase_33 AC 513 ms
14,636 KB
testcase_34 AC 510 ms
14,632 KB
testcase_35 AC 524 ms
14,596 KB
testcase_36 AC 514 ms
14,608 KB
testcase_37 AC 510 ms
14,612 KB
testcase_38 AC 489 ms
11,720 KB
testcase_39 AC 482 ms
11,844 KB
testcase_40 AC 487 ms
11,760 KB
testcase_41 AC 485 ms
12,092 KB
testcase_42 AC 487 ms
11,812 KB
testcase_43 AC 483 ms
11,804 KB
testcase_44 AC 486 ms
11,764 KB
testcase_45 AC 489 ms
11,828 KB
testcase_46 AC 490 ms
11,744 KB
testcase_47 AC 486 ms
11,796 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 485 ms
11,776 KB
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli base1 = 123411237;
lli base2 = 565852344;
lli mod = 1e9 + 7;
lli powm(lli p, lli n)
{
    lli ans = 1;
    while (n) {
        if (n & 1) {
            ans = (ans * p) % mod;
        }
        p = (p * p) % mod;
        n /= 2;
    }
    return ans;
}
int main()
{
    lli n, q;
    cin >> n >> q;
    lli l, r, x;
    string s;
    lli h1 = 0, h2 = 0;
    map<lli, int> g1, g2;
    rep(i, q)
    {
        cin >> s;
        if (s == "!") {
            cin >> l >> r >> x;
            h1 = (h1 + x * (powm(base1, r) - powm(base1, l) + mod) % mod * powm(base1 - 1, mod - 2) + mod * mod) % mod;
            h2 = (h2 + x * (powm(base2, r) - powm(base2, l) + mod) % mod * powm(base2 - 1, mod - 2) + mod * mod) % mod;
            if (g1[h1] == 0 || g2[h2] == 0) {
                g1[h1] = i + 1;
                g2[h2] = i + 1;
            } else if (
                g1[h1] != 0 && g2[h2] != 0 && g1[h1] != g2[h2]) {
                g1[h1] = i + 1;
                g2[h2] = i + 1;
            }
        } else {
            //[l..r)にhash
            if (h1 == 0 && h2 == 0) {
                cout << 0 << endl;
            } else if (g1[h1] == 0 || g2[h2] == 0) {
                cout << i + 1 << endl;
            } else if (g1[h1] && g2[h2] && g1[h1] == g2[h2]) {
                cout << g1[h1] << endl;
            } else {
                cout << min(g1[h1], g2[h2]) << endl;
            }
        }
        //cout << i << ' ' << h1 << ' ' << h2 << endl;
    }
};
0