結果
問題 | No.469 区間加算と一致検索の問題 |
ユーザー |
![]() |
提出日時 | 2017-03-15 18:56:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 91 ms / 5,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 2,020 ms |
コンパイル使用メモリ | 176,664 KB |
実行使用メモリ | 17,140 KB |
最終ジャッジ日時 | 2024-12-21 17:08:13 |
合計ジャッジ時間 | 5,281 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#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]); } } }