結果

問題 No.469 区間加算と一致検索の問題
ユーザー startcppstartcpp
提出日時 2017-01-01 22:04:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 801 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 67,996 KB
実行使用メモリ 9,160 KB
最終ジャッジ日時 2023-08-22 09:30:26
合計ジャッジ時間 7,981 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 13 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 97 ms
6,164 KB
testcase_26 AC 98 ms
6,168 KB
testcase_27 AC 98 ms
6,232 KB
testcase_28 WA -
testcase_29 AC 96 ms
6,280 KB
testcase_30 AC 96 ms
6,292 KB
testcase_31 WA -
testcase_32 AC 97 ms
6,232 KB
testcase_33 WA -
testcase_34 AC 245 ms
9,088 KB
testcase_35 WA -
testcase_36 AC 247 ms
9,020 KB
testcase_37 WA -
testcase_38 AC 230 ms
7,596 KB
testcase_39 AC 231 ms
7,632 KB
testcase_40 AC 232 ms
7,700 KB
testcase_41 AC 232 ms
7,584 KB
testcase_42 AC 234 ms
7,552 KB
testcase_43 AC 234 ms
7,608 KB
testcase_44 AC 233 ms
7,764 KB
testcase_45 AC 233 ms
7,820 KB
testcase_46 AC 232 ms
7,568 KB
testcase_47 AC 233 ms
7,736 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 WA -
testcase_51 AC 233 ms
7,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//階差数列のローリングハッシュをmapで持てば間に合う。
#include <iostream>
#include <map>
#define int long long
using namespace std;

int base = 46792453;
int mod = 1000000009;
int n, q;
char c; int l, r, val;
map<int, int> dict;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

signed main() {
	int i;
	
	cin >> n >> q;
	
	int hashNum = 0;
	for (i = 0; i < q; i++) {
		if (dict.find(hashNum) == dict.end()) dict[hashNum] = i;
		
		cin >> c;
		if (c == '!') {
			cin >> l >> r >> val;
			hashNum += val * powmod(base, l, mod);
			hashNum += (mod - val) * powmod(base, r, mod);
			hashNum %= mod;
		}
		else {
			cout << dict[hashNum] << endl;
		}
	}
	return 0;
}
0