結果

問題 No.469 区間加算と一致検索の問題
ユーザー kimiyukikimiyuki
提出日時 2016-12-14 02:13:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,879 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 85,912 KB
最終ジャッジ日時 2024-11-14 19:55:10
合計ジャッジ時間 1,893 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:7:68: error: no matching function for call to 'begin(__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type&)'
    7 | #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
      |                                                               ~~~~~^~~~~~~
main.cpp:22:5: note: in expansion of macro 'whole'
   22 |     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:7:68: note:   'std::array<int, 3>' is not derived from 'std::initializer_list<_Tp>'
    7 | #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
      |                                                               ~~~~~^~~~~~~
main.cpp:22:5: note: in expansion of macro 'whole'
   22 |     whole(

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <random>
#include <cassert>
#define repeat(i,n) for (int i = 0; (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;

const int L = 3;
const int m[L] = { 1000000007, 1000000009, 1000000021 };
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);
    vector<array<int, L> > acc(n+1);
    repeat (i,n) acc[i+1] = add(acc[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(add(acc[r], mul(acc[l], -1)), k));
            if (not f.count(x)) f[x] = t+1;
        } else if (c == '?') {
            cout << f[x] << endl;
        } else {
            assert (false);
        }
    }
    return 0;
}
0