結果

問題 No.469 区間加算と一致検索の問題
ユーザー kimiyukikimiyuki
提出日時 2016-12-14 01:46:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,184 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 85,244 KB
最終ジャッジ日時 2023-08-21 00:54:10
合計ジャッジ時間 2,483 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: ラムダ関数内:
main.cpp:10:68: エラー: ‘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: 備考: in expansion of macro ‘whole’
   62 |     whole(fill, e[0], 1);
      |     ^~~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/range_access.h:36,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/string:52,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/locale_classes.h:40,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/ios_base.h:41,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ios:42,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ostream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/iostream:39,
         次から読み込み:  main.cpp:1:
/usr/local/gcc7/include/c++/12.2.0/initializer_list:90:5: 備考: 候補: ‘template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)’
   90 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
/usr/local/gcc7/include/c++/12.2.0/initializer_list:90:5: 備考:   template argument deduction/substitution failed:
main.cpp:10:68: 備考:   ‘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: 備考: in expansion of macro ‘whole’
   62 |     whole(fill, e[0], 1);
      |     ^~~~~
/usr/local/gcc7/include/c++/12.2.0/bits/range_access.h:52:5: �

ソースコード

diff #

#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;
}
0