結果

問題 No.469 区間加算と一致検索の問題
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-03-15 18:56:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 1,222 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 172,652 KB
実行使用メモリ 17,176 KB
最終ジャッジ日時 2023-08-23 13:40:08
合計ジャッジ時間 6,089 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
11,532 KB
testcase_01 AC 11 ms
11,368 KB
testcase_02 AC 11 ms
11,504 KB
testcase_03 AC 13 ms
11,644 KB
testcase_04 AC 14 ms
11,680 KB
testcase_05 AC 15 ms
11,952 KB
testcase_06 AC 15 ms
11,844 KB
testcase_07 AC 15 ms
11,872 KB
testcase_08 AC 15 ms
11,848 KB
testcase_09 AC 12 ms
11,604 KB
testcase_10 AC 14 ms
11,448 KB
testcase_11 AC 12 ms
11,720 KB
testcase_12 AC 16 ms
11,944 KB
testcase_13 AC 14 ms
11,816 KB
testcase_14 AC 11 ms
11,676 KB
testcase_15 AC 13 ms
11,552 KB
testcase_16 AC 15 ms
11,840 KB
testcase_17 AC 15 ms
11,992 KB
testcase_18 AC 15 ms
11,800 KB
testcase_19 AC 12 ms
11,452 KB
testcase_20 AC 16 ms
12,024 KB
testcase_21 AC 12 ms
11,472 KB
testcase_22 AC 11 ms
11,380 KB
testcase_23 AC 44 ms
14,160 KB
testcase_24 AC 45 ms
14,212 KB
testcase_25 AC 44 ms
14,148 KB
testcase_26 AC 45 ms
14,140 KB
testcase_27 AC 45 ms
14,248 KB
testcase_28 AC 45 ms
14,312 KB
testcase_29 AC 44 ms
14,180 KB
testcase_30 AC 45 ms
14,184 KB
testcase_31 AC 45 ms
14,248 KB
testcase_32 AC 46 ms
14,300 KB
testcase_33 AC 97 ms
16,980 KB
testcase_34 AC 100 ms
17,028 KB
testcase_35 AC 97 ms
16,980 KB
testcase_36 AC 95 ms
16,980 KB
testcase_37 AC 96 ms
17,176 KB
testcase_38 AC 83 ms
15,652 KB
testcase_39 AC 82 ms
15,652 KB
testcase_40 AC 82 ms
15,588 KB
testcase_41 AC 83 ms
15,568 KB
testcase_42 AC 82 ms
15,548 KB
testcase_43 AC 83 ms
15,632 KB
testcase_44 AC 94 ms
15,572 KB
testcase_45 AC 94 ms
15,552 KB
testcase_46 AC 82 ms
15,556 KB
testcase_47 AC 82 ms
15,776 KB
testcase_48 AC 11 ms
11,376 KB
testcase_49 AC 11 ms
11,256 KB
testcase_50 AC 83 ms
15,740 KB
testcase_51 AC 84 ms
15,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
static const ll mo0 = 1000000007, mo1 = 1000000009;
static const ll add0 = 10009, add1 = 10007;
typedef pair<int, int> Hash;
//-----------------------------------------------------------------
Hash imos[1010101];
void pre() {
	imos[0] = { 0, 0 };
	rep(i, 1, 1010101) imos[i] = {(imos[i - 1].first * add0 + add0) % mo0, (imos[i - 1].second * add1 + add1) % mo1 };
}
Hash calc(Hash h, int L, int R, int K) {
	Hash one = imos[R];
	if (0 < L) one = { one.first - imos[L].first, one.second - imos[L].second };
	one.first = (one.first + mo0) % mo0;
	one.second = (one.second + mo1) % mo1;

	return{ (h.first + one.first * ((K + mo0) % mo0)) % mo0, (h.second + one.second * ((K + mo1) % mo1)) % mo1 };
}
//-----------------------------------------------------------------
int N, Q;
map<Hash, int> ans;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> Q;
	pre();

	Hash h = { 0, 0 };
	ans[h] = 0;

	rep(q, 1, Q + 1) {
		char t; cin >> t;
		if (t == '!') {
			int L, R, K; cin >> L >> R >> K;
			h = calc(h, L, R, K);
			if (ans.count(h) == 0) ans[h] = q;
		} else {
			printf("%d\n", ans[h]);
		}
	}
}
0