結果

問題 No.469 区間加算と一致検索の問題
ユーザー はまやんはまやんはまやんはまやん
提出日時 2017-03-15 17:49:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
OLE  
実行時間 -
コード長 1,187 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 176,872 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2024-07-04 00:00:39
合計ジャッジ時間 14,775 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample OLE * 1 -- * 2
other -- * 49
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:64,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
In member function 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = int]',
    inlined from 'void pre()' at main.cpp:15:111:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_pair.h:584:15: warning: iteration 1010099 invokes undefined behavior [-Waggressive-loop-optimizations]
  584 |         first = std::forward<first_type>(__p.first);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function 'void pre()':
main.cpp:3:33: note: within this loop
    3 | #define rep(i,a,b) for(int i=a;i<b;i++)
      |                                 ^
main.cpp:15:9: note: in expansion of macro 'rep'
   15 |         rep(i, 1, 1010101) imos[i + 1] = { (imos[i].first * add0 + add0) % mo0, (imos[i].second * add1 + add1) % mo1 };
      

ソースコード

diff #

#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;
int N, Q;
//-----------------------------------------------------------------
Hash imos[1010101];
void pre() {
	imos[0] = { 0, 0 };
	rep(i, 1, 1010101) imos[i + 1] = { (imos[i].first * add0 + add0) % mo0, (imos[i].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, (h.second + one.second * K) % mo1 };
}
//-----------------------------------------------------------------
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]);
		}
	}
}
0