ecnerwala / cp-book

Book Code for Competitive Programming
Creative Commons Zero v1.0 Universal
550 stars 64 forks source link

Update char_poly.hpp #10

Closed ghost closed 8 months ago

ghost commented 8 months ago

Hi, Andrew :D

Your code for char_poly.hpp can be optimized, as you can avoid unnecessary copies. All you need to do is to modify the input of A to be done via rvalue reference, which allows you to then use std::move. I have modified the code to do just that.

ghost commented 8 months ago

All tests have passed btw.

╭─ ~/Documents/cp-book                                                                                           ✔   38s ─
╰─ ctest --test-dir build                                                                                                            ─╯
Internal ctest changing into directory: /home/cat/Documents/cp-book/build
Test project /home/cat/Documents/cp-book/build
      Start  1: Berlekamp Massey
 1/16 Test  #1: Berlekamp Massey ...................................................   Passed    0.01 sec
      Start  2: Cartesian Tree
 2/16 Test  #2: Cartesian Tree .....................................................   Passed    0.01 sec
      Start  3: Dirichlet series multiplication and inverse - modnum<int(1e9)+7>
 3/16 Test  #3: Dirichlet series multiplication and inverse - modnum<int(1e9)+7> ...   Passed    0.01 sec
      Start  4: Dirichlet series multiplication and inverse - int64_t
 4/16 Test  #4: Dirichlet series multiplication and inverse - int64_t ..............   Passed    0.01 sec
      Start  5: Dirichlet series BIT sparse multiplication - modnum<int(1e9)+7>
 5/16 Test  #5: Dirichlet series BIT sparse multiplication - modnum<int(1e9)+7> ....   Passed    0.08 sec
      Start  6: Dirichlet series euler transform - modnum<int(1e9)+7>
 6/16 Test  #6: Dirichlet series euler transform - modnum<int(1e9)+7> ..............   Passed    0.01 sec
      Start  7: FFT Multiply Mod
 7/16 Test  #7: FFT Multiply Mod ...................................................   Passed    0.01 sec
      Start  8: FFT Inverse
 8/16 Test  #8: FFT Inverse ........................................................   Passed    0.01 sec
      Start  9: Lattice Count
 9/16 Test  #9: Lattice Count ......................................................   Passed    0.05 sec
      Start 10: Mod Count (positive)
10/16 Test #10: Mod Count (positive) ...............................................   Passed    0.11 sec
      Start 11: Mod Count (negatives)
11/16 Test #11: Mod Count (negatives) ..............................................   Passed    0.10 sec
      Start 12: Permutation Tree
12/16 Test #12: Permutation Tree ...................................................   Passed    0.17 sec
      Start 13: RangeMinQuery
13/16 Test #13: RangeMinQuery ......................................................   Passed    0.03 sec
      Start 14: Segment Tree Layouts - seg_tree::in_order_layout
14/16 Test #14: Segment Tree Layouts - seg_tree::in_order_layout ...................   Passed    0.04 sec
      Start 15: Segment Tree Layouts - seg_tree::circular_layout
15/16 Test #15: Segment Tree Layouts - seg_tree::circular_layout ...................   Passed    0.04 sec
      Start 16: Tensor
16/16 Test #16: Tensor .............................................................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 16

Total Test time (real) =   0.72 sec
ecnerwala commented 8 months ago

For future reference: closed because you can already pass rvalue-references into call-by-value functions and it'll move-construct it for you.