結果
| 問題 | No.469 区間加算と一致検索の問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-19 01:57:57 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 105 ms / 5,000 ms |
| コード長 | 1,060 bytes |
| 記録 | |
| コンパイル時間 | 1,246 ms |
| コンパイル使用メモリ | 116,712 KB |
| 実行使用メモリ | 40,704 KB |
| 最終ジャッジ日時 | 2026-05-19 01:58:04 |
| 合計ジャッジ時間 | 6,730 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#include <iostream>
#include <cstdio>
#include <chrono>
#include <map>
#include <random>
using namespace std;
typedef unsigned long long ULL;
const int N = 1000010;
const ULL P = 1000000007ULL;
ULL r1[N], r2[N], pre1[N], pre2[N];
ULL h1, h2;
int n, q;
map<ULL, int> mp;
int main() {
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
scanf("%d%d", &n, &q);
for (int i = 0; i < n; ++i) {
r1[i] = rng();
r2[i] = rng();
}
for (int i = 0; i < n; ++i) {
pre1[i + 1] = pre1[i] + r1[i];
pre2[i + 1] = pre2[i] + r2[i];
}
mp[0] = 0;
for (int i = 1; i <= q; ++i) {
char type;
scanf(" %c", &type);
if (type == '!') {
int l, r, k;
scanf("%d%d%d", &l, &r, &k);
h1 += (ULL) k * (pre1[r] - pre1[l]);
h2 += (ULL) k * (pre2[r] - pre2[l]);
ULL key = h1 * P + h2;
if (!mp.count(key)) mp[key] = i;
} else {
printf("%d\n", mp[h1 * P + h2]);
}
}
return 0;
}