結果

問題 No.469 区間加算と一致検索の問題
ユーザー uenokuuenoku
提出日時 2017-02-10 11:02:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,761 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 89,052 KB
実行使用メモリ 14,884 KB
最終ジャッジ日時 2023-08-27 05:19:30
合計ジャッジ時間 17,278 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 1 ms
4,380 KB
testcase_50 WA -
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 = 123411234;
lli base2 = 565852344;
lli mod = 1e13 + 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