結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 12 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 99 ms
6,092 KB
testcase_24 AC 100 ms
6,160 KB
testcase_25 AC 99 ms
6,160 KB
testcase_26 AC 98 ms
6,128 KB
testcase_27 AC 99 ms
6,312 KB
testcase_28 AC 99 ms
6,240 KB
testcase_29 AC 98 ms
6,176 KB
testcase_30 AC 98 ms
6,188 KB
testcase_31 AC 97 ms
6,108 KB
testcase_32 AC 98 ms
6,240 KB
testcase_33 WA -
testcase_34 AC 252 ms
9,096 KB
testcase_35 WA -
testcase_36 AC 250 ms
9,076 KB
testcase_37 WA -
testcase_38 AC 233 ms
7,560 KB
testcase_39 AC 234 ms
7,632 KB
testcase_40 AC 234 ms
7,564 KB
testcase_41 AC 235 ms
7,572 KB
testcase_42 AC 236 ms
7,616 KB
testcase_43 WA -
testcase_44 AC 237 ms
7,556 KB
testcase_45 AC 237 ms
7,640 KB
testcase_46 AC 234 ms
7,700 KB
testcase_47 AC 231 ms
7,532 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int base = 467924537;
int mod = 1000000007;
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 + 10, mod);
			hashNum += (mod - val) * powmod(base, r + 10, mod);
			hashNum %= mod;
		}
		else {
			cout << dict[hashNum] << endl;
		}
	}
	return 0;
}
0