結果
問題 | No.469 区間加算と一致検索の問題 |
ユーザー |
![]() |
提出日時 | 2017-02-10 11:04:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,759 bytes |
コンパイル時間 | 1,207 ms |
コンパイル使用メモリ | 92,532 KB |
実行使用メモリ | 14,720 KB |
最終ジャッジ日時 | 2024-12-30 21:40:34 |
合計ジャッジ時間 | 16,370 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 WA * 1 |
ソースコード
#include <algorithm>#include <cmath>#include <iostream>#include <map>#include <queue>#include <set>#include <string>#include <vector>#define rep(i, n) for (int i = 0; i < (n); i++)#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)using namespace std;using lli = long long int;lli base1 = 123411237;lli base2 = 565852344;lli mod = 1e9 + 7;lli powm(lli p, lli n){lli ans = 1;while (n) {if (n & 1) {ans = (ans * p) % mod;}p = (p * p) % mod;n /= 2;}return ans;}int main(){lli n, q;cin >> n >> q;lli l, r, x;string s;lli h1 = 0, h2 = 0;map<lli, int> g1, g2;rep(i, q){cin >> s;if (s == "!") {cin >> l >> r >> x;h1 = (h1 + x * (powm(base1, r) - powm(base1, l) + mod) % mod * powm(base1 - 1, mod - 2) + mod * mod) % mod;h2 = (h2 + x * (powm(base2, r) - powm(base2, l) + mod) % mod * powm(base2 - 1, mod - 2) + mod * mod) % mod;if (g1[h1] == 0 || g2[h2] == 0) {g1[h1] = i + 1;g2[h2] = i + 1;} else if (g1[h1] != 0 && g2[h2] != 0 && g1[h1] != g2[h2]) {g1[h1] = i + 1;g2[h2] = i + 1;}} else {//[l..r)にhashif (h1 == 0 && h2 == 0) {cout << 0 << endl;} else if (g1[h1] == 0 || g2[h2] == 0) {cout << i + 1 << endl;} else if (g1[h1] && g2[h2] && g1[h1] == g2[h2]) {cout << g1[h1] << endl;} else {cout << min(g1[h1], g2[h2]) << endl;}}//cout << i << ' ' << h1 << ' ' << h2 << endl;}};