結果
問題 | No.1000 Point Add and Array Add |
ユーザー | rsk0315 |
提出日時 | 2020-02-28 22:59:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,429 bytes |
コンパイル時間 | 272 ms |
コンパイル使用メモリ | 44,604 KB |
最終ジャッジ日時 | 2024-10-13 18:52:56 |
合計ジャッジ時間 | 1,471 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:11:21: error: 'size_t' does not name a type 11 | using size_type = size_t; | ^~~~~~ main.cpp:4:1: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'? 3 | #include <utility> +++ |+#include <cstddef> 4 | main.cpp:20:3: error: 'size_type' does not name a type 20 | size_type M_base_size; | ^~~~~~~~~ main.cpp:30:30: error: expected ')' before 'n' 30 | dual_segment_tree(size_type n): | ~ ^~ | ) main.cpp:37:30: error: expected ')' before 'n' 37 | dual_segment_tree(size_type n, first_type const& x): | ~ ^~ | ) main.cpp:60:15: error: 'size_type' has not been declared 60 | void modify(size_type l, size_type r, second_type const& x) { | ^~~~~~~~~ main.cpp:60:28: error: 'size_type' has not been declared 60 | void modify(size_type l, size_type r, second_type const& x) { | ^~~~~~~~~ main.cpp:71:18: error: 'size_type' has not been declared 71 | value_type get(size_type i) const { | ^~~~~~~~~ main.cpp: In constructor 'dual_segment_tree<Monoid, Container>::dual_segment_tree(InputIt, InputIt)': main.cpp:48:5: error: class 'dual_segment_tree<Monoid, Container>' does not have any field named 'M_base_size' 48 | M_base_size(std::distance(first, last)), | ^~~~~~~~~~~ main.cpp:51:9: error: 'M_base_size' was not declared in this scope 51 | M_c(M_base_size*2) | ^~~~~~~~~~~ main.cpp:53:10: error: 'size_type' was not declared in this scope 53 | for (size_type i = M_base_size; first != last; ++i) | ^~~~~~~~~ main.cpp:53:54: error: 'i' was not declared in this scope 53 | for (size_type i = M_base_size; first != last; ++i) | ^ main.cpp: In m
ソースコード
#include <climits> #include <vector> #include <utility> template < typename Monoid, typename Container = std::vector<typename Monoid::first_type> > class dual_segment_tree { public: using size_type = size_t; using first_type = typename Monoid::first_type; using second_type = typename Monoid::second_type; using value_type = first_type; using binary_operation = typename Monoid::binary_operation; using external_binary_operation = typename Monoid::external_binary_operation; using container = Container; private: size_type M_base_size; binary_operation M_op1; external_binary_operation M_op2; container M_c; public: dual_segment_tree() = default; dual_segment_tree(dual_segment_tree const&) = default; dual_segment_tree(dual_segment_tree&&) = default; dual_segment_tree(size_type n): M_base_size(n), M_op1(binary_operation()), M_op2(external_binary_operation()), M_c(n+n, M_op1.identity) {} dual_segment_tree(size_type n, first_type const& x): M_base_size(n), M_op1(binary_operation()), M_op2(external_binary_operation()), M_c(n+n, M_op1.identity) { modify(0, n, x); } template <typename InputIt> dual_segment_tree(InputIt first, InputIt last): M_base_size(std::distance(first, last)), M_op1(binary_operation()), M_op2(external_binary_operation()), M_c(M_base_size*2) { for (size_type i = M_base_size; first != last; ++i) M_c[i] = *first++; } dual_segment_tree& operator =(dual_segment_tree const&) = default; dual_segment_tree& operator =(dual_segment_tree&&) = default; void modify(size_type l, size_type r, second_type const& x) { l += M_base_size; r += M_base_size; while (l < r) { if (l & 1) M_c[l] = M_op2(std::move(M_c[l]), x), ++l; if (r & 1) --r, M_c[r] = M_op2(std::move(M_c[r]), x); l >>= 1; r >>= 1; } } value_type get(size_type i) const { i += M_base_size; value_type res = M_c[i]; while (i > 1) { i >>= 1; res = M_op1(std::move(res), M_c[i]); } return res; } }; template <typename Tp> struct single_get_range_add { using first_type = Tp; using second_type = Tp; struct binary_operation { first_type identity{}; first_type operator ()(first_type const& x, first_type const& y) const { return x + y; } }; struct external_binary_operation { first_type operator ()(first_type const& x, second_type const& y) const { return x + y; } }; }; #include <cstdio> #include <cstdint> #include <algorithm> #include <utility> #include <vector> int main() { size_t n, q; scanf("%zu %zu", &n, &q); std::vector<intmax_t> a(n); for (auto& ai: a) scanf("%jd", &ai); dual_segment_tree<single_get_range_add<intmax_t>> sg(n); std::vector<intmax_t> b(n); for (size_t i = 0; i < q; ++i) { char c; scanf(" %c", &c); switch (c) { case 'A': { size_t x; intmax_t y; scanf("%zu %jd", &x, &y); --x; b[x] += sg.get(x) * a[x]; sg.modify(x, x+1, -sg.get(x)); a[x] += y; break; } case 'B': { size_t x, y; scanf("%zu %zu", &x, &y); --x, --y; sg.modify(x, y+1, 1); break; } } } for (size_t i = 0; i < n; ++i) { b[i] += sg.get(i) * a[i]; } for (size_t i = 0; i < n; ++i) printf("%jd%c", b[i], i+1<n? ' ': '\n'); }