結果
問題 | No.469 区間加算と一致検索の問題 |
ユーザー | kimiyuki |
提出日時 | 2016-12-14 01:46:00 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,184 bytes |
コンパイル時間 | 719 ms |
コンパイル使用メモリ | 88,932 KB |
最終ジャッジ日時 | 2024-11-14 19:55:01 |
合計ジャッジ時間 | 3,074 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In lambda function: main.cpp:10:68: error: no matching function for call to 'begin(__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 16> >, std::array<int, 16> >::value_type&)' 10 | #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) | ~~~~~^~~~~~~ main.cpp:62:5: note: in expansion of macro 'whole' 62 | whole(fill, e[0], 1); | ^~~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/range_access.h:36, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:52, 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/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/initializer_list:90:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 90 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/initializer_list:90:5: note: template argument deduction/substitution failed: main.cpp:10:68: note: 'std::array<int, 16>' is not derived from 'std::initializer_list<_Tp>' 10 | #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) | ~~~~~^~~~~~~ main.cpp:62:5: note: in expansion of macro 'whole' 62 | w
ソースコード
#include <iostream> #include <vector> #include <map> #include <functional> #include <random> #include <cmath> #include <cassert> #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) typedef long long ll; using namespace std; template <typename T> struct segment_tree { // on monoid int n; vector<T> a; function<T (T,T)> append; // associative T unit; // unit segment_tree() = default; template <typename F> segment_tree(int a_n, T a_unit, F a_append) { n = pow(2,ceil(log2(a_n))); a.resize(2*n-1, a_unit); unit = a_unit; append = a_append; } void point_update(int i, T z) { a[i+n-1] = z; for (i = (i+n)/2; i > 0; i /= 2) { a[i-1] = append(a[2*i-1], a[2*i]); } } T range_concat(int l, int r) { return range_concat(0, 0, n, l, r); } T range_concat(int i, int il, int ir, int l, int r) { if (l <= il and ir <= r) { return a[i]; } else if (ir <= l or r <= il) { return unit; } else { return append( range_concat(2*i+1, il, (il+ir)/2, l, r), range_concat(2*i+2, (il+ir)/2, ir, l, r)); } } }; // rolling/zobrist hash const int L = 16; const int m[L] = { 1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093, 1000000097, 1000000103, 1000000123, 1000000181, 1000000207, 1000000223, 1000000241, 1000000271, 1000000289, 1000000297 }; vector<array<int, L> > generate_e(int n) { vector<array<int, L> > e(n); int b[L]; random_device device; default_random_engine engine(device()); repeat (i,L) { uniform_int_distribution<int> dist(0, m[i]-1); b[i] = dist(engine); } whole(fill, e[0], 1); repeat (i,n-1) repeat (j,L) e[i+1][j] = e[i][j] *(ll) b[j] % m[j]; return e; } array<int, L> add(array<int, L> const & a, array<int, L> const & b) { array<int, L> c; repeat (i,L) c[i] = (a[i] +(ll) b[i]) % m[i]; return c; }; array<int, L> mul(array<int, L> const & a, int b) { array<int, L> c; repeat (i,L) c[i] = ((a[i] *(ll) b) % m[i] + m[i]) % m[i]; return c; }; int main() { int n, q; cin >> n >> q; assert (1 <= n and n <= 1000000); assert (1 <= q and q <= 100000); vector<array<int, L> > e = generate_e(n); segment_tree<array<int, L> > segtree(n, {}, add); repeat (i,n) segtree.point_update(i, e[i]); array<int, L> x = {}; map<array<int, L>, int> f; f[x] = 0; repeat (t,q) { char c; cin >> c; if (c == '!') { int l, r, k; cin >> l >> r >> k; assert (0 <= l and l < n); assert (l < r and r <= n); assert (- 100 <= k and k <= + 100); x = add(x, mul(segtree.range_concat(l, r), k)); if (not f.count(x)) f[x] = t+1; } else if (c == '?') { cout << f[x] << endl; } else { assert (false); } } return 0; }