結果
問題 | No.469 区間加算と一致検索の問題 |
ユーザー |
![]() |
提出日時 | 2017-02-19 17:54:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,066 ms / 5,000 ms |
コード長 | 1,074 bytes |
コンパイル時間 | 1,199 ms |
コンパイル使用メモリ | 106,772 KB |
実行使用メモリ | 23,844 KB |
最終ジャッジ日時 | 2024-12-21 17:08:57 |
合計ジャッジ時間 | 19,712 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <random>#include <unordered_map>using namespace std;const int64_t p = 2000000000000000303;vector<int64_t> ts, tsum;std::random_device rnd;std::mt19937 mt(rnd());std::normal_distribution<> norm(2, p);int N, Q;unordered_map<int64_t, int> answer;void init_hash() {ts.resize(N + 1); tsum.resize(N + 1);ts[0] = 1; tsum[0] = 0;for(int i = 0; i < N; i++) {ts[i] = norm(mt);while(__gcd(ts[i], p) != 1) {ts[i] = norm(mt);}tsum[i + 1] = (tsum[i] + ts[i]) % p;}}int main() {cin >> N >> Q;init_hash();int64_t cur_hash = 0;answer[cur_hash] = 0;for(int i = 0; i < Q; i++) {string c1;cin >> c1;if(c1 == "!"){int L, R, K;cin >> L >> R >> K;__int128_t tmp = tsum[R] - tsum[L];tmp = tmp * K % p;if(tmp < 0) tmp += p;cur_hash = (cur_hash + tmp) % p;if(answer.count(cur_hash) == 0) {answer[cur_hash] = i + 1;}} else {cout << answer[cur_hash] << endl;}}}