Repository: beet-aizu/library Branch: master Commit: 4f26a088ff99 Files: 696 Total size: 813.6 KB Directory structure: gitextract_cqk4qi75/ ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.md │ │ └── feature_request.md │ └── workflows/ │ ├── sanitize.yml │ └── verify.yml ├── .gitignore ├── .gitignore_gen.sh ├── .verify-helper/ │ ├── config.toml │ ├── docs/ │ │ └── _config.yml │ ├── local.toml │ ├── sanitize.toml │ ├── timestamps.local.json.20201106 │ ├── timestamps.local.json.20210324 │ └── timestamps.remote.json ├── README.md ├── algorithm/ │ ├── knuthyao.cpp │ ├── largestrectangle.cpp │ ├── mo.cpp │ ├── monotoneminima.cpp │ ├── offlineonline.cpp │ ├── optimalbinarytree.cpp │ ├── parallelbinarysearch.cpp │ └── partialsum.cpp ├── bbst/ │ ├── pb_ds_tree.cpp │ └── rbst/ │ ├── data/ │ │ ├── array.cpp │ │ ├── dual.cpp │ │ ├── lazy.cpp │ │ └── ushi.cpp │ ├── impl/ │ │ ├── basic.cpp │ │ └── persistent.cpp │ └── rbst.cpp ├── bflow/ │ └── capacityscaling.cpp ├── clean.sh ├── combinatorics/ │ ├── bell.cpp │ ├── bernoulli.cpp │ ├── enumeration.cpp │ ├── partition.cpp │ ├── partitiontable.cpp │ ├── stirling1st.cpp │ ├── stirling2nd.cpp │ └── surjection.cpp ├── convexhulltrick/ │ ├── convexhulltrick.cpp │ ├── linecontainer.cpp │ ├── segmentcontainer.cpp │ └── withindex.cpp ├── convolution/ │ ├── arbitrarymod.cpp │ ├── bitwise/ │ │ ├── and.cpp │ │ ├── fwht.cpp │ │ ├── or.cpp │ │ └── xor.cpp │ ├── convolution2D.cpp │ ├── divisor.cpp │ ├── fastfouriertransform.cpp │ ├── garner.cpp │ ├── naive.cpp │ └── numbertheoretictransform.cpp ├── datastructure/ │ ├── BIT2D.cpp │ ├── absolutesum.cpp │ ├── binaryindexedtree.cpp │ ├── binarytrie.cpp │ ├── bitvector.cpp │ ├── cartesiantree.cpp │ ├── cumulativesum.cpp │ ├── disjointsparsetable.cpp │ ├── kdtree.cpp │ ├── pb_ds_cc_hash_table.cpp │ ├── prioritysum.cpp │ ├── quickfind.cpp │ ├── radixheap.cpp │ ├── rangeslide.cpp │ ├── rotcev.cpp │ ├── skewheap.cpp │ ├── slidingwindowaggregation.cpp │ ├── slope.cpp │ ├── sparsetable.cpp │ ├── unionfind.cpp │ ├── waveletmatrix.cpp │ └── weightedunionfind.cpp ├── docs/ │ ├── bflow/ │ │ └── capacityscaling.md │ ├── datastructure/ │ │ ├── binaryindexedtree.md │ │ └── waveletmatrix.md │ ├── graph/ │ │ └── rangetorange.md │ ├── maxflow/ │ │ ├── dinic.md │ │ ├── fordfulkerson.md │ │ ├── leastflow.md │ │ └── twocommodity.md │ ├── mincostflow/ │ │ ├── negativeedge.md │ │ └── primaldual.md │ ├── segtree/ │ │ └── basic/ │ │ └── lazy.md │ ├── string/ │ │ ├── longestcommonprefix.md │ │ └── suffixarray.md │ ├── test/ │ │ ├── aoj/ │ │ │ ├── 0438.test.md │ │ │ ├── 0563.test.md │ │ │ ├── 1549.test.md │ │ │ ├── 1595.toptree.test.md │ │ │ ├── 2290.test.md │ │ │ ├── 2313.test.md │ │ │ ├── 2636.test.md │ │ │ ├── 2667.test.md │ │ │ ├── 2679.test.md │ │ │ ├── 2711.test.md │ │ │ ├── 2725.linecontainer.test.md │ │ │ ├── 2890.test.md │ │ │ ├── 3069.test.md │ │ │ ├── 3112.test.md │ │ │ ├── 3117.test.md │ │ │ ├── 3143.test.md │ │ │ ├── DSL_2_F.test.md │ │ │ ├── DSL_2_H.test.md │ │ │ └── DSL_2_I.test.md │ │ ├── yosupo/ │ │ │ └── range_kth_smallest.test.md │ │ └── yukicoder/ │ │ ├── 1732.test.md │ │ ├── 1937.test.md │ │ ├── 3267.test.md │ │ ├── 3453.test.md │ │ └── 7107.test.md │ ├── toptree/ │ │ └── toptree.md │ └── tree/ │ ├── ahu.md │ ├── auxiliarytree.md │ ├── heavylightdecomposition.md │ ├── rerooting.md │ └── sack.md ├── formalpowerseries/ │ ├── 998244353.cpp │ ├── base.cpp │ ├── diff.cpp │ ├── div.cpp │ ├── exp.cpp │ ├── integral.cpp │ ├── inv.cpp │ ├── log.cpp │ ├── mod.cpp │ ├── pow.cpp │ ├── shift.cpp │ └── sqrt.cpp ├── geometry/ │ ├── 3D/ │ │ └── geometry3D.cpp │ ├── argsort.cpp │ ├── geometry.cpp │ └── projectilemotion.cpp ├── graph/ │ ├── arborescence_edmond.cpp │ ├── arborescence_tarjan.cpp │ ├── bellmanford.cpp │ ├── bfs.cpp │ ├── bipartitedecomposition.cpp │ ├── chromatic.cpp │ ├── cycle.cpp │ ├── dijkstra.cpp │ ├── dominatortree.cpp │ ├── dynamicconnectivity.cpp │ ├── girth.cpp │ ├── grid.cpp │ ├── independentset.cpp │ ├── kruskal.cpp │ ├── lowlink.cpp │ ├── manhattanmst.cpp │ ├── multipleeuleriantrail.cpp │ ├── nicetree.cpp │ ├── rangetorange.cpp │ ├── semikernel.cpp │ ├── stronglyconnectedcomponent.cpp │ ├── topologicalsort.cpp │ ├── triangle.cpp │ ├── twoedgeconnectedcomponents.cpp │ ├── twosatisfiability.cpp │ └── voronoiminimumspanningtree.cpp ├── heuristic/ │ ├── timer.cpp │ └── xorshift.cpp ├── includes/ │ └── formalpowerseries.h ├── io/ │ ├── precision.cpp │ ├── single.cpp │ ├── space.cpp │ ├── tuple.cpp │ └── yesno.cpp ├── leetcode/ │ └── treenode.cpp ├── linearalgebra/ │ ├── binarymatrix.cpp │ ├── matrix.cpp │ ├── squarematrix.cpp │ └── tree_theorem.cpp ├── linkcuttree/ │ ├── base.cpp │ ├── farthest.cpp │ ├── path.cpp │ └── subtree.cpp ├── matching/ │ ├── bipartite.cpp │ ├── hopcroft_karp.cpp │ └── tutte.cpp ├── math/ │ ├── affine.cpp │ ├── bostanmori.cpp │ ├── carmichael.cpp │ ├── combination.cpp │ ├── convertbase.cpp │ ├── dual.cpp │ ├── enumerate_primes.cpp │ ├── extgcd.cpp │ ├── factorize.cpp │ ├── fraction.cpp │ ├── isprime.cpp │ ├── kitamasa.cpp │ ├── linearcongruence.cpp │ ├── linearfunction.cpp │ ├── moebius.cpp │ ├── quotients.cpp │ ├── sum_of_floor.cpp │ ├── sum_of_geometric_sequence.cpp │ ├── tetrahedra.cpp │ ├── totient.cpp │ ├── totient_table.cpp │ └── twoway.cpp ├── maxflow/ │ ├── dinic.cpp │ ├── fordfulkerson.cpp │ ├── leastflow.cpp │ └── twocommodity.cpp ├── mincostflow/ │ ├── negativeedge.cpp │ └── primaldual.cpp ├── mod/ │ ├── factorial.cpp │ ├── inverse.cpp │ ├── log.cpp │ ├── mint.cpp │ ├── montmort.cpp │ ├── order.cpp │ ├── pow.cpp │ ├── rint.cpp │ ├── sqrt.cpp │ └── tetration.cpp ├── polynomial/ │ ├── berlekampmassey.cpp │ ├── hash.cpp │ ├── interpolate.cpp │ ├── lagrangeinterpolation.cpp │ ├── multieval.cpp │ ├── polynomial.cpp │ └── recursivesequence.cpp ├── segtree/ │ ├── 2d/ │ │ └── ushi.cpp │ ├── basic/ │ │ ├── dual.cpp │ │ ├── lazy.cpp │ │ └── ushi.cpp │ ├── count/ │ │ ├── dynamic_offline.cpp │ │ └── static.cpp │ ├── persistent/ │ │ └── ushi.cpp │ └── types/ │ ├── offline.cpp │ └── online.cpp ├── string/ │ ├── ahocorasick.cpp │ ├── editdistance.cpp │ ├── knuthmorrispratt.cpp │ ├── longestcommonprefix.cpp │ ├── longestcommonsubstring.cpp │ ├── manacher.cpp │ ├── morrispratt.cpp │ ├── palindromictree.cpp │ ├── parse.cpp │ ├── rectanglehash.cpp │ ├── rollinghash.cpp │ ├── run.cpp │ ├── split.cpp │ ├── suffixarray.cpp │ ├── trie.cpp │ └── zalgorithm.cpp ├── test/ │ ├── aoj/ │ │ ├── 0109.test.cpp │ │ ├── 0168.test.cpp │ │ ├── 0233.test.cpp │ │ ├── 0294.test.cpp │ │ ├── 0314.test.cpp │ │ ├── 0343.test.cpp │ │ ├── 0367.linkcuttree.test.cpp │ │ ├── 0367.test.cpp │ │ ├── 0367.toptree.test.cpp │ │ ├── 0377.test.cpp │ │ ├── 0391.test.cpp │ │ ├── 0402.test.cpp │ │ ├── 0403.test.cpp │ │ ├── 0415.test.cpp │ │ ├── 0422.test.cpp │ │ ├── 0423.test.cpp │ │ ├── 0424.test.cpp │ │ ├── 0425.test.cpp │ │ ├── 0437.test.cpp │ │ ├── 0438.test.cpp │ │ ├── 0439.test.cpp │ │ ├── 0502.test.cpp │ │ ├── 0558.test.cpp │ │ ├── 0563.test.cpp │ │ ├── 0596.test.cpp │ │ ├── 0613.test.cpp │ │ ├── 1069.test.cpp │ │ ├── 1197.test.cpp │ │ ├── 1254.test.cpp │ │ ├── 1293.test.cpp │ │ ├── 1300.test.cpp │ │ ├── 1308.test.cpp │ │ ├── 1312.test.cpp │ │ ├── 1328.test.cpp │ │ ├── 1338.test.cpp │ │ ├── 1508.test.cpp │ │ ├── 1549.test.cpp │ │ ├── 1579.test.cpp │ │ ├── 1595.linkcuttree.test.cpp │ │ ├── 1595.test.cpp │ │ ├── 1595.toptree.test.cpp │ │ ├── 1599.test.cpp │ │ ├── 1607.test.cpp │ │ ├── 1613.test.cpp │ │ ├── 1615.test.cpp │ │ ├── 1630.test.cpp │ │ ├── 1642.test.cpp │ │ ├── 2060.test.cpp │ │ ├── 2187.test.cpp │ │ ├── 2212.test.cpp │ │ ├── 2222.test.cpp │ │ ├── 2230.test.cpp │ │ ├── 2235.test.cpp │ │ ├── 2257.test.cpp │ │ ├── 2270.test.cpp │ │ ├── 2286.test.cpp │ │ ├── 2290.test.cpp │ │ ├── 2292.test.cpp │ │ ├── 2294.test.cpp │ │ ├── 2308.test.cpp │ │ ├── 2309.tarjan.test.cpp │ │ ├── 2309.test.cpp │ │ ├── 2313.test.cpp │ │ ├── 2324.test.cpp │ │ ├── 2328.test.cpp │ │ ├── 2359.test.cpp │ │ ├── 2370.test.cpp │ │ ├── 2397.test.cpp │ │ ├── 2405.test.cpp │ │ ├── 2415.knuthyao.test.cpp │ │ ├── 2415.test.cpp │ │ ├── 2432.ignore.cpp │ │ ├── 2444.test.cpp │ │ ├── 2446.test.cpp │ │ ├── 2450.linkcuttree.test.cpp │ │ ├── 2450.test.cpp │ │ ├── 2488.test.cpp │ │ ├── 2513.test.cpp │ │ ├── 2560.test.cpp │ │ ├── 2563.test.cpp │ │ ├── 2603.test.cpp │ │ ├── 2624.test.cpp │ │ ├── 2627.test.cpp │ │ ├── 2636.test.cpp │ │ ├── 2644.test.cpp │ │ ├── 2646.test.cpp │ │ ├── 2647.test.cpp │ │ ├── 2659.test.cpp │ │ ├── 2667.test.cpp │ │ ├── 2674.count.test.cpp │ │ ├── 2674.test.cpp │ │ ├── 2679.test.cpp │ │ ├── 2687.test.cpp │ │ ├── 2711.test.cpp │ │ ├── 2720.test.cpp │ │ ├── 2725.linecontainer.test.cpp │ │ ├── 2725.test.cpp │ │ ├── 2736.test.cpp │ │ ├── 2790.test.cpp │ │ ├── 2842.BIT2D.test.cpp │ │ ├── 2842.test.cpp │ │ ├── 2871.test.cpp │ │ ├── 2872.test.cpp │ │ ├── 2890.test.cpp │ │ ├── 2891.test.cpp │ │ ├── 2934.test.cpp │ │ ├── 2948.test.cpp │ │ ├── 2951.test.cpp │ │ ├── 2959.test.cpp │ │ ├── 2968.test.cpp │ │ ├── 2969.test.cpp │ │ ├── 2970.test.cpp │ │ ├── 2971.test.cpp │ │ ├── 2975.test.cpp │ │ ├── 2977.test.cpp │ │ ├── 2979.test.cpp │ │ ├── 2981.test.cpp │ │ ├── 2983.test.cpp │ │ ├── 2985.garner.test.cpp │ │ ├── 2985.test.cpp │ │ ├── 2995.test.cpp │ │ ├── 3024.test.cpp │ │ ├── 3033.test.cpp │ │ ├── 3035.test.cpp │ │ ├── 3037.test.cpp │ │ ├── 3047.test.cpp │ │ ├── 3053.test.cpp │ │ ├── 3058.test.cpp │ │ ├── 3062.test.cpp │ │ ├── 3063.test.cpp │ │ ├── 3069.test.cpp │ │ ├── 3072.test.cpp │ │ ├── 3073.test.cpp │ │ ├── 3074.test.cpp │ │ ├── 3081.test.cpp │ │ ├── 3084.test.cpp │ │ ├── 3086.test.cpp │ │ ├── 3102.test.cpp │ │ ├── 3112.test.cpp │ │ ├── 3117.test.cpp │ │ ├── 3120.test.cpp │ │ ├── 3138.test.cpp │ │ ├── 3142.test.cpp │ │ ├── 3143.test.cpp │ │ ├── 3148.test.cpp │ │ ├── 3168.test.cpp │ │ ├── 3179.test.cpp │ │ ├── 3183.test.cpp │ │ ├── 3198.test.cpp │ │ ├── 3208.test.cpp │ │ ├── 3213.test.cpp │ │ ├── 3506.test.cpp │ │ ├── 3518.test.cpp │ │ ├── ALDS1_10_C.test.cpp │ │ ├── ALDS1_14_B.knuthmorrispratt.test.cpp │ │ ├── ALDS1_14_B.test.cpp │ │ ├── ALDS1_14_C.test.cpp │ │ ├── ALDS1_15_B.test.cpp │ │ ├── ALDS1_1_C.test.cpp │ │ ├── ALDS1_5_D.test.cpp │ │ ├── ALDS1_9_C.test.cpp │ │ ├── DPL_1_E.test.cpp │ │ ├── DPL_3_B.test.cpp │ │ ├── DPL_3_C.test.cpp │ │ ├── DPL_5_A.test.cpp │ │ ├── DPL_5_B.test.cpp │ │ ├── DPL_5_C.test.cpp │ │ ├── DPL_5_D.test.cpp │ │ ├── DPL_5_E.test.cpp │ │ ├── DPL_5_F.test.cpp │ │ ├── DPL_5_G.test.cpp │ │ ├── DPL_5_H.test.cpp │ │ ├── DPL_5_I.test.cpp │ │ ├── DPL_5_J.test.cpp │ │ ├── DPL_5_K.test.cpp │ │ ├── DPL_5_L.test.cpp │ │ ├── DSL_1_A.quickfind.test.cpp │ │ ├── DSL_1_A.test.cpp │ │ ├── DSL_1_B.test.cpp │ │ ├── DSL_2_B.test.cpp │ │ ├── DSL_2_C.test.cpp │ │ ├── DSL_2_D.test.cpp │ │ ├── DSL_2_E.test.cpp │ │ ├── DSL_2_F.bbst.test.cpp │ │ ├── DSL_2_F.test.cpp │ │ ├── DSL_2_G.bbst.test.cpp │ │ ├── DSL_2_H.bbst.test.cpp │ │ ├── DSL_2_H.test.cpp │ │ ├── DSL_2_I.bbst.test.cpp │ │ ├── DSL_2_I.test.cpp │ │ ├── DSL_3_D.cartesiantree.test.cpp │ │ ├── DSL_3_D.disjointsparsetable.test.cpp │ │ ├── DSL_3_D.slidingwindowaggregation.test.cpp │ │ ├── DSL_3_D.sparsetable.test.cpp │ │ ├── DSL_3_D.test.cpp │ │ ├── GRL_1_A.test.cpp │ │ ├── GRL_1_B.test.cpp │ │ ├── GRL_2_A.test.cpp │ │ ├── GRL_2_B.tarjan.test.cpp │ │ ├── GRL_2_B.test.cpp │ │ ├── GRL_3_A.test.cpp │ │ ├── GRL_3_B.test.cpp │ │ ├── GRL_4_B.ignore.cpp │ │ ├── GRL_5_A.linkcuttree.test.cpp │ │ ├── GRL_5_A.test.cpp │ │ ├── GRL_5_C.lca.test.cpp │ │ ├── GRL_5_C.test.cpp │ │ ├── GRL_5_D.linkcuttree.test.cpp │ │ ├── GRL_5_D.test.cpp │ │ ├── GRL_5_E.linkcuttree.test.cpp │ │ ├── GRL_6_A.test.cpp │ │ ├── GRL_6_B.test.cpp │ │ ├── GRL_7_A.test.cpp │ │ ├── ITP1_11_A.test.cpp │ │ ├── ITP1_11_B.test.cpp │ │ ├── ITP1_11_C.test.cpp │ │ ├── ITP1_11_D.test.cpp │ │ ├── NTL_1_A.test.cpp │ │ ├── NTL_1_B.test.cpp │ │ ├── NTL_1_D.test.cpp │ │ ├── NTL_1_E.test.cpp │ │ ├── NTL_2_A.test.cpp │ │ ├── NTL_2_B.test.cpp │ │ ├── NTL_2_C.test.cpp │ │ ├── NTL_2_D.test.cpp │ │ ├── NTL_2_E.test.cpp │ │ ├── NTL_2_F.test.cpp │ │ └── geometry/ │ │ ├── 2334.test.cpp │ │ ├── 2448.test.cpp │ │ ├── 2454.test.cpp │ │ ├── 3049.test.cpp │ │ ├── 3056.test.cpp │ │ ├── CGL_1_A.test.cpp │ │ ├── CGL_1_B.test.cpp │ │ ├── CGL_1_C.test.cpp │ │ ├── CGL_2_A.test.cpp │ │ ├── CGL_2_B.test.cpp │ │ ├── CGL_2_C.test.cpp │ │ ├── CGL_2_D.test.cpp │ │ ├── CGL_3_A.test.cpp │ │ ├── CGL_3_B.test.cpp │ │ ├── CGL_3_C.test.cpp │ │ ├── CGL_4_A.test.cpp │ │ ├── CGL_4_B.test.cpp │ │ ├── CGL_4_C.test.cpp │ │ ├── CGL_5_A.test.cpp │ │ ├── CGL_6_A.test.cpp │ │ ├── CGL_7_A.test.cpp │ │ ├── CGL_7_D.test.cpp │ │ ├── CGL_7_E.test.cpp │ │ ├── CGL_7_F.test.cpp │ │ ├── CGL_7_G.test.cpp │ │ ├── CGL_7_H.test.cpp │ │ └── CGL_7_I.test.cpp │ ├── yosupo/ │ │ ├── assignment.test.cpp │ │ ├── associative_array.test.cpp │ │ ├── bernoulli_number.test.cpp │ │ ├── bipartitematching.test.cpp │ │ ├── bitwise_and_convolution.test.cpp │ │ ├── bitwise_xor_convolution.test.cpp │ │ ├── cartesian_tree.test.cpp │ │ ├── convolution_mod.test.cpp │ │ ├── convolution_mod_1000000007.garner.test.cpp │ │ ├── convolution_mod_1000000007.test.cpp │ │ ├── cycle_detection.test.cpp │ │ ├── discrete_logarithm_mod.test.cpp │ │ ├── dominatortree.test.cpp │ │ ├── dynamic_sequence_range_affine_range_sum.test.cpp │ │ ├── dynamic_tree_vertex_add_path_sum.test.cpp │ │ ├── dynamic_tree_vertex_add_subtree_sum.test.cpp │ │ ├── dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp │ │ ├── dynamic_tree_vertex_set_path_composite.test.cpp │ │ ├── dynamic_tree_vertex_set_path_composite.toptree.test.cpp │ │ ├── enumerate_primes.test.cpp │ │ ├── enumerate_triangles.test.cpp │ │ ├── exp_of_formal_power_series.test.cpp │ │ ├── find_linear_recurrence.test.cpp │ │ ├── frequency_table_of_tree_distance.test.cpp │ │ ├── inv_of_formal_power_series.test.cpp │ │ ├── kth_root_integer.test.cpp │ │ ├── kth_term_of_linearly_recurrent_sequence.test.cpp │ │ ├── lca.linkcuttree.test.cpp │ │ ├── lca.test.cpp │ │ ├── line_add_get_min.test.cpp │ │ ├── log_of_formal_power_series.test.cpp │ │ ├── manhattanmst.test.cpp │ │ ├── many_aplusb.test.cpp │ │ ├── matrix_det.test.cpp │ │ ├── maximum_independent_set.test.cpp │ │ ├── min_cost_b_flow.test.cpp │ │ ├── montmort_number_mod.test.cpp │ │ ├── multipoint_evaluation.test.cpp │ │ ├── number_of_substrings.test.cpp │ │ ├── partition_function.test.cpp │ │ ├── persistent_queue.test.cpp │ │ ├── point_add_range_sum.test.cpp │ │ ├── point_add_rectangle_sum.test.cpp │ │ ├── point_set_range_composite.test.cpp │ │ ├── polynomial_interpolation.test.cpp │ │ ├── polynomial_taylor_shift.test.cpp │ │ ├── pow_of_formal_power_series.test.cpp │ │ ├── queue_operate_all_composite.test.cpp │ │ ├── range_affine_range_sum.test.cpp │ │ ├── range_kth_smallest.test.cpp │ │ ├── rectangle_sum.test.cpp │ │ ├── runenumerate.test.cpp │ │ ├── scc.test.cpp │ │ ├── segment_add_get_min.test.cpp │ │ ├── set_xor_min.test.cpp │ │ ├── sharp_p_subset_sum.test.cpp │ │ ├── shortest_path.test.cpp │ │ ├── sort_points_by_argument.test.cpp │ │ ├── sqrt_mod.test.cpp │ │ ├── sqrt_of_formal_power_series.test.cpp │ │ ├── static_range_frequency.test.cpp │ │ ├── static_range_inversions_query.test.cpp │ │ ├── static_range_sum.test.cpp │ │ ├── staticrmq.disjointsparsetable.test.cpp │ │ ├── staticrmq.sparsetable.test.cpp │ │ ├── stirling_number_of_the_first_kind.test.cpp │ │ ├── stirling_number_of_the_second_kind.test.cpp │ │ ├── subset_convolution.test.cpp │ │ ├── suffixarray.test.cpp │ │ ├── sum_of_floor_of_linear.test.cpp │ │ ├── tetration_mod.test.cpp │ │ ├── tree_decomposition_width_2.test.cpp │ │ ├── tree_diameter.test.cpp │ │ ├── two_edge_connected_components.test.cpp │ │ ├── two_sat.test.cpp │ │ ├── unionfind.test.cpp │ │ ├── vertex_add_path_sum.test.cpp │ │ ├── vertex_add_subtree_sum.test.cpp │ │ └── zalgorithm.test.cpp │ └── yukicoder/ │ ├── 0022.test.cpp │ ├── 0104.test.cpp │ ├── 0143.test.cpp │ ├── 0206.test.cpp │ ├── 0222.test.cpp │ ├── 0399.test.cpp │ ├── 0444.test.cpp │ ├── 0472.test.cpp │ ├── 0771.test.cpp │ ├── 0831.test.cpp │ ├── 1013.test.cpp │ ├── 1504.test.cpp │ ├── 1580.test.cpp │ ├── 1665.test.cpp │ ├── 1732.test.cpp │ ├── 1923.test.cpp │ ├── 1937.test.cpp │ ├── 1948.test.cpp │ ├── 1950.test.cpp │ ├── 1973.test.cpp │ ├── 2063.test.cpp │ ├── 2085.test.cpp │ ├── 2113.test.cpp │ ├── 2125.test.cpp │ ├── 2147.test.cpp │ ├── 2520.test.cpp │ ├── 2587.test.cpp │ ├── 2600.test.cpp │ ├── 2744.test.cpp │ ├── 2772.test.cpp │ ├── 3211.test.cpp │ ├── 3227.test.cpp │ ├── 3267.test.cpp │ ├── 3277.test.cpp │ ├── 3354.test.cpp │ ├── 3405.test.cpp │ ├── 3407.test.cpp │ ├── 3453.test.cpp │ ├── 3592.test.cpp │ ├── 3912.test.cpp │ ├── 3961.test.cpp │ ├── 4072.test.cpp │ ├── 4117.test.cpp │ ├── 4271.avx2.test.cpp │ ├── 4271.test.cpp │ ├── 4387.test.cpp │ ├── 4474.test.cpp │ ├── 4569.test.cpp │ ├── 4706.test.cpp │ ├── 4778.test.cpp │ ├── 4852.test.cpp │ ├── 4862.test.cpp │ ├── 4872.test.cpp │ ├── 4918.test.cpp │ ├── 4941.test.cpp │ ├── 5011.test.cpp │ ├── 5025.test.cpp │ ├── 5061.test.cpp │ ├── 5223.test.cpp │ ├── 5633.test.cpp │ ├── 6680.test.cpp │ ├── 7107.test.cpp │ └── 9158.test.cpp ├── tools/ │ ├── all_permutations.cpp │ ├── avx2.cpp │ ├── bigint.cpp │ ├── cc_hash.cpp │ ├── chminmax.cpp │ ├── debug.cpp │ ├── defaultdict.cpp │ ├── dice.cpp │ ├── drop.cpp │ ├── fastio.cpp │ ├── fixpoint.cpp │ ├── gridbfs.cpp │ ├── int128.cpp │ ├── iskado.cpp │ └── trio.cpp ├── toptree/ │ ├── base.cpp │ ├── distancesum.cpp │ ├── farthest.cpp │ ├── steiner.cpp │ └── toptree.cpp ├── tree/ │ ├── ahu.cpp │ ├── auxiliarytree.cpp │ ├── centroid.cpp │ ├── construct_from_distances_to_farthest_vertex.cpp │ ├── diameterforedge.cpp │ ├── diameterforvertex.cpp │ ├── eulertourforbfs.cpp │ ├── eulertourforedge.cpp │ ├── eulertourforvertex.cpp │ ├── heavylightdecomposition.cpp │ ├── lca.cpp │ ├── levelancestor.cpp │ ├── lowestcommonancestor.cpp │ ├── mo_on_tree.cpp │ ├── rerooting.cpp │ └── sack.cpp └── vector/ ├── compress.cpp ├── fusion.cpp ├── identity.cpp ├── inversion.cpp ├── multi.cpp ├── near.cpp ├── powers.cpp ├── reversed.cpp ├── runlength.cpp ├── sorted.cpp └── zip.cpp ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Create a report to help us improve title: '' labels: '' assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **Additional context** Add any other context about the problem here. ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: Feature request about: Suggest an idea for this project title: '' labels: '' assignees: '' --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .github/workflows/sanitize.yml ================================================ name: sanitize on: push jobs: build-sanitize: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Set up Python uses: actions/setup-python@v1 - name: Install dependencies run: pip3 install -U git+https://github.com/online-judge-tools/verification-helper@master - name: Run tests env: YUKICODER_TOKEN: ${{ secrets.YUKICODER_TOKEN }} run: oj-verify --config-file .verify-helper/sanitize.toml run -j 2 --timeout 3600 --tle 600 ================================================ FILE: .github/workflows/verify.yml ================================================ name: verify on: push jobs: build: runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v1 - name: Set up Python uses: actions/setup-python@v1 - name: Install dependencies run: pip3 install -U git+https://github.com/online-judge-tools/verification-helper@master - name: Run tests env: GH_PAT: ${{ secrets.GH_PAT }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} YUKICODER_TOKEN: ${{ secrets.YUKICODER_TOKEN }} run: oj-verify all -j 2 ================================================ FILE: .gitignore ================================================ #Do NOT edit this file manually. Use ./.gitignore_gen.sh > .gitignore ### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/Vim.gitignore # Swap [._]*.s[a-v][a-z] [._]*.sw[a-p] [._]s[a-v][a-z] [._]sw[a-p] # Session Session.vim # Temporary .netrwhist *~ # Auto-generated tag files tags ### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/Emacs.gitignore # -*- mode: gitignore; -*- *~ \#*\# /.emacs.desktop /.emacs.desktop.lock *.elc auto-save-list tramp .\#* # Org-mode .org-id-locations *_archive # flymake-mode *_flymake.* # eshell files /eshell/history /eshell/lastdir # elpa packages /elpa/ # reftex files *.rel # AUCTeX auto folder /auto/ # cask packages .cask/ dist/ # Flycheck flycheck_*.el # server auth directory /server/ # projectiles files .projectile # directory configuration .dir-locals.el ### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/C.gitignore # Prerequisites *.d # Object files *.o *.ko *.obj *.elf # Linker output *.ilk *.map *.exp # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ *.su *.idb *.pdb # Kernel Module Compile Results *.mod* *.cmd .tmp_versions/ modules.order Module.symvers Mkfile.old dkms.conf ### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/C++.gitignore # Prerequisites *.d # Compiled Object files *.slo *.lo *.o *.obj # Precompiled Headers *.gch *.pch # Compiled Dynamic libraries *.so *.dylib *.dll # Fortran module files *.mod *.smod # Compiled Static libraries *.lai *.la *.a *.lib # Executables *.exe *.out *.app ### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Python.gitignore # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ ### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Java.gitignore # Compiled class file *.class # Log file *.log # BlueJ files *.ctxt # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.ear *.zip *.tar.gz *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* setup.* bin rime-out library-checker-problems .DS_Store in in1 in2 in3 in4 in5 *.in ================================================ FILE: .gitignore_gen.sh ================================================ #!/bin/bash echo "#Do NOT edit this file manually. Use ./.gitignore_gen.sh > .gitignore" gibo dump Vim Emacs C C++ Python Java echo "setup.*" echo "bin" echo "rime-out" echo "library-checker-problems" echo ".DS_Store" echo "in" echo "in1" echo "in2" echo "in3" echo "in4" echo "in5" echo "*.in" ================================================ FILE: .verify-helper/config.toml ================================================ [[languages.cpp.environments]] CXX = "g++" [[languages.cpp.environments]] CXX = "clang++" ================================================ FILE: .verify-helper/docs/_config.yml ================================================ exclude: ["./heuristic/", "./leetcode/", "./test/aoj/2432.ignore.cpp", "test/aoj/GRL_4_B.ignore.cpp"] ================================================ FILE: .verify-helper/local.toml ================================================ [[languages.cpp.environments]] CXX = "g++" ================================================ FILE: .verify-helper/sanitize.toml ================================================ [[languages.cpp.environments]] CXX = "g++" CXXFLAGS = ["-std=c++17", "-Wall", "-g", "-DSANITIZE", "-fsanitize=undefined", "-D_GLIBCXX_DEBUG"] [[languages.cpp.environments]] CXX = "clang++" CXXFLAGS = ["-std=c++17", "-Wall", "-g", "-DSANITIZE", "-fsanitize=undefined", "-D_GLIBCXX_DEBUG"] ================================================ FILE: .verify-helper/timestamps.local.json.20201106 ================================================ { "test/aoj/0109.test.cpp": "2020-10-27 13:22:02 +0900", "test/aoj/0168.test.cpp": "2020-10-13 16:41:33 +0900", "test/aoj/0233.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0294.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0314.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/0343.test.cpp": "2020-10-27 12:52:35 +0900", "test/aoj/0367.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/0367.test.cpp": "2020-10-27 18:05:34 +0900", "test/aoj/0367.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/0377.test.cpp": "2020-10-27 15:55:39 +0900", "test/aoj/0391.test.cpp": "2020-11-02 16:39:41 +0900", "test/aoj/0403.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/0415.test.cpp": "2020-10-27 15:55:39 +0900", "test/aoj/0422.test.cpp": "2020-10-27 16:29:08 +0900", "test/aoj/0423.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0424.test.cpp": "2020-10-27 16:21:44 +0900", "test/aoj/0425.test.cpp": "2020-10-27 12:29:05 +0900", "test/aoj/0437.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/0438.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/0439.test.cpp": "2020-10-27 19:20:38 +0900", "test/aoj/0502.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/0558.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0563.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0596.test.cpp": "2020-10-27 16:43:37 +0900", "test/aoj/0613.test.cpp": "2020-10-27 12:54:24 +0900", "test/aoj/1069.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/1197.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/1254.test.cpp": "2020-10-26 14:43:47 +0900", "test/aoj/1293.test.cpp": "2020-10-27 16:18:38 +0900", "test/aoj/1300.test.cpp": "2020-10-27 13:20:54 +0900", "test/aoj/1308.test.cpp": "2020-10-27 15:57:10 +0900", "test/aoj/1312.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/1328.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/1338.test.cpp": "2020-10-07 14:37:56 +0900", "test/aoj/1508.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/1549.test.cpp": "2020-10-27 19:25:09 +0900", "test/aoj/1579.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/1595.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/1595.test.cpp": "2020-10-27 16:29:49 +0900", "test/aoj/1595.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/1599.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/1607.test.cpp": "2020-10-27 12:28:55 +0900", "test/aoj/1613.test.cpp": "2020-10-27 12:28:43 +0900", "test/aoj/1615.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/1630.test.cpp": "2020-10-27 17:57:02 +0900", "test/aoj/2060.test.cpp": "2020-10-27 16:03:41 +0900", "test/aoj/2187.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/2212.test.cpp": "2020-10-07 14:42:51 +0900", "test/aoj/2222.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2230.test.cpp": "2020-10-27 16:28:23 +0900", "test/aoj/2235.test.cpp": "2020-10-27 18:02:37 +0900", "test/aoj/2257.test.cpp": "2020-10-07 14:42:51 +0900", "test/aoj/2270.test.cpp": "2020-10-27 19:20:38 +0900", "test/aoj/2286.test.cpp": "2020-10-27 16:28:50 +0900", "test/aoj/2290.test.cpp": "2020-10-27 12:29:05 +0900", "test/aoj/2292.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/2294.test.cpp": "2020-10-27 12:29:08 +0900", "test/aoj/2308.test.cpp": "2020-10-27 15:49:25 +0900", "test/aoj/2309.tarjan.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2309.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2313.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/2324.test.cpp": "2020-10-27 15:54:31 +0900", "test/aoj/2328.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/2359.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2397.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/2405.test.cpp": "2020-10-27 15:54:50 +0900", "test/aoj/2415.knuthyao.test.cpp": "2020-10-27 12:47:14 +0900", "test/aoj/2415.test.cpp": "2020-10-27 12:59:47 +0900", "test/aoj/2444.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/2450.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/2450.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2488.test.cpp": "2020-10-27 12:47:14 +0900", "test/aoj/2513.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/2560.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2563.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2603.test.cpp": "2020-10-27 12:32:38 +0900", "test/aoj/2624.test.cpp": "2020-10-27 15:57:10 +0900", "test/aoj/2627.test.cpp": "2020-10-27 18:00:48 +0900", "test/aoj/2636.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/2644.test.cpp": "2020-10-27 19:01:32 +0900", "test/aoj/2646.test.cpp": "2020-10-27 13:57:14 +0900", "test/aoj/2647.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2659.test.cpp": "2020-10-27 16:28:57 +0900", "test/aoj/2667.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2674.count.test.cpp": "2020-10-27 18:05:48 +0900", "test/aoj/2674.test.cpp": "2020-10-27 19:25:09 +0900", "test/aoj/2679.test.cpp": "2020-10-07 13:03:03 +0900", "test/aoj/2711.test.cpp": "2020-10-27 19:01:32 +0900", "test/aoj/2720.test.cpp": "2020-10-24 13:43:25 +0900", "test/aoj/2725.test.cpp": "2020-10-27 12:59:18 +0900", "test/aoj/2736.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/2790.test.cpp": "2020-10-27 19:19:20 +0900", "test/aoj/2842.BIT2D.test.cpp": "2020-10-27 12:59:35 +0900", "test/aoj/2842.test.cpp": "2020-10-27 18:05:43 +0900", "test/aoj/2871.test.cpp": "2020-10-27 19:19:44 +0900", "test/aoj/2872.test.cpp": "2020-10-27 16:28:23 +0900", "test/aoj/2890.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/2934.test.cpp": "2020-10-27 13:21:18 +0900", "test/aoj/2948.test.cpp": "2020-10-27 15:53:30 +0900", "test/aoj/2951.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/2959.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2970.test.cpp": "2020-10-27 16:28:57 +0900", "test/aoj/2971.test.cpp": "2020-10-27 17:58:32 +0900", "test/aoj/2975.test.cpp": "2020-10-27 12:59:18 +0900", "test/aoj/2977.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2979.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/2983.test.cpp": "2020-10-27 16:18:21 +0900", "test/aoj/2985.garner.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2985.test.cpp": "2020-10-27 16:52:54 +0900", "test/aoj/2995.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/3024.test.cpp": "2020-10-27 13:26:17 +0900", "test/aoj/3033.test.cpp": "2020-10-27 19:01:32 +0900", "test/aoj/3035.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/3037.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/3047.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/3053.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/3058.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/3062.test.cpp": "2020-10-24 13:16:03 +0900", "test/aoj/3063.test.cpp": "2020-10-27 19:25:09 +0900", "test/aoj/3069.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/3072.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/3073.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/3074.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/3081.test.cpp": "2020-10-27 13:20:33 +0900", "test/aoj/3084.test.cpp": "2020-10-27 19:19:20 +0900", "test/aoj/3086.test.cpp": "2020-10-27 19:24:14 +0900", "test/aoj/3102.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/3112.test.cpp": "2020-10-27 19:01:32 +0900", "test/aoj/3117.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/3120.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/3138.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/3142.test.cpp": "2020-10-27 19:19:20 +0900", "test/aoj/3143.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/3148.test.cpp": "2020-10-27 16:29:49 +0900", "test/aoj/3168.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/3183.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/3198.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/3208.test.cpp": "2020-10-30 12:17:32 +0900", "test/aoj/3506.test.cpp": "2020-10-27 12:38:29 +0900", "test/aoj/ALDS1_10_C.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp": "2020-10-27 13:21:30 +0900", "test/aoj/ALDS1_14_B.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/ALDS1_14_C.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/ALDS1_15_B.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/ALDS1_1_C.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/ALDS1_9_C.test.cpp": "2020-10-27 12:59:47 +0900", "test/aoj/DPL_1_E.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/DPL_3_B.test.cpp": "2020-10-27 12:31:57 +0900", "test/aoj/DPL_3_C.test.cpp": "2020-10-27 12:31:57 +0900", "test/aoj/DPL_5_A.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_B.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_C.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_D.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_E.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_F.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_G.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_H.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_I.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_J.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_K.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_L.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DSL_1_A.quickfind.test.cpp": "2020-10-27 19:24:17 +0900", "test/aoj/DSL_1_A.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/DSL_1_B.test.cpp": "2020-10-27 19:25:22 +0900", "test/aoj/DSL_2_A.test.cpp": "2020-10-27 18:05:34 +0900", "test/aoj/DSL_2_B.test.cpp": "2020-10-27 12:53:16 +0900", "test/aoj/DSL_2_C.test.cpp": "2020-10-27 19:22:46 +0900", "test/aoj/DSL_2_D.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/DSL_2_E.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/DSL_2_F.bbst.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/DSL_2_F.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/DSL_2_G.bbst.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/DSL_2_H.bbst.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/DSL_2_H.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/DSL_2_I.bbst.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/DSL_2_I.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/DSL_3_D.cartesiantree.test.cpp": "2020-10-27 16:42:28 +0900", "test/aoj/DSL_3_D.disjointsparsetable.test.cpp": "2020-10-27 19:24:22 +0900", "test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/DSL_3_D.sparsetable.test.cpp": "2020-10-27 19:24:14 +0900", "test/aoj/DSL_3_D.test.cpp": "2020-10-27 12:54:24 +0900", "test/aoj/GRL_1_A.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/GRL_1_B.test.cpp": "2020-10-27 16:00:51 +0900", "test/aoj/GRL_2_A.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/GRL_2_B.tarjan.test.cpp": "2020-10-27 18:03:06 +0900", "test/aoj/GRL_2_B.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/GRL_3_A.test.cpp": "2020-10-27 15:53:46 +0900", "test/aoj/GRL_3_B.test.cpp": "2020-10-27 15:53:46 +0900", "test/aoj/GRL_5_A.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/GRL_5_A.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/GRL_5_C.lca.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/GRL_5_C.test.cpp": "2020-10-27 19:20:38 +0900", "test/aoj/GRL_5_D.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/GRL_5_D.test.cpp": "2020-10-27 19:19:29 +0900", "test/aoj/GRL_5_E.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/GRL_6_A.test.cpp": "2020-10-27 18:00:21 +0900", "test/aoj/GRL_6_B.test.cpp": "2020-10-07 13:03:03 +0900", "test/aoj/GRL_7_A.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/ITP1_11_A.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/ITP1_11_B.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/ITP1_11_C.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/ITP1_11_D.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/NTL_1_A.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/NTL_1_B.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/NTL_1_D.test.cpp": "2020-10-24 12:57:13 +0900", "test/aoj/NTL_1_E.test.cpp": "2020-10-27 16:28:57 +0900", "test/aoj/NTL_2_A.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_B.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_C.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_D.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_E.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_F.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/geometry/2334.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/geometry/2448.test.cpp": "2020-10-27 12:47:27 +0900", "test/aoj/geometry/2454.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/3049.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/geometry/3056.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/geometry/CGL_1_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_1_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_1_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_D.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/geometry/CGL_3_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_3_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_3_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_4_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_4_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_4_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_5_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_6_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_D.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_E.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_F.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_G.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_H.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/geometry/CGL_7_I.test.cpp": "2020-10-27 12:28:39 +0900", "test/yosupo/assignment.test.cpp": "2020-10-27 16:28:23 +0900", "test/yosupo/associative_array.test.cpp": "2020-10-27 12:28:01 +0900", "test/yosupo/bernoulli_number.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/bipartitematching.test.cpp": "2020-10-27 16:21:44 +0900", "test/yosupo/cartesian_tree.test.cpp": "2020-10-27 16:42:28 +0900", "test/yosupo/convolution_mod.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/convolution_mod_1000000007.garner.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/convolution_mod_1000000007.test.cpp": "2020-10-27 16:52:54 +0900", "test/yosupo/discrete_logarithm_mod.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/dominatortree.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/yosupo/enumerate_primes.test.cpp": "2020-10-07 11:58:48 +0900", "test/yosupo/enumerate_triangles.test.cpp": "2020-10-27 16:43:59 +0900", "test/yosupo/exp_of_formal_power_series.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/find_linear_recurrence.test.cpp": "2020-10-27 16:43:02 +0900", "test/yosupo/frequency_table_of_tree_distance.test.cpp": "2020-10-27 19:19:20 +0900", "test/yosupo/inv_of_formal_power_series.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/kth_root_integer.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/lca.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/lca.test.cpp": "2020-10-27 19:20:38 +0900", "test/yosupo/line_add_get_min.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/log_of_formal_power_series.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/manhattanmst.test.cpp": "2020-10-27 19:24:11 +0900", "test/yosupo/many_aplusb.test.cpp": "2020-10-27 12:27:57 +0900", "test/yosupo/matrix_det.test.cpp": "2020-10-27 13:13:32 +0900", "test/yosupo/maximum_independent_set.test.cpp": "2020-10-27 15:53:30 +0900", "test/yosupo/min_cost_b_flow.test.cpp": "2020-10-27 16:28:23 +0900", "test/yosupo/montmort_number_mod.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/multipoint_evaluation.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/number_of_substrings.test.cpp": "2020-10-27 19:01:32 +0900", "test/yosupo/partition_function.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/persistent_queue.test.cpp": "2020-11-04 18:44:56 +0900", "test/yosupo/point_add_range_sum.test.cpp": "2020-10-27 12:52:35 +0900", "test/yosupo/point_add_rectangle_sum.test.cpp": "2020-10-27 18:05:43 +0900", "test/yosupo/point_set_range_composite.test.cpp": "2020-10-27 18:05:34 +0900", "test/yosupo/polynomial_interpolation.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/polynomial_taylor_shift.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/pow_of_formal_power_series.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/queue_operate_all_composite.test.cpp": "2020-10-27 16:28:39 +0900", "test/yosupo/range_affine_range_sum.test.cpp": "2020-10-27 16:18:54 +0900", "test/yosupo/range_kth_smallest.test.cpp": "2020-10-27 19:25:09 +0900", "test/yosupo/rectangle_sum.test.cpp": "2020-10-27 18:05:43 +0900", "test/yosupo/runenumerate.test.cpp": "2020-10-27 13:20:33 +0900", "test/yosupo/scc.test.cpp": "2020-10-27 18:02:44 +0900", "test/yosupo/segment_add_get_min.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/set_xor_min.test.cpp": "2020-10-27 12:53:16 +0900", "test/yosupo/shortest_path.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/sort_points_by_argument.test.cpp": "2020-10-27 16:29:27 +0900", "test/yosupo/sqrt_mod.test.cpp": "2020-10-27 16:02:40 +0900", "test/yosupo/sqrt_of_formal_power_series.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/static_range_inversions_query.test.cpp": "2020-10-27 12:52:35 +0900", "test/yosupo/static_range_sum.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/staticrmq.disjointsparsetable.test.cpp": "2020-10-27 19:24:22 +0900", "test/yosupo/staticrmq.sparsetable.test.cpp": "2020-10-27 19:24:14 +0900", "test/yosupo/stirling_number_of_the_first_kind.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/stirling_number_of_the_second_kind.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/suffixarray.test.cpp": "2020-10-27 19:01:32 +0900", "test/yosupo/sum_of_floor_of_linear.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/tetration_mod.test.cpp": "2020-10-27 13:23:08 +0900", "test/yosupo/tree_decomposition_width_2.test.cpp": "2020-10-27 15:54:50 +0900", "test/yosupo/tree_diameter.test.cpp": "2020-10-27 12:47:27 +0900", "test/yosupo/two_edge_connected_components.test.cpp": "2020-10-27 15:55:39 +0900", "test/yosupo/two_sat.test.cpp": "2020-10-27 18:02:44 +0900", "test/yosupo/unionfind.test.cpp": "2020-10-27 19:24:11 +0900", "test/yosupo/vertex_add_path_sum.test.cpp": "2020-10-28 14:04:34 +0900", "test/yosupo/vertex_add_subtree_sum.test.cpp": "2020-10-27 19:19:44 +0900", "test/yosupo/zalgorithm.test.cpp": "2020-10-27 13:20:33 +0900", "test/yukicoder/0022.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/0104.test.cpp": "2020-10-27 16:43:02 +0900", "test/yukicoder/0143.test.cpp": "2020-10-27 12:49:07 +0900", "test/yukicoder/0222.test.cpp": "2020-10-05 16:59:31 +0900", "test/yukicoder/0399.test.cpp": "2020-10-27 19:01:09 +0900", "test/yukicoder/0444.test.cpp": "2020-10-27 16:52:54 +0900", "test/yukicoder/0472.test.cpp": "2020-10-27 13:23:08 +0900", "test/yukicoder/0831.test.cpp": "2020-10-27 12:49:07 +0900", "test/yukicoder/1504.test.cpp": "2020-10-27 16:53:25 +0900", "test/yukicoder/1580.test.cpp": "2020-10-05 16:59:31 +0900", "test/yukicoder/1665.test.cpp": "2020-10-27 16:28:50 +0900", "test/yukicoder/1732.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/1923.test.cpp": "2020-10-27 12:54:24 +0900", "test/yukicoder/1937.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/1948.test.cpp": "2020-10-27 12:32:58 +0900", "test/yukicoder/1950.test.cpp": "2020-10-27 12:32:58 +0900", "test/yukicoder/1973.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/2063.test.cpp": "2020-10-27 18:05:43 +0900", "test/yukicoder/2085.test.cpp": "2020-10-27 16:29:49 +0900", "test/yukicoder/2113.test.cpp": "2020-10-27 12:32:58 +0900", "test/yukicoder/2125.test.cpp": "2020-10-27 12:52:35 +0900", "test/yukicoder/2147.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/2587.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/2600.test.cpp": "2020-10-27 12:51:44 +0900", "test/yukicoder/2744.test.cpp": "2020-10-27 16:52:54 +0900", "test/yukicoder/2772.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/3211.test.cpp": "2020-10-27 16:43:02 +0900", "test/yukicoder/3227.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/3405.test.cpp": "2020-11-02 16:12:34 +0900", "test/yukicoder/3407.test.cpp": "2020-10-27 19:20:38 +0900", "test/yukicoder/3453.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/3592.test.cpp": "2020-10-27 19:25:22 +0900", "test/yukicoder/3912.test.cpp": "2020-10-27 19:19:20 +0900", "test/yukicoder/3961.test.cpp": "2020-10-27 19:19:20 +0900", "test/yukicoder/4072.test.cpp": "2020-10-27 19:24:22 +0900", "test/yukicoder/4271.test.cpp": "2020-10-27 16:42:52 +0900", "test/yukicoder/4387.test.cpp": "2020-10-27 18:02:44 +0900", "test/yukicoder/4474.test.cpp": "2020-10-24 13:16:03 +0900", "test/yukicoder/4569.test.cpp": "2020-10-27 16:29:08 +0900", "test/yukicoder/4706.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/4778.test.cpp": "2020-10-27 12:29:12 +0900", "test/yukicoder/4852.test.cpp": "2020-10-27 19:20:38 +0900", "test/yukicoder/4862.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/4918.test.cpp": "2020-10-27 12:28:47 +0900", "test/yukicoder/4941.test.cpp": "2020-10-07 14:35:46 +0900", "test/yukicoder/5011.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/5223.test.cpp": "2020-10-27 16:18:54 +0900" } ================================================ FILE: .verify-helper/timestamps.local.json.20210324 ================================================ { "test/aoj/0109.test.cpp": "2020-12-19 16:43:05 +0900", "test/aoj/0168.test.cpp": "2020-12-20 13:43:25 +0900", "test/aoj/0233.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0294.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0314.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/0343.test.cpp": "2020-10-27 12:52:35 +0900", "test/aoj/0367.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/0367.test.cpp": "2021-02-05 14:58:50 +0900", "test/aoj/0367.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/0377.test.cpp": "2020-10-27 15:55:39 +0900", "test/aoj/0391.test.cpp": "2020-11-02 16:39:41 +0900", "test/aoj/0402.test.cpp": "2020-12-16 13:02:24 +0900", "test/aoj/0403.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/0415.test.cpp": "2020-10-27 15:55:39 +0900", "test/aoj/0422.test.cpp": "2020-10-27 16:29:08 +0900", "test/aoj/0423.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0424.test.cpp": "2020-10-27 16:21:44 +0900", "test/aoj/0425.test.cpp": "2020-10-27 12:29:05 +0900", "test/aoj/0437.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/0438.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/0439.test.cpp": "2020-10-27 19:20:38 +0900", "test/aoj/0502.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/0558.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0563.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/0596.test.cpp": "2020-10-27 16:43:37 +0900", "test/aoj/0613.test.cpp": "2020-10-27 12:54:24 +0900", "test/aoj/1069.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/1197.test.cpp": "2020-11-15 18:49:57 +0900", "test/aoj/1254.test.cpp": "2020-10-26 14:43:47 +0900", "test/aoj/1293.test.cpp": "2020-10-27 16:18:38 +0900", "test/aoj/1300.test.cpp": "2020-10-27 13:20:54 +0900", "test/aoj/1308.test.cpp": "2020-10-27 15:57:10 +0900", "test/aoj/1312.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/1328.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/1338.test.cpp": "2020-10-07 14:37:56 +0900", "test/aoj/1508.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/1549.test.cpp": "2020-10-27 19:25:09 +0900", "test/aoj/1579.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/1595.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/1595.test.cpp": "2020-10-27 16:29:49 +0900", "test/aoj/1595.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/1599.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/1607.test.cpp": "2020-10-27 12:28:55 +0900", "test/aoj/1613.test.cpp": "2020-10-27 12:28:43 +0900", "test/aoj/1615.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/1630.test.cpp": "2020-10-27 17:57:02 +0900", "test/aoj/1642.test.cpp": "2020-11-19 16:59:17 +0900", "test/aoj/2060.test.cpp": "2020-10-27 16:03:41 +0900", "test/aoj/2187.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/2212.test.cpp": "2021-01-22 18:37:25 +0900", "test/aoj/2222.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2230.test.cpp": "2020-10-27 16:28:23 +0900", "test/aoj/2235.test.cpp": "2020-10-27 18:02:37 +0900", "test/aoj/2257.test.cpp": "2021-01-22 18:37:25 +0900", "test/aoj/2270.test.cpp": "2020-10-27 19:20:38 +0900", "test/aoj/2286.test.cpp": "2020-10-27 16:28:50 +0900", "test/aoj/2290.test.cpp": "2020-10-27 12:29:05 +0900", "test/aoj/2292.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/2294.test.cpp": "2020-10-27 12:29:08 +0900", "test/aoj/2308.test.cpp": "2020-10-27 15:49:25 +0900", "test/aoj/2309.tarjan.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2309.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2313.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/2324.test.cpp": "2020-10-27 15:54:31 +0900", "test/aoj/2328.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/2359.test.cpp": "2020-11-15 18:14:06 +0900", "test/aoj/2397.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/2405.test.cpp": "2020-10-27 15:54:50 +0900", "test/aoj/2415.knuthyao.test.cpp": "2020-10-27 12:47:14 +0900", "test/aoj/2415.test.cpp": "2020-10-27 12:59:47 +0900", "test/aoj/2444.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/2446.test.cpp": "2020-12-16 13:02:24 +0900", "test/aoj/2450.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/2450.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2488.test.cpp": "2020-10-27 12:47:14 +0900", "test/aoj/2513.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/2560.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2563.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2603.test.cpp": "2021-03-05 12:18:38 +0900", "test/aoj/2624.test.cpp": "2020-10-27 15:57:10 +0900", "test/aoj/2627.test.cpp": "2020-10-27 18:00:48 +0900", "test/aoj/2636.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/2644.test.cpp": "2021-02-05 14:58:50 +0900", "test/aoj/2646.test.cpp": "2020-10-27 13:57:14 +0900", "test/aoj/2647.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/2659.test.cpp": "2020-11-13 17:53:54 +0900", "test/aoj/2667.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/2674.count.test.cpp": "2020-10-27 18:05:48 +0900", "test/aoj/2674.test.cpp": "2020-10-27 19:25:09 +0900", "test/aoj/2679.test.cpp": "2020-10-07 13:03:03 +0900", "test/aoj/2687.test.cpp": "2021-03-11 20:23:34 +0900", "test/aoj/2711.test.cpp": "2020-12-28 13:48:49 +0900", "test/aoj/2720.test.cpp": "2020-10-24 13:43:25 +0900", "test/aoj/2725.test.cpp": "2020-10-27 12:59:18 +0900", "test/aoj/2736.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/2790.test.cpp": "2020-10-27 19:19:20 +0900", "test/aoj/2842.BIT2D.test.cpp": "2020-10-27 12:59:35 +0900", "test/aoj/2842.test.cpp": "2020-10-27 18:05:43 +0900", "test/aoj/2871.test.cpp": "2020-10-27 19:19:44 +0900", "test/aoj/2872.test.cpp": "2020-10-27 16:28:23 +0900", "test/aoj/2890.test.cpp": "2020-11-04 18:44:56 +0900", "test/aoj/2891.test.cpp": "2021-01-03 18:38:06 +0900", "test/aoj/2934.test.cpp": "2020-10-27 13:21:18 +0900", "test/aoj/2948.test.cpp": "2020-10-27 15:53:30 +0900", "test/aoj/2951.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/2959.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2968.test.cpp": "2020-11-15 17:38:18 +0900", "test/aoj/2969.test.cpp": "2021-02-05 14:58:50 +0900", "test/aoj/2970.test.cpp": "2020-11-13 17:53:54 +0900", "test/aoj/2971.test.cpp": "2020-10-27 17:58:32 +0900", "test/aoj/2975.test.cpp": "2020-10-27 12:59:18 +0900", "test/aoj/2977.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/2979.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/2981.test.cpp": "2020-12-16 13:02:24 +0900", "test/aoj/2983.test.cpp": "2020-10-27 16:18:21 +0900", "test/aoj/2985.garner.test.cpp": "2020-11-22 16:21:33 +0900", "test/aoj/2985.test.cpp": "2020-11-22 16:21:33 +0900", "test/aoj/2995.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/3024.test.cpp": "2020-10-27 13:26:17 +0900", "test/aoj/3033.test.cpp": "2020-12-28 13:48:49 +0900", "test/aoj/3035.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/3037.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/3047.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/3053.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/3058.test.cpp": "2020-10-27 18:00:16 +0900", "test/aoj/3062.test.cpp": "2020-11-13 17:54:21 +0900", "test/aoj/3063.test.cpp": "2020-12-28 13:48:49 +0900", "test/aoj/3069.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/3072.test.cpp": "2020-11-22 16:21:33 +0900", "test/aoj/3073.test.cpp": "2021-01-22 18:37:25 +0900", "test/aoj/3074.test.cpp": "2020-10-27 16:53:25 +0900", "test/aoj/3081.test.cpp": "2021-03-04 16:59:57 +0900", "test/aoj/3084.test.cpp": "2020-11-22 16:22:14 +0900", "test/aoj/3086.test.cpp": "2020-10-27 19:24:14 +0900", "test/aoj/3102.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/3112.test.cpp": "2020-12-28 13:48:49 +0900", "test/aoj/3117.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/3120.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/3138.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/3142.test.cpp": "2020-10-27 19:19:20 +0900", "test/aoj/3143.test.cpp": "2020-10-27 18:58:51 +0900", "test/aoj/3148.test.cpp": "2020-10-27 16:29:49 +0900", "test/aoj/3168.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/3183.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/3198.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/3208.test.cpp": "2020-10-30 12:17:32 +0900", "test/aoj/3213.test.cpp": "2020-12-19 16:55:59 +0900", "test/aoj/3506.test.cpp": "2020-10-27 12:38:29 +0900", "test/aoj/ALDS1_10_C.test.cpp": "2020-12-21 13:20:36 +0900", "test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp": "2020-10-27 13:21:30 +0900", "test/aoj/ALDS1_14_B.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/ALDS1_14_C.test.cpp": "2020-10-27 19:01:09 +0900", "test/aoj/ALDS1_15_B.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/ALDS1_1_C.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/ALDS1_9_C.test.cpp": "2020-10-27 12:59:47 +0900", "test/aoj/DPL_1_E.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/DPL_3_B.test.cpp": "2020-10-27 12:31:57 +0900", "test/aoj/DPL_3_C.test.cpp": "2020-10-27 12:31:57 +0900", "test/aoj/DPL_5_A.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_B.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_C.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_D.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_E.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_F.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_G.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_H.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_I.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_J.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_K.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DPL_5_L.test.cpp": "2020-10-27 13:13:32 +0900", "test/aoj/DSL_1_A.quickfind.test.cpp": "2020-10-27 19:24:17 +0900", "test/aoj/DSL_1_A.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/DSL_1_B.test.cpp": "2020-10-27 19:25:22 +0900", "test/aoj/DSL_2_B.test.cpp": "2020-10-27 12:53:16 +0900", "test/aoj/DSL_2_C.test.cpp": "2020-10-27 19:22:46 +0900", "test/aoj/DSL_2_D.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/DSL_2_E.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/DSL_2_F.bbst.test.cpp": "2020-11-28 18:11:38 +0900", "test/aoj/DSL_2_F.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/DSL_2_G.bbst.test.cpp": "2020-11-28 18:12:25 +0900", "test/aoj/DSL_2_H.bbst.test.cpp": "2020-11-28 18:12:43 +0900", "test/aoj/DSL_2_H.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/DSL_2_I.bbst.test.cpp": "2020-11-28 18:14:23 +0900", "test/aoj/DSL_2_I.test.cpp": "2020-10-27 16:18:54 +0900", "test/aoj/DSL_3_D.cartesiantree.test.cpp": "2020-10-27 16:42:28 +0900", "test/aoj/DSL_3_D.disjointsparsetable.test.cpp": "2020-10-27 19:24:22 +0900", "test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/DSL_3_D.sparsetable.test.cpp": "2020-10-27 19:24:14 +0900", "test/aoj/DSL_3_D.test.cpp": "2020-10-27 12:54:24 +0900", "test/aoj/GRL_1_A.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/GRL_1_B.test.cpp": "2020-10-27 16:00:51 +0900", "test/aoj/GRL_2_A.test.cpp": "2020-10-27 19:24:11 +0900", "test/aoj/GRL_2_B.tarjan.test.cpp": "2020-10-27 18:03:06 +0900", "test/aoj/GRL_2_B.test.cpp": "2020-10-27 18:02:44 +0900", "test/aoj/GRL_3_A.test.cpp": "2020-10-27 15:53:46 +0900", "test/aoj/GRL_3_B.test.cpp": "2020-10-27 15:53:46 +0900", "test/aoj/GRL_5_A.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/GRL_5_A.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/GRL_5_C.lca.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/GRL_5_C.test.cpp": "2020-10-27 19:20:38 +0900", "test/aoj/GRL_5_D.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/GRL_5_D.test.cpp": "2020-10-27 19:19:29 +0900", "test/aoj/GRL_5_E.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/aoj/GRL_6_A.test.cpp": "2020-10-27 18:00:21 +0900", "test/aoj/GRL_6_B.test.cpp": "2020-10-07 13:03:03 +0900", "test/aoj/GRL_7_A.test.cpp": "2020-10-27 16:19:34 +0900", "test/aoj/ITP1_11_A.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/ITP1_11_B.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/ITP1_11_C.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/ITP1_11_D.test.cpp": "2020-10-25 17:34:04 +0900", "test/aoj/NTL_1_A.test.cpp": "2020-10-05 16:59:31 +0900", "test/aoj/NTL_1_B.test.cpp": "2020-11-13 17:54:21 +0900", "test/aoj/NTL_1_D.test.cpp": "2020-10-24 12:57:13 +0900", "test/aoj/NTL_1_E.test.cpp": "2020-10-27 16:28:57 +0900", "test/aoj/NTL_2_A.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_B.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_C.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_D.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_E.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/NTL_2_F.test.cpp": "2020-10-27 12:49:07 +0900", "test/aoj/geometry/2334.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/geometry/2448.test.cpp": "2020-10-27 12:47:27 +0900", "test/aoj/geometry/2454.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/3049.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/geometry/3056.test.cpp": "2020-10-27 12:28:09 +0900", "test/aoj/geometry/CGL_1_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_1_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_1_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_2_D.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/geometry/CGL_3_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_3_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_3_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_4_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_4_B.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_4_C.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_5_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_6_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_A.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_D.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_E.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_F.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_G.test.cpp": "2020-10-26 15:07:27 +0900", "test/aoj/geometry/CGL_7_H.test.cpp": "2020-10-27 12:28:39 +0900", "test/aoj/geometry/CGL_7_I.test.cpp": "2020-10-27 12:28:39 +0900", "test/yosupo/assignment.test.cpp": "2020-10-27 16:28:23 +0900", "test/yosupo/associative_array.test.cpp": "2020-10-27 12:28:01 +0900", "test/yosupo/bernoulli_number.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/bipartitematching.test.cpp": "2020-10-27 16:21:44 +0900", "test/yosupo/bitwise_and_convolution.test.cpp": "2020-12-16 13:02:24 +0900", "test/yosupo/bitwise_xor_convolution.test.cpp": "2020-12-16 13:02:24 +0900", "test/yosupo/cartesian_tree.test.cpp": "2020-10-27 16:42:28 +0900", "test/yosupo/convolution_mod.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/convolution_mod_1000000007.garner.test.cpp": "2020-10-27 16:53:25 +0900", "test/yosupo/convolution_mod_1000000007.test.cpp": "2020-10-27 16:52:54 +0900", "test/yosupo/cycle_detection.test.cpp": "2021-01-03 18:34:38 +0900", "test/yosupo/discrete_logarithm_mod.test.cpp": "2020-11-13 17:53:32 +0900", "test/yosupo/dominatortree.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/dynamic_sequence_range_affine_range_sum.test.cpp": "2020-11-28 18:18:13 +0900", "test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp": "2020-10-27 18:58:51 +0900", "test/yosupo/enumerate_primes.test.cpp": "2020-10-07 11:58:48 +0900", "test/yosupo/enumerate_triangles.test.cpp": "2020-10-27 16:43:59 +0900", "test/yosupo/exp_of_formal_power_series.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/find_linear_recurrence.test.cpp": "2020-10-27 16:43:02 +0900", "test/yosupo/frequency_table_of_tree_distance.test.cpp": "2020-10-27 19:19:20 +0900", "test/yosupo/inv_of_formal_power_series.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/kth_root_integer.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/kth_term_of_linearly_recurrent_sequence.test.cpp": "2021-02-02 17:29:25 +0900", "test/yosupo/lca.linkcuttree.test.cpp": "2020-10-28 18:39:44 +0900", "test/yosupo/lca.test.cpp": "2020-10-27 19:20:38 +0900", "test/yosupo/line_add_get_min.test.cpp": "2020-11-22 19:36:37 +0900", "test/yosupo/log_of_formal_power_series.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/manhattanmst.test.cpp": "2020-10-27 19:24:11 +0900", "test/yosupo/many_aplusb.test.cpp": "2020-10-27 12:27:57 +0900", "test/yosupo/matrix_det.test.cpp": "2020-10-27 13:13:32 +0900", "test/yosupo/maximum_independent_set.test.cpp": "2020-10-27 15:53:30 +0900", "test/yosupo/min_cost_b_flow.test.cpp": "2020-10-27 16:28:23 +0900", "test/yosupo/montmort_number_mod.test.cpp": "2020-11-13 17:52:53 +0900", "test/yosupo/multipoint_evaluation.test.cpp": "2020-11-22 16:24:54 +0900", "test/yosupo/number_of_substrings.test.cpp": "2020-12-28 13:48:49 +0900", "test/yosupo/partition_function.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/persistent_queue.test.cpp": "2020-11-04 18:44:56 +0900", "test/yosupo/point_add_range_sum.test.cpp": "2020-10-27 12:52:35 +0900", "test/yosupo/point_add_rectangle_sum.test.cpp": "2020-10-27 18:05:43 +0900", "test/yosupo/point_set_range_composite.test.cpp": "2021-02-05 14:58:50 +0900", "test/yosupo/polynomial_interpolation.test.cpp": "2020-11-22 16:24:54 +0900", "test/yosupo/polynomial_taylor_shift.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/pow_of_formal_power_series.test.cpp": "2020-11-22 16:22:14 +0900", "test/yosupo/queue_operate_all_composite.test.cpp": "2020-10-27 16:28:39 +0900", "test/yosupo/range_affine_range_sum.test.cpp": "2020-11-28 18:18:13 +0900", "test/yosupo/range_kth_smallest.test.cpp": "2020-10-27 19:25:09 +0900", "test/yosupo/rectangle_sum.test.cpp": "2020-10-27 18:05:43 +0900", "test/yosupo/runenumerate.test.cpp": "2021-03-04 16:59:57 +0900", "test/yosupo/scc.test.cpp": "2020-10-27 18:02:44 +0900", "test/yosupo/segment_add_get_min.test.cpp": "2020-11-22 19:36:37 +0900", "test/yosupo/set_xor_min.test.cpp": "2020-10-27 12:53:16 +0900", "test/yosupo/sharp_p_subset_sum.test.cpp": "2020-12-21 13:43:02 +0900", "test/yosupo/shortest_path.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/sort_points_by_argument.test.cpp": "2020-10-27 16:29:27 +0900", "test/yosupo/sqrt_mod.test.cpp": "2020-11-13 20:21:23 +0900", "test/yosupo/sqrt_of_formal_power_series.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/static_range_inversions_query.test.cpp": "2020-10-27 12:52:35 +0900", "test/yosupo/static_range_sum.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/staticrmq.disjointsparsetable.test.cpp": "2020-10-27 19:24:22 +0900", "test/yosupo/staticrmq.sparsetable.test.cpp": "2020-10-27 19:24:14 +0900", "test/yosupo/stirling_number_of_the_first_kind.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/stirling_number_of_the_second_kind.test.cpp": "2020-11-22 16:21:33 +0900", "test/yosupo/subset_convolution.test.cpp": "2020-12-16 13:03:55 +0900", "test/yosupo/suffixarray.test.cpp": "2020-12-28 13:48:49 +0900", "test/yosupo/sum_of_floor_of_linear.test.cpp": "2020-10-05 16:59:31 +0900", "test/yosupo/tetration_mod.test.cpp": "2020-11-13 17:56:51 +0900", "test/yosupo/tree_decomposition_width_2.test.cpp": "2020-10-27 15:54:50 +0900", "test/yosupo/tree_diameter.test.cpp": "2020-10-27 12:47:27 +0900", "test/yosupo/two_edge_connected_components.test.cpp": "2020-10-27 15:55:39 +0900", "test/yosupo/two_sat.test.cpp": "2020-10-27 18:02:44 +0900", "test/yosupo/unionfind.test.cpp": "2020-10-27 19:24:11 +0900", "test/yosupo/vertex_add_path_sum.test.cpp": "2020-10-28 14:04:34 +0900", "test/yosupo/vertex_add_subtree_sum.test.cpp": "2020-10-27 19:19:44 +0900", "test/yosupo/zalgorithm.test.cpp": "2021-03-04 17:00:27 +0900", "test/yukicoder/0022.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/0104.test.cpp": "2020-12-20 13:43:25 +0900", "test/yukicoder/0143.test.cpp": "2020-10-27 12:49:07 +0900", "test/yukicoder/0222.test.cpp": "2020-10-05 16:59:31 +0900", "test/yukicoder/0399.test.cpp": "2020-10-27 19:01:09 +0900", "test/yukicoder/0444.test.cpp": "2020-12-20 13:43:25 +0900", "test/yukicoder/0472.test.cpp": "2020-11-13 17:56:51 +0900", "test/yukicoder/0831.test.cpp": "2020-10-27 12:49:07 +0900", "test/yukicoder/1013.test.cpp": "2021-01-22 18:37:25 +0900", "test/yukicoder/1504.test.cpp": "2020-11-13 17:54:01 +0900", "test/yukicoder/1580.test.cpp": "2020-10-05 16:59:31 +0900", "test/yukicoder/1665.test.cpp": "2020-10-27 16:28:50 +0900", "test/yukicoder/1732.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/1923.test.cpp": "2020-10-27 12:54:24 +0900", "test/yukicoder/1937.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/1948.test.cpp": "2020-10-27 12:32:58 +0900", "test/yukicoder/1950.test.cpp": "2020-10-27 12:32:58 +0900", "test/yukicoder/1973.test.cpp": "2020-12-19 16:21:21 +0900", "test/yukicoder/2063.test.cpp": "2020-10-27 18:05:43 +0900", "test/yukicoder/2085.test.cpp": "2020-10-27 16:29:49 +0900", "test/yukicoder/2113.test.cpp": "2020-10-27 12:32:58 +0900", "test/yukicoder/2125.test.cpp": "2020-10-27 12:52:35 +0900", "test/yukicoder/2147.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/2587.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/2600.test.cpp": "2020-12-10 16:27:42 +0900", "test/yukicoder/2744.test.cpp": "2020-11-22 16:21:33 +0900", "test/yukicoder/2772.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/3211.test.cpp": "2020-10-27 16:43:02 +0900", "test/yukicoder/3227.test.cpp": "2020-10-27 19:25:09 +0900", "test/yukicoder/3277.test.cpp": "2021-02-05 14:58:50 +0900", "test/yukicoder/3354.test.cpp": "2021-02-20 22:27:17 +0900", "test/yukicoder/3405.test.cpp": "2020-11-02 16:12:34 +0900", "test/yukicoder/3407.test.cpp": "2020-10-27 19:20:38 +0900", "test/yukicoder/3453.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/3592.test.cpp": "2020-10-27 19:25:22 +0900", "test/yukicoder/3912.test.cpp": "2020-10-27 19:19:20 +0900", "test/yukicoder/3961.test.cpp": "2020-10-27 19:19:20 +0900", "test/yukicoder/4072.test.cpp": "2020-10-27 19:24:22 +0900", "test/yukicoder/4117.test.cpp": "2021-02-20 22:50:07 +0900", "test/yukicoder/4271.avx2.test.cpp": "2020-11-14 15:21:58 +0900", "test/yukicoder/4271.test.cpp": "2020-10-27 16:42:52 +0900", "test/yukicoder/4387.test.cpp": "2020-10-27 18:02:44 +0900", "test/yukicoder/4474.test.cpp": "2020-11-13 17:54:21 +0900", "test/yukicoder/4569.test.cpp": "2020-10-27 16:29:08 +0900", "test/yukicoder/4706.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/4778.test.cpp": "2020-11-15 18:14:06 +0900", "test/yukicoder/4852.test.cpp": "2020-10-27 19:20:38 +0900", "test/yukicoder/4862.test.cpp": "2020-10-27 18:58:51 +0900", "test/yukicoder/4872.test.cpp": "2020-11-15 15:34:02 +0900", "test/yukicoder/4918.test.cpp": "2020-10-27 12:28:47 +0900", "test/yukicoder/4941.test.cpp": "2020-10-07 14:35:46 +0900", "test/yukicoder/5011.test.cpp": "2020-10-27 13:13:32 +0900", "test/yukicoder/5025.test.cpp": "2020-12-16 13:02:24 +0900", "test/yukicoder/5223.test.cpp": "2020-10-27 16:18:54 +0900", "test/yukicoder/5633.test.cpp": "2020-12-29 15:19:06 +0900" } ================================================ FILE: .verify-helper/timestamps.remote.json ================================================ { "test/aoj/0109.test.cpp": "2021-09-10 23:35:46 +0900", "test/aoj/0168.test.cpp": "2020-12-20 13:43:34 +0900", "test/aoj/0233.test.cpp": "2020-09-25 12:37:15 +0900", "test/aoj/0294.test.cpp": "2020-09-25 12:37:15 +0900", "test/aoj/0314.test.cpp": "2021-09-23 21:21:39 +0900", "test/aoj/0343.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/0367.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/0367.test.cpp": "2021-02-05 14:59:47 +0900", "test/aoj/0367.toptree.test.cpp": "2021-09-25 22:06:41 +0900", "test/aoj/0377.test.cpp": "2020-10-27 16:01:15 +0900", "test/aoj/0391.test.cpp": "2020-11-02 16:40:04 +0900", "test/aoj/0402.test.cpp": "2021-09-23 20:26:31 +0900", "test/aoj/0403.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/0415.test.cpp": "2020-10-27 16:01:15 +0900", "test/aoj/0422.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/0423.test.cpp": "2020-09-25 13:46:01 +0900", "test/aoj/0424.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/0425.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/0437.test.cpp": "2020-11-04 18:35:12 +0900", "test/aoj/0438.test.cpp": "2020-11-04 18:35:12 +0900", "test/aoj/0439.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/0502.test.cpp": "2020-10-25 17:34:17 +0900", "test/aoj/0558.test.cpp": "2020-09-30 16:50:39 +0900", "test/aoj/0563.test.cpp": "2020-09-25 12:37:15 +0900", "test/aoj/0596.test.cpp": "2020-10-27 16:52:37 +0900", "test/aoj/0613.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/1069.test.cpp": "2020-05-07 21:38:10 +0900", "test/aoj/1197.test.cpp": "2020-11-15 18:54:23 +0900", "test/aoj/1254.test.cpp": "2020-10-26 14:50:55 +0900", "test/aoj/1293.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/1300.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/1308.test.cpp": "2020-10-27 16:01:15 +0900", "test/aoj/1312.test.cpp": "2020-10-27 19:04:41 +0900", "test/aoj/1328.test.cpp": "2021-09-23 21:21:39 +0900", "test/aoj/1338.test.cpp": "2021-05-23 16:26:48 +0900", "test/aoj/1508.test.cpp": "2020-11-04 18:35:12 +0900", "test/aoj/1549.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/1579.test.cpp": "2020-11-04 18:35:12 +0900", "test/aoj/1595.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/1595.test.cpp": "2020-10-27 16:41:24 +0900", "test/aoj/1595.toptree.test.cpp": "2021-09-25 22:06:41 +0900", "test/aoj/1599.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/1607.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/1613.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/1615.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/1630.test.cpp": "2021-03-25 10:42:25 +0900", "test/aoj/1642.test.cpp": "2020-11-19 17:00:02 +0900", "test/aoj/2060.test.cpp": "2021-09-23 21:21:39 +0900", "test/aoj/2187.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/2212.test.cpp": "2021-01-22 18:37:50 +0900", "test/aoj/2222.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2230.test.cpp": "2020-10-27 16:41:24 +0900", "test/aoj/2235.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2257.test.cpp": "2021-01-22 18:37:50 +0900", "test/aoj/2270.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/2286.test.cpp": "2020-10-27 16:41:24 +0900", "test/aoj/2290.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/2292.test.cpp": "2020-10-27 19:04:41 +0900", "test/aoj/2294.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/2308.test.cpp": "2020-10-27 15:50:08 +0900", "test/aoj/2309.tarjan.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2309.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2313.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2324.test.cpp": "2020-10-27 16:01:15 +0900", "test/aoj/2328.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2359.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/2370.test.cpp": "2021-07-23 12:56:32 +0900", "test/aoj/2397.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2405.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2415.knuthyao.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/2415.test.cpp": "2020-10-27 13:13:52 +0900", "test/aoj/2444.test.cpp": "2020-10-27 19:04:41 +0900", "test/aoj/2446.test.cpp": "2021-09-23 20:26:31 +0900", "test/aoj/2450.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/2450.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/2488.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/2513.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/2560.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2563.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/2603.test.cpp": "2021-03-05 12:19:04 +0900", "test/aoj/2624.test.cpp": "2020-10-27 16:01:15 +0900", "test/aoj/2627.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2636.test.cpp": "2021-09-25 22:06:41 +0900", "test/aoj/2644.test.cpp": "2023-03-20 15:38:36 +0900", "test/aoj/2646.test.cpp": "2020-10-27 14:01:51 +0900", "test/aoj/2647.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2659.test.cpp": "2021-06-20 16:57:30 +0900", "test/aoj/2667.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/2674.count.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2674.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/2679.test.cpp": "2020-10-06 13:10:17 +0900", "test/aoj/2687.test.cpp": "2021-03-11 20:23:56 +0900", "test/aoj/2711.test.cpp": "2023-03-20 16:01:48 +0900", "test/aoj/2720.test.cpp": "2020-10-24 13:53:02 +0900", "test/aoj/2725.linecontainer.test.cpp": "2021-11-21 11:20:30 +0900", "test/aoj/2725.test.cpp": "2021-10-17 17:32:37 +0900", "test/aoj/2736.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/2790.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/2842.BIT2D.test.cpp": "2020-10-27 13:13:52 +0900", "test/aoj/2842.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2871.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/2872.test.cpp": "2020-10-27 16:41:24 +0900", "test/aoj/2890.test.cpp": "2020-11-04 18:35:12 +0900", "test/aoj/2891.test.cpp": "2021-01-03 18:39:08 +0900", "test/aoj/2934.test.cpp": "2020-10-27 13:26:46 +0900", "test/aoj/2948.test.cpp": "2020-10-27 15:54:11 +0900", "test/aoj/2951.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2959.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2968.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/2969.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/2970.test.cpp": "2021-06-20 16:57:30 +0900", "test/aoj/2971.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2975.test.cpp": "2021-10-17 17:32:37 +0900", "test/aoj/2977.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2979.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/2981.test.cpp": "2021-09-23 20:26:31 +0900", "test/aoj/2983.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2985.garner.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2985.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/2995.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/3024.test.cpp": "2020-10-27 13:26:46 +0900", "test/aoj/3033.test.cpp": "2023-03-20 15:38:36 +0900", "test/aoj/3035.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/3037.test.cpp": "2023-05-04 18:59:07 +0900", "test/aoj/3047.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/3053.test.cpp": "2020-09-25 13:59:55 +0900", "test/aoj/3058.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/3062.test.cpp": "2020-11-13 17:57:07 +0900", "test/aoj/3063.test.cpp": "2023-03-20 16:01:48 +0900", "test/aoj/3069.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/3072.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/3073.test.cpp": "2021-01-22 18:37:50 +0900", "test/aoj/3074.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/3081.test.cpp": "2021-03-04 17:00:41 +0900", "test/aoj/3084.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/3086.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/3102.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/3112.test.cpp": "2023-03-20 16:01:48 +0900", "test/aoj/3117.test.cpp": "2020-05-07 21:38:10 +0900", "test/aoj/3120.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/3138.test.cpp": "2020-10-25 17:34:17 +0900", "test/aoj/3142.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/3143.test.cpp": "2021-09-25 22:06:41 +0900", "test/aoj/3148.test.cpp": "2020-10-27 16:41:24 +0900", "test/aoj/3168.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/3179.test.cpp": "2021-09-25 22:06:41 +0900", "test/aoj/3183.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/3198.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/3208.test.cpp": "2020-10-30 12:18:04 +0900", "test/aoj/3213.test.cpp": "2020-12-20 13:43:34 +0900", "test/aoj/3506.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/3518.test.cpp": "2022-08-28 21:28:57 +0900", "test/aoj/ALDS1_10_C.test.cpp": "2020-12-21 13:22:00 +0900", "test/aoj/ALDS1_14_B.knuthmorrispratt.test.cpp": "2020-10-27 13:26:46 +0900", "test/aoj/ALDS1_14_B.test.cpp": "2020-10-27 19:04:41 +0900", "test/aoj/ALDS1_14_C.test.cpp": "2020-10-27 19:04:41 +0900", "test/aoj/ALDS1_15_B.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/ALDS1_1_C.test.cpp": "2020-09-25 14:33:00 +0900", "test/aoj/ALDS1_5_D.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/ALDS1_9_C.test.cpp": "2020-10-27 13:13:52 +0900", "test/aoj/DPL_1_E.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/DPL_3_B.test.cpp": "2020-10-27 12:43:10 +0900", "test/aoj/DPL_3_C.test.cpp": "2020-10-27 12:43:10 +0900", "test/aoj/DPL_5_A.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_B.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_C.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_D.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_E.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_F.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_G.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_H.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_I.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_J.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_K.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DPL_5_L.test.cpp": "2021-03-25 09:46:10 +0900", "test/aoj/DSL_1_A.quickfind.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/DSL_1_A.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/DSL_1_B.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/DSL_2_B.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/DSL_2_C.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/DSL_2_D.test.cpp": "2020-09-25 14:47:24 +0900", "test/aoj/DSL_2_E.test.cpp": "2020-09-25 14:47:24 +0900", "test/aoj/DSL_2_F.bbst.test.cpp": "2020-11-28 18:14:40 +0900", "test/aoj/DSL_2_F.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/DSL_2_G.bbst.test.cpp": "2020-11-28 18:14:40 +0900", "test/aoj/DSL_2_H.bbst.test.cpp": "2020-11-28 18:14:40 +0900", "test/aoj/DSL_2_H.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/DSL_2_I.bbst.test.cpp": "2020-11-28 18:14:40 +0900", "test/aoj/DSL_2_I.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/DSL_3_D.cartesiantree.test.cpp": "2020-10-27 16:52:37 +0900", "test/aoj/DSL_3_D.disjointsparsetable.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/DSL_3_D.slidingwindowaggregation.test.cpp": "2020-09-25 15:01:13 +0900", "test/aoj/DSL_3_D.sparsetable.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/DSL_3_D.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/GRL_1_A.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/GRL_1_B.test.cpp": "2020-10-27 16:01:15 +0900", "test/aoj/GRL_2_A.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/GRL_2_B.tarjan.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/GRL_2_B.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/GRL_3_A.test.cpp": "2020-10-27 15:54:11 +0900", "test/aoj/GRL_3_B.test.cpp": "2020-10-27 15:54:11 +0900", "test/aoj/GRL_5_A.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/GRL_5_A.test.cpp": "2020-09-25 15:10:41 +0900", "test/aoj/GRL_5_C.lca.test.cpp": "2020-09-25 15:10:41 +0900", "test/aoj/GRL_5_C.test.cpp": "2020-10-27 19:32:25 +0900", "test/aoj/GRL_5_D.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/GRL_5_D.test.cpp": "2021-05-01 12:56:38 +0900", "test/aoj/GRL_5_E.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/aoj/GRL_6_A.test.cpp": "2020-10-27 18:08:33 +0900", "test/aoj/GRL_6_B.test.cpp": "2020-10-06 13:10:17 +0900", "test/aoj/GRL_7_A.test.cpp": "2020-10-27 16:27:26 +0900", "test/aoj/ITP1_11_A.test.cpp": "2020-10-25 17:34:17 +0900", "test/aoj/ITP1_11_B.test.cpp": "2020-10-25 17:34:17 +0900", "test/aoj/ITP1_11_C.test.cpp": "2020-10-25 17:34:17 +0900", "test/aoj/ITP1_11_D.test.cpp": "2020-10-25 17:34:17 +0900", "test/aoj/NTL_1_A.test.cpp": "2020-09-25 15:10:41 +0900", "test/aoj/NTL_1_B.test.cpp": "2020-11-13 17:57:07 +0900", "test/aoj/NTL_1_D.test.cpp": "2020-10-24 12:57:36 +0900", "test/aoj/NTL_1_E.test.cpp": "2021-06-20 16:57:30 +0900", "test/aoj/NTL_2_A.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/NTL_2_B.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/NTL_2_C.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/NTL_2_D.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/NTL_2_E.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/NTL_2_F.test.cpp": "2021-03-25 09:40:53 +0900", "test/aoj/geometry/2334.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/geometry/2448.test.cpp": "2020-10-27 12:55:52 +0900", "test/aoj/geometry/2454.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/3049.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/geometry/3056.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/geometry/CGL_1_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_1_B.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_1_C.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_2_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_2_B.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_2_C.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_2_D.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/geometry/CGL_3_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_3_B.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_3_C.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_4_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_4_B.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_4_C.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_5_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_6_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_7_A.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_7_D.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_7_E.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_7_F.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_7_G.test.cpp": "2020-10-26 15:08:18 +0900", "test/aoj/geometry/CGL_7_H.test.cpp": "2020-10-27 12:29:50 +0900", "test/aoj/geometry/CGL_7_I.test.cpp": "2020-10-27 12:29:50 +0900", "test/yosupo/assignment.test.cpp": "2020-10-27 16:41:24 +0900", "test/yosupo/associative_array.test.cpp": "2020-10-27 12:29:50 +0900", "test/yosupo/bernoulli_number.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/bipartitematching.test.cpp": "2020-10-27 16:27:26 +0900", "test/yosupo/bitwise_and_convolution.test.cpp": "2021-09-23 20:26:31 +0900", "test/yosupo/bitwise_xor_convolution.test.cpp": "2021-09-23 20:26:31 +0900", "test/yosupo/cartesian_tree.test.cpp": "2020-10-27 16:52:37 +0900", "test/yosupo/convolution_mod.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/convolution_mod_1000000007.garner.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/convolution_mod_1000000007.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/cycle_detection.test.cpp": "2021-01-03 18:39:08 +0900", "test/yosupo/discrete_logarithm_mod.test.cpp": "2020-11-13 17:57:07 +0900", "test/yosupo/dominatortree.test.cpp": "2020-09-25 15:33:26 +0900", "test/yosupo/dynamic_sequence_range_affine_range_sum.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/dynamic_tree_vertex_add_path_sum.test.cpp": "2021-03-25 09:21:12 +0900", "test/yosupo/dynamic_tree_vertex_add_subtree_sum.test.cpp": "2021-03-25 09:21:12 +0900", "test/yosupo/dynamic_tree_vertex_add_subtree_sum.toptree.test.cpp": "2021-09-25 22:06:41 +0900", "test/yosupo/dynamic_tree_vertex_set_path_composite.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/dynamic_tree_vertex_set_path_composite.toptree.test.cpp": "2023-05-04 18:59:07 +0900", "test/yosupo/enumerate_primes.test.cpp": "2020-10-07 11:59:04 +0900", "test/yosupo/enumerate_triangles.test.cpp": "2020-10-27 16:52:37 +0900", "test/yosupo/exp_of_formal_power_series.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/find_linear_recurrence.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/frequency_table_of_tree_distance.test.cpp": "2020-10-27 19:32:25 +0900", "test/yosupo/inv_of_formal_power_series.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/kth_root_integer.test.cpp": "2020-09-25 18:28:59 +0900", "test/yosupo/kth_term_of_linearly_recurrent_sequence.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/lca.linkcuttree.test.cpp": "2021-03-25 09:21:12 +0900", "test/yosupo/lca.test.cpp": "2020-10-27 19:32:25 +0900", "test/yosupo/line_add_get_min.test.cpp": "2020-11-22 19:37:49 +0900", "test/yosupo/log_of_formal_power_series.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/manhattanmst.test.cpp": "2020-10-27 19:32:25 +0900", "test/yosupo/many_aplusb.test.cpp": "2020-10-27 12:29:50 +0900", "test/yosupo/matrix_det.test.cpp": "2021-09-23 21:21:39 +0900", "test/yosupo/maximum_independent_set.test.cpp": "2020-10-27 15:54:11 +0900", "test/yosupo/min_cost_b_flow.test.cpp": "2020-10-27 16:41:24 +0900", "test/yosupo/montmort_number_mod.test.cpp": "2020-11-13 17:57:07 +0900", "test/yosupo/multipoint_evaluation.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/number_of_substrings.test.cpp": "2023-03-20 16:01:48 +0900", "test/yosupo/partition_function.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/persistent_queue.test.cpp": "2020-11-04 18:35:12 +0900", "test/yosupo/point_add_range_sum.test.cpp": "2021-05-01 12:56:38 +0900", "test/yosupo/point_add_rectangle_sum.test.cpp": "2021-05-01 12:56:38 +0900", "test/yosupo/point_set_range_composite.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/polynomial_interpolation.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/polynomial_taylor_shift.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/pow_of_formal_power_series.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/queue_operate_all_composite.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/range_affine_range_sum.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/range_kth_smallest.test.cpp": "2020-10-27 12:55:52 +0900", "test/yosupo/rectangle_sum.test.cpp": "2021-05-01 12:56:38 +0900", "test/yosupo/runenumerate.test.cpp": "2021-03-04 17:00:41 +0900", "test/yosupo/scc.test.cpp": "2020-10-27 18:08:33 +0900", "test/yosupo/segment_add_get_min.test.cpp": "2020-11-22 19:37:49 +0900", "test/yosupo/set_xor_min.test.cpp": "2020-10-27 12:55:52 +0900", "test/yosupo/sharp_p_subset_sum.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/shortest_path.test.cpp": "2020-09-25 18:28:59 +0900", "test/yosupo/sort_points_by_argument.test.cpp": "2020-10-27 16:41:24 +0900", "test/yosupo/sqrt_mod.test.cpp": "2020-11-13 20:22:13 +0900", "test/yosupo/sqrt_of_formal_power_series.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/static_range_frequency.test.cpp": "2021-10-27 00:41:51 +0900", "test/yosupo/static_range_inversions_query.test.cpp": "2021-05-01 12:56:38 +0900", "test/yosupo/static_range_sum.test.cpp": "2020-09-25 16:01:41 +0900", "test/yosupo/staticrmq.disjointsparsetable.test.cpp": "2020-10-27 19:32:25 +0900", "test/yosupo/staticrmq.sparsetable.test.cpp": "2020-10-27 19:32:25 +0900", "test/yosupo/stirling_number_of_the_first_kind.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/stirling_number_of_the_second_kind.test.cpp": "2021-03-25 09:46:10 +0900", "test/yosupo/subset_convolution.test.cpp": "2021-09-23 20:26:31 +0900", "test/yosupo/suffixarray.test.cpp": "2023-03-20 15:38:36 +0900", "test/yosupo/sum_of_floor_of_linear.test.cpp": "2020-09-25 16:01:41 +0900", "test/yosupo/tetration_mod.test.cpp": "2020-11-13 17:57:07 +0900", "test/yosupo/tree_decomposition_width_2.test.cpp": "2020-10-27 16:01:15 +0900", "test/yosupo/tree_diameter.test.cpp": "2020-10-27 12:55:52 +0900", "test/yosupo/two_edge_connected_components.test.cpp": "2020-10-27 16:01:15 +0900", "test/yosupo/two_sat.test.cpp": "2020-10-27 18:08:33 +0900", "test/yosupo/unionfind.test.cpp": "2020-10-27 19:32:25 +0900", "test/yosupo/vertex_add_path_sum.test.cpp": "2021-05-01 12:56:38 +0900", "test/yosupo/vertex_add_subtree_sum.test.cpp": "2021-05-01 12:56:38 +0900", "test/yosupo/zalgorithm.test.cpp": "2021-03-04 17:00:41 +0900", "test/yukicoder/0022.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/0104.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/0143.test.cpp": "2021-03-25 09:40:53 +0900", "test/yukicoder/0206.test.cpp": "2021-06-20 18:05:51 +0900", "test/yukicoder/0222.test.cpp": "2020-09-30 16:50:39 +0900", "test/yukicoder/0399.test.cpp": "2020-10-27 19:04:41 +0900", "test/yukicoder/0444.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/0472.test.cpp": "2020-11-13 17:57:07 +0900", "test/yukicoder/0771.test.cpp": "2021-10-17 17:43:57 +0900", "test/yukicoder/0831.test.cpp": "2021-03-25 09:40:53 +0900", "test/yukicoder/1013.test.cpp": "2021-01-22 18:37:50 +0900", "test/yukicoder/1504.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/1580.test.cpp": "2020-09-25 16:15:28 +0900", "test/yukicoder/1665.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/1732.test.cpp": "2021-05-01 12:56:38 +0900", "test/yukicoder/1923.test.cpp": "2020-10-27 12:55:52 +0900", "test/yukicoder/1937.test.cpp": "2020-10-27 12:55:52 +0900", "test/yukicoder/1948.test.cpp": "2020-10-27 12:43:10 +0900", "test/yukicoder/1950.test.cpp": "2020-10-27 12:43:10 +0900", "test/yukicoder/1973.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/2063.test.cpp": "2020-10-27 18:08:33 +0900", "test/yukicoder/2085.test.cpp": "2020-10-27 16:41:24 +0900", "test/yukicoder/2113.test.cpp": "2020-10-27 12:43:10 +0900", "test/yukicoder/2125.test.cpp": "2021-05-01 12:56:38 +0900", "test/yukicoder/2147.test.cpp": "2020-10-27 12:55:52 +0900", "test/yukicoder/2520.test.cpp": "2021-08-08 16:43:28 +0900", "test/yukicoder/2587.test.cpp": "2021-09-25 22:06:41 +0900", "test/yukicoder/2600.test.cpp": "2020-12-10 16:40:15 +0900", "test/yukicoder/2744.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/2772.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/3211.test.cpp": "2021-07-24 22:40:18 +0900", "test/yukicoder/3227.test.cpp": "2020-10-27 12:55:52 +0900", "test/yukicoder/3267.test.cpp": "2021-11-21 12:07:31 +0900", "test/yukicoder/3277.test.cpp": "2021-02-05 15:09:55 +0900", "test/yukicoder/3354.test.cpp": "2021-02-20 22:51:36 +0900", "test/yukicoder/3405.test.cpp": "2020-11-02 16:12:53 +0900", "test/yukicoder/3407.test.cpp": "2020-10-27 19:32:25 +0900", "test/yukicoder/3453.test.cpp": "2021-09-25 22:06:41 +0900", "test/yukicoder/3592.test.cpp": "2020-10-27 19:32:25 +0900", "test/yukicoder/3912.test.cpp": "2020-10-27 19:32:25 +0900", "test/yukicoder/3961.test.cpp": "2021-05-01 12:56:38 +0900", "test/yukicoder/4072.test.cpp": "2020-10-27 19:32:25 +0900", "test/yukicoder/4117.test.cpp": "2021-02-20 22:51:36 +0900", "test/yukicoder/4271.avx2.test.cpp": "2020-11-14 15:24:41 +0900", "test/yukicoder/4271.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/4387.test.cpp": "2020-10-27 18:08:33 +0900", "test/yukicoder/4474.test.cpp": "2020-11-13 17:57:07 +0900", "test/yukicoder/4569.test.cpp": "2021-03-25 09:21:12 +0900", "test/yukicoder/4706.test.cpp": "2021-09-25 22:06:41 +0900", "test/yukicoder/4778.test.cpp": "2021-05-01 12:56:38 +0900", "test/yukicoder/4852.test.cpp": "2021-05-01 12:56:38 +0900", "test/yukicoder/4862.test.cpp": "2021-09-25 22:06:41 +0900", "test/yukicoder/4872.test.cpp": "2020-11-15 16:01:34 +0900", "test/yukicoder/4918.test.cpp": "2020-10-27 12:29:50 +0900", "test/yukicoder/4941.test.cpp": "2021-05-23 16:26:48 +0900", "test/yukicoder/5011.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/5025.test.cpp": "2021-09-23 20:26:31 +0900", "test/yukicoder/5061.test.cpp": "2021-09-05 12:24:05 +0900", "test/yukicoder/5223.test.cpp": "2021-05-01 12:56:38 +0900", "test/yukicoder/5633.test.cpp": "2021-03-25 09:46:10 +0900", "test/yukicoder/6680.test.cpp": "2021-08-06 23:06:43 +0900", "test/yukicoder/7107.test.cpp": "2021-11-21 12:07:31 +0900", "test/yukicoder/9158.test.cpp": "2023-05-05 23:39:01 +0900" } ================================================ FILE: README.md ================================================ # library [![Actions Status](https://github.com/beet-aizu/library/workflows/verify/badge.svg)](https://github.com/beet-aizu/library/actions) [![GitHub Pages](https://img.shields.io/static/v1?label=GitHub+Pages&message=+&color=brightgreen&logo=github)](https://beet-aizu.github.io/library/) うぃーんビートビートひるどwwwwwwうっくっくwwwwwwえいえいえt(←いずらいt)いえいwwwwらて。 ================================================ FILE: algorithm/knuthyao.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // f(i,l) + f(j,k) >= f(i,k) + f(j,l) (i <= j, k <= l) template T KnuthYao(int n,F cost){ vector< vector > dp(n,vector(n)); vector< vector > ar(n,vector(n)); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template T largestrectangle(vector &v){ int n=v.size(); T res=0; using P = pair; stack

sp; sp.emplace(-1,T(0)); for(int i=0;iv[i]){ j=sp.top().first; res=max(res,(i-j)*sp.top().second); sp.pop(); } if(sp.top().second using namespace std; #endif //BEGIN CUT HERE struct Mo{ using F = function; vector ls,rs,ord; int n,width,nl,nr,ptr; F expandL,expandR; F shrinkL,shrinkR; Mo(int n,int width,F expandL,F expandR,F shrinkL,F shrinkR): n(n),width(width),nl(0),nr(0),ptr(0), expandL(expandL),expandR(expandR), shrinkL(shrinkL),shrinkR(shrinkR){} Mo(int n,int width,F expand,F shrink): Mo(n,width,expand,expand,shrink,shrink){} void add(int l,int r){ ls.emplace_back(l); rs.emplace_back(r); } void build(){ ord.resize(ls.size()); iota(ord.begin(),ord.end(),0); sort(ord.begin(),ord.end(), [&](int a,int b){ if(ls[a]/width!=ls[b]/width) return ls[a]ls[idx]) expandL(--nl); while(nrrs[idx]) shrinkR(--nr); return idx; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: algorithm/monotoneminima.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE namespace MonotoneMinima{ template void induce(int l,int r,int a,int b,vector &dp,F dist){ if(l==r) return; int m=(l+r)>>1; int &idx=(dp[m]=a); T res=dist(m,idx); for(int i=a;i(l,m,a,idx+1,dp,dist); induce(m+1,r,idx,b,dp,dist); } // p < q -> argmin f(p, *) <= argmin f(q, *) template vector args(int n,int m,F dist){ vector dp(n,-1); induce(0,n,0,m,dp,dist); return dp; } } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: algorithm/offlineonline.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif // https://qiita.com/tmaehara/items/0687af2cfb807cde7860 //BEGIN CUT HERE namespace OfflineOnline{ vector used; template void update(vector &dp,int k,T val){ if(!used[k]) dp[k]=val; dp[k]=min(dp[k],val); used[k]=1; } // [l, r), [a, b] template void induce(int l,int r,int a,int b,vector &dp,F dist){ if(l==r) return; int m=(l+r)>>1; assert(m void solve(int l,int r,vector &dp,F dist){ if(l+1==r) return update(dp,l,dist(l,r)+dp[r]); int m=(l+r)>>1; solve(m,r,dp,dist); induce(l,m,m,r,dp,dist); solve(l,m,dp,dist); } // dp[i] = min_{i T solve(int n,F dist){ vector dp(n+1,0); used.assign(n+1,0); used[n]=1; solve(0,n,dp,dist); return dp[0]; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: algorithm/optimalbinarytree.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../datastructure/skewheap.cpp" #undef call_from_test #endif //BEGIN CUT HERE template T optimalbinarytree(vector ws){ const T INF = numeric_limits::max()/2; using Heap=SkewHeap; auto g=[](T a,T b){return a+b;}; auto c=[](T a,T b){return a>b;}; Heap heap(g,g,c,INF,0); int n=ws.size(); vector hs(n-1,nullptr); vector ls(n),rs(n); vector cs(n-1); using P = pair; priority_queue,greater

> pq; for(int i=0;i0){ int j=ls[i]; hs[j]=heap.meld(hs[j],hs[i]); rs[j]=rs[i]; rs[i]=-1; ls[rs[j]]=j; i=j; } if(mr and rs[i]+1 using namespace std; #endif //BEGIN CUT HERE // n questions, q operations vector parallel_binary_search(int n,int q, function init, function apply, function check){ vector< vector > C(q); vector L(n,-1),R(n,q); bool flg=1; while(flg){ flg=0; init(); for(int i=0;i>1].emplace_back(i); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE // O(n sqrt(n) / w) // w: wordsize template bitset partial_sum(vector vs){ int sum=0; for(int v:vs) sum+=v; assert(sum<=N); vector cnt(sum+1,0); for(int v:vs) cnt[v]++; for(int i=1;i*2<=sum;i++){ int num=(cnt[i]-1)/2; cnt[i]-=num*2; cnt[i*2]+=num; } bitset dp; dp[0]=1; for(int i=1;i<=sum;i++) for(int t=0;t using namespace std; #endif //BEGIN CUT HERE #include #include #include using namespace __gnu_pbds; template using gtree = tree, rb_tree_tag, tree_order_statistics_node_update>; // usage: // find_by_order(int k): // return the iterator of k-th smallest element (0-indexed) // order_of_key(T key): return the index of key in tree //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: bbst/rbst/data/array.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Array{ struct Node{ Node *l,*r,*p; size_t cnt; bool rev; T val; Node(T val): cnt(1),rev(0),val(val){l=r=p=nullptr;} }; static inline size_t count(const Node *t){ return t?t->cnt:0; } inline void toggle(Node *t){ swap(t->l,t->r); t->rev^=1; } inline bool dirty(Node *t){ return t->rev; } inline Node* eval(Node* t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } return t; } inline Node* pushup(Node *t){ t->cnt=count(t->l)+1+count(t->r); return t; } inline T get_val(Node *t){ assert(t); return t->val; } void dump(typename vector::iterator it,Node* const t,bool rev){ if(!count(t)) return; Node *l=t->l,*r=t->r; if(rev) swap(l,r); rev^=t->rev; dump(it,l,rev); *(it+count(l))=Node(t->val); dump(it+count(l)+1,r,rev); } vector dump(Node* t){ assert(t!=nullptr); vector vs(count(t),*t); dump(vs.begin(),t,false); return vs; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: bbst/rbst/data/dual.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Dual{ struct Node{ Node *l,*r,*p; size_t cnt; bool rev; E val,laz; Node(E val): cnt(1),rev(0),val(val),laz(val){l=r=p=nullptr;} }; H h; E ei; Dual(H h,E ei):h(h),ei(ei){} static inline size_t count(const Node *t){ return t?t->cnt:0; } inline void toggle(Node *t){ swap(t->l,t->r); t->rev^=1; } inline void propagate(Node *t,E x){ t->val=h(t->val,x); t->laz=h(t->laz,x); } inline bool dirty(Node *t){ return t->rev or t->laz!=ei; } inline Node* eval(Node* t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } if(t->laz!=ei){ if(t->l) propagate(t->l,t->laz); if(t->r) propagate(t->r,t->laz); t->laz=ei; } return t; } inline Node* pushup(Node *t){ t->cnt=count(t->l)+1+count(t->r); return t; } inline E get_val(Node *t){ assert(t); return t->val; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: bbst/rbst/data/lazy.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Lazy{ F f; G g; H h; Flip flip; T ti; E ei; Lazy(F f,G g,H h,Flip flip,T ti,E ei): f(f),g(g),h(h),flip(flip),ti(ti),ei(ei){} struct Node{ Node *l,*r,*p; size_t cnt; bool rev; T val,dat; E laz; Node(T val,E laz): cnt(1),rev(0),val(val),dat(val),laz(laz){l=r=p=nullptr;} }; static inline size_t count(const Node *t){ return t?t->cnt:0; } inline void toggle(Node *t){ swap(t->l,t->r); t->val=flip(t->val); t->dat=flip(t->dat); t->rev^=1; } inline bool dirty(Node *t){ return t->rev or t->laz!=ei; } inline void propagate(Node *t,E v){ t->laz=h(t->laz,v); t->val=g(t->val,v); t->dat=g(t->dat,v); } inline Node* eval(Node* t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } if(t->laz!=ei){ if(t->l) propagate(t->l,t->laz); if(t->r) propagate(t->r,t->laz); t->laz=ei; } return t; } inline Node* pushup(Node *t){ t->cnt=count(t->l)+1+count(t->r); t->dat=t->val; if(t->l) t->dat=f(t->l->dat,t->dat); if(t->r) t->dat=f(t->dat,t->r->dat); return t; } inline T get_val(Node *t){ assert(t); return t->val; } inline T reflect(Node *t){ assert(t); return t->dat; } void dump(typename vector::iterator it, const Node* t,bool rev,E laz){ if(!count(t)) return; Node *l=t->l,*r=t->r; if(rev) swap(l,r); rev^=t->rev; dump(it,l,rev,h(laz,t->laz)); *(it+count(l))=Node(g(t->val,laz),ei); dump(it+count(l)+1,r,rev,h(laz,t->laz)); } vector dump(Node* t){ assert(t!=nullptr); vector vs(count(t),*t); dump(vs.begin(),t,false,ei); return vs; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: bbst/rbst/data/ushi.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Ushi{ F f; Flip flip; T ti; Ushi(F f,Flip flip,T ti):f(f),flip(flip),ti(ti){} struct Node{ Node *l,*r,*p; size_t cnt; bool rev; T val,dat; Node(T val): cnt(1),rev(0),val(val),dat(val){l=r=p=nullptr;} }; static inline size_t count(const Node *t){ return t?t->cnt:0; } inline void toggle(Node *t){ swap(t->l,t->r); t->val=flip(t->val); t->dat=flip(t->dat); t->rev^=1; } inline bool dirty(Node *t){ return t->rev; } inline Node* eval(Node* t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } return t; } inline Node* pushup(Node *t){ t->cnt=count(t->l)+1+count(t->r); t->dat=t->val; if(t->l) t->dat=f(t->l->dat,t->dat); if(t->r) t->dat=f(t->dat,t->r->dat); return t; } inline T get_val(Node *t){ assert(t); return t->val; } inline T reflect(Node *t){ assert(t); return t->dat; } void dump(typename vector::iterator it,Node* const t,bool rev){ if(!count(t)) return; Node *l=t->l,*r=t->r; if(rev) swap(l,r); rev^=t->rev; dump(it,l,rev); *(it+count(l))=Node(t->val); dump(it+count(l)+1,r,rev); } vector dump(Node* t){ assert(t!=nullptr); vector vs(count(t),*t); dump(vs.begin(),t,false); return vs; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: bbst/rbst/impl/basic.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../rbst.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Basic : RBST, Data, typename Data::Node, LIM>{ using super = RBST; using Node = typename Data::Node; Data data; template Basic(Args... args):data(forward(args)...){} inline Node* touch(Node *t){return data.eval(t);} using super::toggle; inline void toggle(Node *t){return data.toggle(t);} template inline void propagate(Node *t,E x){return data.propagate(t,x);} inline Node* pushup(Node *t){return data.pushup(t);} inline decltype(auto) get_val(Node *a,size_t k){ return data.get_val(super::get_val(a,k)); } using super::query; inline decltype(auto) query(Node *a){ return data.reflect(a); } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: bbst/rbst/impl/persistent.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../rbst.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Persistent : RBST, Data, typename Data::Node, LIM>{ using super = RBST; using Node = typename Data::Node; Data data; template Persistent(Args... args):data(forward(args)...){} inline Node* clone(Node *t){ if(t==nullptr) return t; return super::create(*t); } inline Node* touch(Node *t){ if(t==nullptr) return t; t=clone(t); if(data.dirty(t)){ t->l=clone(t->l); t->r=clone(t->r); } return data.eval(t); } using super::toggle; inline void toggle(Node *t){return data.toggle(t);} template inline void propagate(Node *t,E x){return data.propagate(t,x);} inline Node* pushup(Node *t){return data.pushup(t);} inline decltype(auto) get_val(Node *a,size_t k){ return data.get_val(super::get_val(a,k)); } using super::merge, super::split; decltype(auto) query(Node *a,size_t l,size_t r){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=t.first; return data.reflect(u); } bool almost_full() const{ return super::size+1000>LIM; } Node* rebuild(Node* a){ auto vs=data.dump(a); super::size=0; return super::build(vs); } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "../data/array.cpp" #undef call_from_test signed JOISC2012_COPYPASTE(){ cin.tie(0); ios::sync_with_stdio(0); int m; string buf; cin>>m>>buf; using Data = Array; using Node = Data::Node; const size_t LIM = 1e7; Persistent pa; vector vs(buf.begin(),buf.end()); auto rt=pa.build(vs); int n; cin>>n; for(int i=0;i>a>>b>>c; auto s=pa.split(rt,a); auto t=pa.split(s.second,b-a); auto u=pa.split(rt,c); rt=pa.merge(pa.merge(u.first,t.first),u.second); if((int)pa.count(rt)>m) rt=pa.split(rt,m).first; if(pa.almost_full()) rt=pa.rebuild(rt); } auto ds=pa.data.dump(rt); buf.resize(ds.size()); for(int i=0;i<(int)ds.size();i++) buf[i]=ds[i].val; cout<>n>>q; using ll = long long; using P = pair; vector

vp(n,P(0,1)); for(int i=0;i>vp[i].first; auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[](P a,ll b){return P(a.first+b*a.second,a.second);}; auto h=[](ll a,ll b){return a+b;}; auto flip=[](P a){return a;}; using Data = Lazy; using Node = Data::Node; constexpr size_t LIM = 6e6; Persistent G(f,g,h,flip,P(0,0),0); vector vs; for(auto v:vp) vs.emplace_back(v,0); auto rt=G.build(vs); for(int i=0;i>t; if(t==1){ int a,b,v; cin>>a>>b>>v; a--; rt=G.update(rt,a,b,v); } if(t==2){ int a,b,c,d; cin>>a>>b>>c>>d; a--;c--; auto s=G.split(rt,a); auto t=G.split(s.second,b-a); auto u=G.split(rt,c); auto v=G.split(u.second,d-c); rt=G.merge(G.merge(s.first,v.first),t.second); } if(t==3){ int a,b; cin>>a>>b; a--; cout< using namespace std; #endif //BEGIN CUT HERE template struct RBST{ using u32 = uint32_t; u32 xor128(){ static u32 x = 123456789; static u32 y = 362436069; static u32 z = 521288629; static u32 w = 88675123; u32 t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } alignas(Node) static inline char pool[sizeof(Node)*LIM]; static inline Node* ptr = (Node*)pool; static inline size_t size; template inline Node* create(Args&&... args){ return new (ptr+size++) Node(std::forward(args)...); } inline size_t count(const Node *t){return Data::count(t);} inline Node* touch(Node *t){ return static_cast(this)->touch(t); } inline void toggle(Node *t){ return static_cast(this)->toggle(t); } inline Node* pushup(Node *t){ return static_cast(this)->pushup(t); } Node* toggle(Node *a,size_t l,size_t r){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=touch(t.first); toggle(u); return merge(s.first,merge(u,t.second)); } Node* merge(Node* a,Node* b){ if(a==nullptr) return b; if(b==nullptr) return a; if(xor128()%(count(a)+count(b))r=merge(a->r,b); a->r->p=a; return pushup(a); } b=touch(b); b->l=merge(a,b->l); b->l->p=b; return pushup(b); } pair split(Node* a,size_t k){ if(a==nullptr) return make_pair(a,a); a=touch(a); if(k<=count(a->l)){ if(a->l) a->l->p=nullptr; auto s=split(a->l,k); a->l=s.second; if(a->l) a->l->p=a; return make_pair(s.first,pushup(a)); } if(a->r) a->r->p=nullptr; auto s=split(a->r,k-(count(a->l)+1)); a->r=s.first; if(a->r) a->r->p=a; return make_pair(pushup(a),s.second); } Node* insert(Node *a,size_t k,Node v){ Node* b=create(v); auto s=split(a,k); return merge(merge(s.first,b),s.second); } Node* erase(Node *a,size_t k){ assert(kl); if(kl,k); if(k>num) return find_by_order(a->r,k-(num+1)); return a; } inline bool is_right(Node* a){ return a->p and a->p->r==a; } size_t order_of_key(Node* a){ size_t res=count(a->l); while(a){ if(is_right(a)) res+=count(a->p->l)+1; a=a->p; } return res; } Node* build(size_t l,size_t r,const vector &vs){ if(l+1==r) return create(vs[l]); size_t m=(l+r)>>1; return merge(build(l,m,vs),build(m,r,vs)); } Node* build(const vector &vs){ return build(0,vs.size(),vs); } template Node* set_val(Node *a,size_t k,T val){ assert(kl); if(kl=set_val(a->l,k,val); if(k>num) a->r=set_val(a->r,k-(num+1),val); if(k==num) a->val=val; return pushup(a); } Node* get_val(Node *a,size_t k){ assert(kl); if(kl,k); if(k>num) return get_val(a->r,k-(num+1)); return a; } template Node* update(Node *a,size_t l,size_t r,E v){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=touch(t.first); static_cast(this)->propagate(u,v); return merge(s.first,merge(u,t.second)); } decltype(auto) query(Node *&a,size_t l,size_t r){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=t.first; auto res=static_cast(this)->query(u); a=merge(s.first,merge(u,t.second)); return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: bflow/capacityscaling.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // O(m^2 \log m \log U) // U: maximum capacity enum Objective{ MINIMIZE = +1, MAXIMIZE = -1, }; template struct MinCostFlow{ template inline void chmin(T &x,T y){x=min(x,y);} struct Edge{ int src,dst; Flow flow,cap; Cost cost; int rev; Edge(int src,int dst,Flow cap,Cost cost,int rev): src(src),dst(dst),flow(0),cap(cap),cost(cost),rev(rev){} Flow residual_cap()const{return cap-flow;} }; struct EdgePtr{ int v,e; EdgePtr(int v,int e):v(v),e(e){} }; int n; vector> G; vector b; vector p; MinCostFlow(int n):n(n),G(n),b(n,0){} EdgePtr add_edge(int src,int dst,Flow lower,Flow upper,Cost cost){ int e=G[src].size(); int r=(src==dst?e+1:G[dst].size()); assert(lower<=upper); G[src].emplace_back(src,dst,+upper,+cost*objective,r); G[dst].emplace_back(dst,src,-lower,-cost*objective,e); return EdgePtr(src,e); } const Edge &get_edge(EdgePtr ep)const{return G[ep.v][ep.e];} void push(Edge &e,Flow amount){ e.flow+=amount; G[e.dst][e.rev].flow-=amount; } void add_supply(int v,Flow amount){b[v]+=amount;} void add_demand(int v,Flow amount){b[v]-=amount;} Cost residual_cost(const Edge &e){ return e.cost+p[e.src]-p[e.dst]; } vector excess_vs,deficit_vs; void saturate_negative(const Flow delta){ for(auto &es:G){ for(auto &e:es){ Flow cap=e.residual_cap(); cap-=cap%delta; if(cap<0 or residual_cost(e)<0){ push(e,cap); b[e.src]-=cap; b[e.dst]+=cap; } } } excess_vs.clear(); deficit_vs.clear(); for(int v=0;v0) excess_vs.emplace_back(v); if(b[v]<0) deficit_vs.emplace_back(v); } } const Cost unreachable = std::numeric_limits::max(); Cost farthest; vector dist; vector parent; struct P{ Cost first; int second; P(Cost first,int second):first(first),second(second){} bool operator<(const P o)const{return first>o.first;} }; priority_queue

pq; template void eliminate(vector &vs,Predicate predicate){ vs.erase(remove_if(begin(vs),end(vs),predicate),end(vs)); } bool dual(const Flow delta){ eliminate(excess_vs, [&](int v){return b[v]<+delta;}); eliminate(deficit_vs,[&](int v){return b[v]>-delta;}); dist.assign(n,unreachable); for(int v:excess_vs) pq.emplace(dist[v]=0,v); parent.assign(n,nullptr); auto emplace=[&](Edge& e){ if(e.residual_cap()=dist[e.dst]) return; pq.emplace(dist[e.dst]=nxt,e.dst); parent[e.dst]=&e; }; farthest=0; int deficit_count=0; while(!pq.empty()){ Cost d=pq.top().first; int v=pq.top().second; pq.pop(); if(dist[v]=(int)deficit_vs.size()) break; for(auto &e:G[v]) emplace(e); } pq=decltype(pq)(); for(int v=0;v0; } void primal(const Flow delta){ for(int t:deficit_vs){ if(dist[t]>farthest) continue; Flow f=-b[t]; int v; for(v=t;parent[v];v=parent[v]->src) chmin(f,parent[v]->residual_cap()); chmin(f,b[v]); f-=f%delta; if(f<=0) continue; for(v=t;parent[v];){ auto &e=*parent[v]; push(e,f); int u=parent[v]->src; if(e.residual_cap()<=0) parent[v]=nullptr; v=u; } b[t]+=f; b[v]-=f; } } template bool build(){ p.resize(n); Flow max_flow=1; for(auto t:b) max_flow=max({max_flow,t,-t}); for(auto &es:G) for(auto &e:es) max_flow=max({max_flow,e.residual_cap(),-e.residual_cap()}); Flow delta=1; while(delta T get_cost(){ T res=0; for(auto &es:G) for(auto &e:es) res+=T(e.flow)*T(e.cost)/T(objective); return res/T(2); } template T get_gain(){return get_cost();} vector get_potential(){ fill(p.begin(),p.end(),0); for(int i=0;i0) chmin(p[e.dst],p[e.src]+e.cost); return p; } }; template using MaxGainFlow = MinCostFlow; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: clean.sh ================================================ #!/bin/bash find . -name '*~' | xargs rm -v find . -name 'a.out' | grep -v verify-helper | xargs rm -v ================================================ FILE: combinatorics/bell.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "enumeration.cpp" #undef call_from_test #endif //BEGIN CUT HERE // put n distinct balls into at most k identical boxes template M bell(int n,int k){ if(n==0) return M(1); using E = Enumeration; k=min(k,n); E::init(k); vector dp(k+1); dp[0]=M(1); for(int i=1;i<=k;i++) dp[i]=dp[i-1]+((i&1)?-E::Finv(i):E::Finv(i)); M res(0); for(int i=1;i<=k;i++) res+=M(i).pow(n)*E::Finv(i)*dp[k-i]; return res; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: combinatorics/bernoulli.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "enumeration.cpp" #include "../formalpowerseries/base.cpp" #include "../formalpowerseries/inv.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Bernoulli : FormalPowerSeries{ using M = M_; using super = FormalPowerSeries; using Poly = typename super::Poly; using super::super, super::fact, super::finv; Poly rs; void build(int n){ super::init(n+2); rs.assign(n+1,M(1)); for(int i=1;i<=n;i++) rs[i]=finv[i+1]; rs=super::inv(rs,n+1); for(int i=1;i<=n;i++) rs[i]*=fact[i]; } M operator[](int k)const{return rs[k];} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: combinatorics/enumeration.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template class Enumeration{ using M = M_; protected: inline static vector fact,finv,invs; public: static void init(int n){ n=min(n,M::mod-1); int m=fact.size(); if(n=m;i--) finv[i-1]=finv[i]*M(i); for(int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1]; } static M Fact(int n){ init(n); return fact[n]; } static M Finv(int n){ init(n); return finv[n]; } static M Invs(int n){ init(n); return invs[n]; } static M C(int n,int k){ if(n using namespace std; #define call_from_test #include "enumeration.cpp" #include "../formalpowerseries/base.cpp" #include "../formalpowerseries/inv.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Partition : FormalPowerSeries{ using M = M_; using super = FormalPowerSeries; using Poly = typename super::Poly; using super::super; Poly rs; void build(int n){ rs.resize(n+1); rs[0]=M(1); for(int k=1;k<=n;k++){ if(1LL*k*(3*k+1)/2<=n) rs[k*(3*k+1)/2]+=k%2?-M(1):M(1); if(1LL*k*(3*k-1)/2<=n) rs[k*(3*k-1)/2]+=k%2?-M(1):M(1); } rs=super::inv(rs,n+1); } M operator[](int k)const{return rs[k];} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: combinatorics/partitiontable.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct PartitionTable{ vector< vector > dp; PartitionTable(int h,int w):dp(h+1,vector(w+1,0)){ dp[0][0]=M(1); for(int i=0;i<=h;i++){ for(int j=1;j<=w;j++){ dp[i][j]=dp[i][j-1]; if(i-j>=0) dp[i][j]+=dp[i-j][j]; } } } // put n identical balls into k identical boxes M operator()(int n,int k){return dp[n][k];} // put n identical balls into some boxes M operator()(int n){return dp[n][n];} }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: combinatorics/stirling1st.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "enumeration.cpp" #include "../formalpowerseries/base.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Stirling1st : FormalPowerSeries{ using M = M_; using super = FormalPowerSeries; using Poly = typename super::Poly; using super::super, super::fact, super::finv, super::mul; Poly rs; void build(int n){ super::init(n+1); if(n==0){ rs={M(1)}; return; } int m=1; rs=Poly({M(0),M(1)}); for(int e=31-__builtin_clz(n)-1;e>=0;e--){ Poly as(m+1),bs(m+1); for(int i=0;i<=m;i++) as[i]=fact[i]*rs[i]; bs[m-0]=M(1); for(int i=1;i<=m;i++) bs[m-i]=bs[m-(i-1)]*-M(m); for(int i=0;i<=m;i++) bs[m-i]*=finv[i]; Poly cs=mul(as,bs); Poly ds(m+1); for(int i=0;i<=m;i++) ds[i]=finv[i]*cs[m+i]; rs=mul(rs,ds); m<<=1; if((n>>e)&1){ Poly ts(m+1+1,M(0)); for(int i=0;i<=m;i++){ ts[i+0]+=rs[i]*-M(m); ts[i+1]+=rs[i]; } rs=ts; m|=1; } } assert(m==n); } M operator[](int k)const{return rs[k];} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: combinatorics/stirling2nd.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "enumeration.cpp" #include "../formalpowerseries/base.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Stirling2nd : FormalPowerSeries{ using M = M_; using super = FormalPowerSeries; using Poly = typename super::Poly; using super::super, super::finv; Poly rs; void build(int n){ super::init(n+1); Poly as(n+1),bs(n+1); for(int i=0;i<=n;i++){ as[i]=M(i).pow(n)*finv[i]; bs[i]=(i&1?-M(1):M(1))*finv[i]; } rs=super::pre(super::mul(as,bs),n+1); } M operator[](int k)const{return rs[k];} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: combinatorics/surjection.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "enumeration.cpp" #undef call_from_test #endif //BEGIN CUT HERE // put n distinct balls into k distinct boxes template M surjection(int n,int k){ using E = Enumeration; E::init(k); M res(0); for(int i=1;i<=k;i++){ M tmp=E::C(k,i)*M(i).pow(n); if((k-i)&1) res-=tmp; else res+=tmp; } return res; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: convexhulltrick/convexhulltrick.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE enum Objective{ MINIMIZE = +1, MAXIMIZE = -1, }; template struct Line { T k,m; T operator()(const T x)const{return k*x+m;} }; template struct ConvexHullTrick : deque>{ inline int sgn(T x){return x==0?0:(x<0?-1:1);} using D = long double; inline bool check(const Line &a,const Line &b,const Line &c){ if(b.m==a.m or c.m==b.m) return sgn(b.k-a.k)*sgn(c.m-b.m) >= sgn(c.k-b.k)*sgn(b.m-a.m); // return (b.k-a.k)*(c.m-b.m) >= (b.m-a.m)*(c.k-b.k); return D(b.k-a.k)*sgn(c.m-b.m)/D(abs(b.m-a.m)) >= D(c.k-b.k)*sgn(b.m-a.m)/D(abs(c.m-b.m)); } using super = deque>; using super::empty,super::size,super::front,super::back; using super::emplace_front,super::emplace_back; using super::pop_front,super::pop_back; const Line at(int i) const{return (*this)[i];} void add(T k_,T m_){ Line l({k_*objective,m_*objective}); if(empty()){ emplace_front(l); return; } if(front().k<=l.k){ if(front().k==l.k){ if(front().m<=l.m) return; pop_front(); } while(size()>=2 and check(l,at(0),at(1))) pop_front(); emplace_front(l); }else{ assert(l.k<=back().k); if(back().k==l.k){ if(back().m<=l.m) return; pop_back(); } while(size()>=2 and check(at(size()-2),at(size()-1),l)) pop_back(); emplace_back(l); } } T query(T x){ assert(!empty()); int l=-1,r=size()-1; while(l+1>1; if(at(m)(x)>=at(m+1)(x)) l=m; else r=m; } return at(r)(x)*objective; } T queryMonotoneInc(T x){ assert(!empty()); while(size()>=2 and at(0)(x)>=at(1)(x)) pop_front(); return front()(x)*objective; } T queryMonotoneDec(T x){ assert(!empty()); while(size()>=2 and at(size()-1)(x)>=at(size()-2)(x)) pop_back(); return back()(x)*objective; } vector> getVertices(){ vector> res; for(int i=0;i+1<(int)size();i++){ auto l0=at(i+0),l1=at(i+1); assert(l0.k!=l1.k); T x=(l1.m-l0.m)/(l0.k-l1.k); res.emplace_back(x,at(i)(x)*objective); } return res; } }; template using MinConvexHullTrick = ConvexHullTrick; template using MaxConvexHullTrick = ConvexHullTrick; template void chmin(optional &a,const T& b){if(!a or *a>b) a=b;} // O(n \log n) (n = as.size()) template optional solve_lp(T p0,T p1,vector as,vector bs,vector cs){ auto calc=[&](T y0,T y1){return y0*p0+y1*p1;}; using P = pair; vector

vp; for(int i=0;i<(int)as.size();i++) vp.emplace_back(-bs[i]/as[i],cs[i]/as[i]); sort(vp.begin(),vp.end()); ConvexHullTrick cht; for(auto[k,m]:vp) cht.add(k,m); optional res; for(auto[y1,y0]:cht.getVertices()) if(y0>=0 and y1>=0) chmin(res,calc(y0,y1)); return res; } // minimize_{y0, y1 >=0} p0 y0 + p1 y1 // s.t. as[i] * y0 + bs[i] * y1 >= cs[i] // assume as[i], bs[i] >0 template T solve_lp_min(T p0,T p1,vector as,vector bs,vector cs){ T y0=0,y1=0; for(int i=0;i<(int)as.size();i++){ y0=max(y0,cs[i]/as[i]); y1=max(y1,cs[i]/bs[i]); } auto res=solve_lp(+p0,+p1,as,bs,cs); chmin(res,p0*y0); chmin(res,p1*y1); return *res; } // maximize_{y0, y1 >=0} p0 y0 + p1 y1 // s.t. as[i] * y0 + bs[i] * y1 <= cs[i] // assume as[i], bs[i] >0, cs[i] >=0 template T solve_lp_max(T p0,T p1,vector as,vector bs,vector cs){ T y0=cs[0]/as[0],y1=cs[0]/bs[0]; for(int i=0;i<(int)as.size();i++){ y0=min(y0,cs[i]/as[i]); y1=min(y1,cs[i]/bs[i]); as[i]=-as[i];bs[i]=-bs[i];cs[i]=-cs[i]; } auto res=solve_lp(-p0,-p1,as,bs,cs); chmin(res,-p0*y0); chmin(res,-p1*y1); return -*res; } //END CUT HERE #ifndef call_from_test signed ARC128_C(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,s; cin>>n>>m>>s; using D = double; vector as(n); for(int i=0;i>as[i]; vector bs(n+1,0),cs(n+1,0); for(int i=0;i<=n;i++) bs[i]=n-i; for(int i=n;i>0;i--) cs[i-1]=as[i-1]+cs[i]; D ans=solve_lp_min(m,s,vector(n+1,1),bs,cs); cout< using namespace std; #endif //BEGIN CUT HERE enum Objective{ MAXIMIZE = +1, MINIMIZE = -1, }; template struct Line { mutable T k,m,p; bool operator<(const Line&o)const{return k T lc_inf(){return numeric_limits::max();} template<> double lc_inf(){return 1/.0;} template T lc_div(T a,T b){return a/b-((a^b)<0 and a%b);} template<> double lc_div(double a,double b){return a/b;}; template struct LineContainer : multiset, less<>>{ using super = multiset, less<>>; using super::begin,super::end,super::insert,super::erase; using super::empty,super::lower_bound; const T inf = lc_inf(); bool insect(typename super::iterator x,typename super::iterator y){ if(y==end()) return x->p=inf,false; if(x->k==y->k) x->p=(x->m>y->m?inf:-inf); else x->p=lc_div(y->m-x->m,x->k-y->k); return x->p>=y->p; } void add(T k,T m){ auto z=insert({k*objective,m*objective,0}),y=z++,x=y; while(insect(y,z)) z=erase(z); if(x!=begin() and insect(--x,y)) insect(x,y=erase(y)); while((y=x)!=begin() and (--x)->p>=y->p) insect(x,erase(y)); } T query(T x){ assert(!empty()); auto l=*lower_bound(x); return (l.k*x+l.m)*objective; } }; template using MinLineContainer = LineContainer; template using MaxLineContainer = LineContainer; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: convexhulltrick/segmentcontainer.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE enum Objective{ MINIMIZE = +1, MAXIMIZE = -1, }; template struct SegmentContainer{ const T INF = numeric_limits::max() / 2; struct Segment{ T a,b; T operator()(T x) const{return a*x+b;} }; int n; vector xs; vector dat; SegmentContainer(const vector &xs_):xs(xs_){ sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end()); n=xs.size(); dat.assign(n<<1,Segment({T(0),INF})); } inline int index(T x) const{ return lower_bound(xs.begin(),xs.end(),x)-xs.begin(); } // [xl, xr) void add(T a,T b,T xl,T xr){ Segment g({a*objective,b*objective}); for(int l=index(xl)+n,r=index(xr)+n;l>=1,r>>=1){ if(l&1) update(g,l++); if(r&1) update(g,--r); } } void update(Segment g,int i){ int l=i,r=i+1; while(l>1; T xl=xs[l-n],xr=xs[r-1-n],xm=xs[m-n]; Segment &f=dat[i]; if(f(xl)<=g(xl) and f(xr)<=g(xr)) return; if(f(xl)>=g(xl) and f(xr)>=g(xr)) return (void)(f=g); if(f(xm)>g(xm)) swap(f,g); if(f(xl)>g(xl)) i=(i<<1)|0,r=m; else i=(i<<1)|1,l=m; } } T query(T x){ T res=INF; for(int i=index(x)+n;i;i>>=1) res=min(res,dat[i](x)); return res*objective; } }; template using MinSegmentContainer = SegmentContainer; template using MaxSegmentContainer = SegmentContainer; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: convexhulltrick/withindex.cpp ================================================ #include using namespace std; //BEGIN CUT HERE // index siyou kimattenai template struct ConvexHullTrickWithIndex { struct P{ T m,b; int idx; P(T m,T b,int idx):m(m),b(b),idx(idx){}; bool operator<(const P &a){ return m!=a.m?m H; bool empty()const{return H.empty();} void clear(){H.clear();} inline int sgn(T x){return x==0?0:(x<0?-1:1);} using D = long double; inline bool check(const P &a,const P &b,const P &c){ if(b.b==a.b or c.b==b.b) return sgn(b.m-a.m)*sgn(c.b-b.b) >= sgn(c.m-b.m)*sgn(b.b-a.b); return D(b.m-a.m)*sgn(c.b-b.b)/D(abs(b.b-a.b)) >= D(c.m-b.m)*sgn(b.b-a.b)/D(abs(c.b-b.b)); } void addLine(T m,T b,int idx){ if(!isMin) m*=-1,b*=-1; P line(m,b,idx); if(empty()){ H.emplace_front(line); return; } if(empty() or H.front().m<=m){ if(H.front().m==m){ if(H.front().b<=b) return; H.pop_front(); } while(H.size()>=2 and check(line,H.front(),H[1])) H.pop_front(); H.emplace_front(line); }else{ assert(m<=H.back().m); if(H.back().m==m){ if(H.back().b<=b) return; H.pop_back(); } while(H.size()>=2 and check(H[H.size()-2],H.back(),line)) H.pop_back(); H.emplace_back(line); } } inline pair getY(const P &a,const T &x){ return make_pair(a.m*x+a.b,a.idx); } pair query(T x){ assert(!empty()); int l=-1,r=H.size()-1; while(l+1>1; if(getY(H[m],x)>=getY(H[m+1],x)) l=m; else r=m; } if(isMin) return getY(H[r],x); return make_pair(-getY(H[r],x).first,H[r].idx); } pair queryMonotoneInc(T x){ assert(!empty()); while(H.size()>=2 and getY(H.front(),x)>=getY(H[1],x)) H.pop_front(); if(isMin) return getY(H.front(),x); return make_pair(-getY(H.front(),x).first,H.front().idx); } pair queryMonotoneDec(T x){ assert(!empty()); while(H.size()>=2 and getY(H.back(),x)>=getY(H[H.size()-2],x)) H.pop_back(); if(isMin) return getY(H.back(),x); return make_pair(-getY(H.back(),x).first,H.back().idx); } }; //END CUT HERE //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; ll n,m; cin>>n>>m; using CHT = ConvexHullTrickWithIndex; CHT cht; ll bs=0,ss=0,len=n; cht.addLine(0,-bs,0); for(int i=0;i>t; if(t==1){ ll k; cin>>k; cht.clear(); cht.addLine(0,-bs,0); len+=k; } if(t==2){ ll k; cin>>k; cht.addLine(len,-(bs+len*ss),len); len+=k; } if(t==3){ ll b,s; cin>>b>>s; bs+=b; ss+=s; } auto p=cht.queryMonotoneInc(ss); cout< using namespace std; #define call_from_test #include "fastfouriertransform.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct ArbitraryMod{ using dbl=FFT::dbl; using num=FFT::num; vector multiply(vector as,vector bs){ int need=as.size()+bs.size()-1; int sz=1; while(sz fa(sz),fb(sz); for(int i=0;i<(int)as.size();i++) fa[i]=num(as[i].v&((1<<15)-1),as[i].v>>15); for(int i=0;i<(int)bs.size();i++) fb[i]=num(bs[i].v&((1<<15)-1),bs[i].v>>15); fft(fa);fft(fb); dbl ratio=0.25/sz; num r2(0,-1),r3(ratio,0),r4(0,-ratio),r5(0,1); for(int i=0;i<=(sz>>1);i++){ int j=(sz-i)&(sz-1); num a1=(fa[i]+conj(fa[j])); num a2=(fa[i]-conj(fa[j]))*r2; num b1=(fb[i]+conj(fb[j]))*r3; num b2=(fb[i]-conj(fb[j]))*r4; if(i!=j){ num c1=(fa[j]+conj(fa[i])); num c2=(fa[j]-conj(fa[i]))*r2; num d1=(fb[j]+conj(fb[i]))*r3; num d2=(fb[j]-conj(fb[i]))*r4; fa[i]=c1*d1+c2*d2*r5; fb[i]=c1*d2+c2*d1; } fa[j]=a1*b1+a2*b2*r5; fb[j]=a1*b2+a2*b1; } fft(fa);fft(fb); vector cs(need); using ll = long long; for(int i=0;i using namespace std; #endif //BEGIN CUT HERE namespace bitwise_and{ auto zeta=[](auto& lo,auto& hi){lo+=hi;}; auto moebius=[](auto& lo,auto& hi){lo-=hi;}; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: convolution/bitwise/fwht.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif // https://kazuma8128.hatenablog.com/entry/2018/05/31/144519 //BEGIN CUT HERE // O(n \log n) template void fwht(vector &as,F f){ int n=as.size(); for(int d=1;d using namespace std; #endif //BEGIN CUT HERE namespace bitwise_or{ auto zeta=[](auto& lo,auto& hi){hi+=lo;}; auto moebius=[](auto& lo,auto& hi){hi-=lo;}; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: convolution/bitwise/xor.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE namespace bitwise_xor{ auto zeta=[](auto& lo,auto& hi){ auto x=lo+hi,y=lo-hi; lo=x; hi=y; }; auto moebius=[](auto& lo,auto& hi){ auto x=lo+hi,y=lo-hi; lo=x/decltype(x)(2); hi=y/decltype(y)(2); }; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: convolution/convolution2D.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Convolution2D{ using Matrix = vector< vector >; const Transformer tran; Convolution2D(Transformer tran):tran(tran){} void transpose(Matrix &as){ int n=as.size(),m=as[0].size(); Matrix cs(as); as.assign(m,vector(n)); for(int i=0;i using namespace std; #endif // https://noshi91.hatenablog.com/entry/2019/09/23/002445 //BEGIN CUT HERE // O(n \log \log n) namespace DivisorTransform{ template void inc(vector &as,F f){ assert(as[0]==T(0)); int n=as.size(); vector sieve(n,false); for(int p=2;p void dec(vector &as,F f){ assert(as[0]==T(0)); int n=as.size(); vector sieve(n,false); for(int p=2;p void zeta(vector &as){ auto f=[](T &lo,T &hi){lo+=hi;}; DivisorTransform::dec(as,f); } template void moebius(vector &as){ auto f=[](T &lo,T &hi){lo-=hi;}; DivisorTransform::inc(as,f); } } namespace LCMConvolution{ template void zeta(vector &as){ auto f=[](T &lo,T &hi){hi+=lo;}; DivisorTransform::inc(as,f); } template void moebius(vector &as){ auto f=[](T &lo,T &hi){hi-=lo;}; DivisorTransform::dec(as,f); } } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: convolution/fastfouriertransform.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE namespace FFT{ using dbl = double; struct num{ dbl x,y; num(){x=y=0;} num(dbl x,dbl y):x(x),y(y){} }; inline num operator+(num a,num b){ return num(a.x+b.x,a.y+b.y); } inline num operator-(num a,num b){ return num(a.x-b.x,a.y-b.y); } inline num operator*(num a,num b){ return num(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x); } inline num conj(num a){ return num(a.x,-a.y); } int base=1; vector rts={{0,0},{1,0}}; vector rev={0,1}; const dbl PI=asinl(1)*2; void ensure_base(int nbase){ if(nbase<=base) return; rev.resize(1<>1]>>1)+((i&1)<<(nbase-1)); rts.resize(1< &as){ int n=as.size(); assert((n&(n-1))==0); int zeros=__builtin_ctz(n); ensure_base(zeros); int shift=base-zeros; for(int i=0;i>shift)) swap(as[i],as[rev[i]>>shift]); for(int k=1;k vector multiply(vector &as,vector &bs){ int need=as.size()+bs.size()-1; int nbase=0; while((1< fa(sz); for(int i=0;i>1);i++){ int j=(sz-i)&(sz-1); num z=(fa[j]*fa[j]-conj(fa[i]*fa[i]))*r; if(i!=j) fa[j]=(fa[i]*fa[i]-conj(fa[j]*fa[j]))*r; fa[i]=z; } fft(fa); vector res(need); for(int i=0;i using namespace std; #define call_from_test #include "../mod/mint.cpp" #include "numbertheoretictransform.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct Garner{ using ll = long long; inline static NTT<0> ntt0; inline static NTT<1> ntt1; inline static NTT<2> ntt2; static constexpr int pow(int a,int b,int md){ int res=1; a=a%md; while(b){ if(b&1) res=(ll)res*a%md; a=(ll)a*a%md; b>>=1; } return res; } static constexpr int inv(int x,int md){ return pow(x,md-2,md); } inline void garner(int &c0,int c1,int c2,int m01,int MOD){ static constexpr int r01=inv(ntt0.md,ntt1.md); static constexpr int r02=inv(ntt0.md,ntt2.md); static constexpr int r12=inv(ntt1.md,ntt2.md); c1=(ll)(c1-c0)*r01%ntt1.md; if(c1<0) c1+=ntt1.md; c2=(ll)(c2-c0)*r02%ntt2.md; c2=(ll)(c2-c1)*r12%ntt2.md; if(c2<0) c2+=ntt2.md; c0%=MOD; c0+=(ll)c1*ntt0.md%MOD; if(c0>=MOD) c0-=MOD; c0+=(ll)c2*m01%MOD; if(c0>=MOD) c0-=MOD; } inline void garner(vector< vector > &cs,int MOD){ int m01 =(ll)ntt0.md*ntt1.md%MOD; int sz=cs[0].size(); for(int i=0;i multiply(vector as,vector bs,int MOD){ vector< vector > cs(3); cs[0]=ntt0.multiply(as,bs); cs[1]=ntt1.multiply(as,bs); cs[2]=ntt2.multiply(as,bs); size_t sz=as.size()+bs.size()-1; for(auto& v:cs) v.resize(sz); garner(cs,MOD); return cs[0]; } template decltype(auto) multiply(vector am, vector bm){ vector as(am.size()),bs(bm.size()); for(int i=0;i<(int)as.size();i++) as[i]=am[i].v; for(int i=0;i<(int)bs.size();i++) bs[i]=bm[i].v; vector cs=multiply(as,bs,T::mod); vector cm(cs.size()); for(int i=0;i<(int)cm.size();i++) cm[i]=T(cs[i]); return cm; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: convolution/naive.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // O(N M) template decltype(auto) naive(){ using Poly = vector; auto conv=[](Poly as, Poly bs){ Poly cs(as.size()+bs.size()-1,0); for(int i=0;i<(int)as.size();i++) for(int j=0;j<(int)bs.size();j++) cs[i+j]+=as[i]*bs[j]; return cs; }; return +conv; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: convolution/numbertheoretictransform.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../mod/mint.cpp" #undef call_from_test #endif //BEGIN CUT HERE constexpr int bmds(int x){ const int v[] = {1012924417, 924844033, 998244353, 897581057, 645922817}; return v[x]; } constexpr int brts(int x){ const int v[] = {5, 5, 3, 3, 3}; return v[x]; } template struct NTT{ inline static constexpr int md = bmds(X); inline static constexpr int rt = brts(X); using M = Mint; vector< vector > rts,rrts; void ensure_base(int n){ if((int)rts.size()>=n) return; rts.resize(n);rrts.resize(n); for(int i=1;i &as,bool f){ int n=as.size(); assert((n&(n-1))==0); ensure_base(n); for(int i=0,j=1;j+1>1;k>(i^=k);k>>=1); if(i>j) swap(as[i],as[j]); } for(int i=1;i multiply(vector as,vector bs){ int need=as.size()+bs.size()-1; int sz=1; while(sz multiply(vector as,vector bs){ vector am(as.size()),bm(bs.size()); for(int i=0;i<(int)am.size();i++) am[i]=M(as[i]); for(int i=0;i<(int)bm.size();i++) bm[i]=M(bs[i]); vector cm=multiply(am,bm); vector cs(cm.size()); for(int i=0;i<(int)cs.size();i++) cs[i]=cm[i].v; return cs; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: datastructure/BIT2D.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct BIT2D{ int n,m; T d; vector< vector > bit; //1-indexed BIT2D():n(-1),m(-1){} BIT2D(int n_,int m_):n(n_),m(m_),bit(n_+1,vector(m+1,0)){} T sum(int i,int j){ T s(0); for(int x=i;x>0;x-=(x&-x)) for(int y=j;y>0;y-=(y&-y)) s+=bit[x][y]; return s; } void add(int i,int j,T a){ if(i==0 or j==0) return; for(int x=i;x<=n;x+=(x&-x)) for(int y=j;y<=m;y+=(y&-y)) bit[x][y]+=a; } // (x1,x2] * (y1,y2]; T sum(int x1,int y1,int x2,int y2){ return sum(x1,y1)-sum(x1,y2)-sum(x2,y1)+sum(x2,y2); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: datastructure/absolutesum.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct AbsoluteSum{ multiset lp,rp; T sum; AbsoluteSum():sum(0){} T insert(T x){ if(lp.empty()){ lp.emplace(x); rp.emplace(x); return T(0); } auto p=interval(); lp.emplace(x); rp.emplace(x); if(p.first<=x and x<=p.second) return T(0); if(*lp.rbegin()>*rp.begin()){ T a=*lp.rbegin(); T b=*rp.begin(); lp.erase(lp.find(a)); rp.erase(rp.find(b)); rp.emplace(a); lp.emplace(b); } T res=min(abs(p.first-x),abs(p.second-x)); sum+=res; return res; } T erase(T x){ assert(lp.count(x)+rp.count(x)>=2); if(lp.count(x) and rp.count(x)){ lp.erase(lp.find(x)); rp.erase(rp.find(x)); return T(0); } if(lp.count(x)){ lp.erase(lp.find(x)); lp.erase(lp.find(x)); lp.emplace(*rp.begin()); rp.erase(rp.begin()); }else{ rp.erase(rp.find(x)); rp.erase(rp.find(x)); rp.emplace(*lp.rbegin()); lp.erase(--lp.end()); } auto p=interval(); if(p.first<=x and x<=p.second) return T(0); T res=min(abs(p.first-x),abs(p.second-x)); sum-=res; return res; } pair interval(){ assert(!lp.empty()); return make_pair(*lp.rbegin(),*rp.begin()); } T value(){return sum;} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE // test interval() signed ABC127_F(){ cin.tie(0); ios::sync_with_stdio(0); int q; cin>>q; using ll = long long; AbsoluteSum as; ll sum=0; for(int i=0;i>t; if(t==1){ ll a,b; cin>>a>>b; as.insert(a); sum+=b; } if(t==2){ cout< using namespace std; #endif //BEGIN CUT HERE template class BIT{ private: // \sum_{j < i} v[j] T sum(int i){ T s(0); for(int x=i;x>0;x-=(x&-x)) s+=bit[x]; return s; } public: int n; vector bit; BIT(int n_):n(n_+1),bit(n_+2,0){} // v[i] += a void add(int i,T a){ for(int x=++i;x<=n;x+=(x&-x)) bit[x]+=a; } // \sum_{l <= i < r} v[i] T query(int l,int r){return sum(r)-sum(l);} // min({x | sum(x) >= w}) int lower_bound(const T w){ if(w<=0) return 0; T r=w; int x=0,p=1; while(p0;k>>=1){ if(x+k<=n and bit[x+k]=w); return x; } // min({x | sum(x) > w}) int upper_bound(T w){return lower_bound(w+1);} }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: datastructure/binarytrie.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct BinaryTrie{ struct Node{ size_t cnt; Node *p,*l,*r; Node(Node* p):cnt(0),p(p){l=r=nullptr;} }; T acc; Node *root; BinaryTrie():acc(0){root=emplace(nullptr);} void clear(Node *a){ if(!a) return; clear(a->l);clear(a->r); delete(a); } inline Node* emplace(Node* p){ return new Node(p); } inline size_t count(Node* a){ return a?a->cnt:0; } void add(const T b,size_t k=1){ const T nb=b^acc; Node* a=root; for(int i=X-1;i>=0;i--){ bool f=(nb>>i)&1; if(!f and !a->l) a->l=emplace(a); if( f and !a->r) a->r=emplace(a); a=f?a->r:a->l; } a->cnt+=k; while((a=a->p)) a->cnt=count(a->l)+count(a->r); } inline void update(const T b){acc^=b;} Node* find(const T b){ const T nb=b^acc; Node* a=root; for(int i=X-1;i>=0;i--){ bool f=(nb>>i)&1; a=f?a->r:a->l; if(!a) return a; } return a; } Node* check(Node *a){ if(!a or count(a)) return a; delete(a); return nullptr; } void sub(Node* a,size_t k=1){ assert(a and a->cnt>=k); a->cnt-=k; while((a=a->p)){ a->l=check(a->l); a->r=check(a->r); a->cnt=count(a->l)+count(a->r); } } Node* xmax(const T b){ assert(count(root)); const T nb=b^acc; Node* a=root; for(int i=X-1;i>=0;i--){ bool f=(nb>>i)&1; if(!a->l or !a->r) a=a->l?a->l:a->r; else a=f?a->l:a->r; } return a; } Node* xmin(const T b){ return xmax(~b&((T(1)<l,*r=a->r; if((acc>>i)&1) swap(l,r); if(l or r) return ge(l?l:r,i+1); return a; } Node* next(Node* a,int i){ if(!(a->p)) return nullptr; Node *l=a->p->l,*r=a->p->r; if((acc>>(i+1))&1) swap(l,r); if(a==l and r) return ge(r,i); return next(a->p,i+1); } Node* lower_bound(const T b){ const T nb=b^acc; Node* a=root; for(int i=X-1;i>=0;i--){ bool f=(nb>>i)&1; if(!f and a->l){a=a->l;continue;} if( f and a->r){a=a->r;continue;} if((b>>i)&1) return next(a,i); return ge(a,i); } return a; } Node* upper_bound(const T b){ return lower_bound(b+1); } T val(Node* a){ T res(0); for(int i=0;i<(int)X;i++){ assert(a->p); res|=(T(a==a->p->r)<p; } return res^acc; } Node* find_by_order(size_t k){ Node *a=root; if(count(a)<=k) return nullptr; for(int i=X-1;i>=0;i--){ bool f=(acc>>i)&1; if(count(f?a->r:a->l)<=k){ k-=count(f?a->r:a->l); a=f?a->l:a->r; }else{ a=f?a->r:a->l; } } return a; } size_t order_of_key(const T b){ Node *a=root; size_t res=0; for(int i=X-1;i>=0;i--){ Node *l=a->l,*r=a->r; if((acc>>i)&1) swap(l,r); bool f=(b>>i)&1; if(f) res+=count(l); a=f?r:l; if(!a) break; } return res; } }; //END CUT HERE #ifndef call_from_test // find_by_order (weak) signed ARC033_C(){ int q; scanf("%d",&q); BinaryTrie bt; while(q--){ int t,x; scanf("%d %d",&t,&x); if(t==1) bt.add(x); if(t==2){ auto k=bt.find_by_order(x-1); printf("%d\n",bt.val(k)); bt.sub(k); } } return 0; } /* verified on 2020/06/06 https://atcoder.jp/contests/arc033/tasks/arc033_3 */ // upper_bound signed CFR477_C(){ using ll = long long; int n; scanf("%d",&n); vector bs(n); for(int i=0;i bt; for(int i=0;i ans; ll x=bt.val(bt.xmin(0)); ans.emplace_back(x); bt.sub(bt.find(x)); apply(x); for(int i=1;i using namespace std; #endif //BEGIN CUT HERE // half open interval [l, r) template struct BitVector{ inline static constexpr size_t B = sizeof(T) * CHAR_BIT; size_t n; vector dat; BitVector(size_t n_):n(n_),dat(n_/B+1,0){} inline T get(size_t i)const{return (dat[i/B]>>(i%B))&T(1);} void set(size_t i,T v){ dat[i/B]&=~(T(1)<<(i%B)); dat[i/B]|=v<<(i%B); } // O(B + (r - l) / B) BitVector get(size_t l,size_t r)const{ BitVector res(r-l); if(r-l<=B){ for(size_t i=l;i>(B-(p-l)); } } // [q, r) for(size_t i=q;i>(p-l))|(bv.dat[(i-l)/B+1]<<(B-(p-l))); } // [q, r) for(size_t i=q;i using namespace std; #endif //BEGIN CUT HERE template vector cartesian_tree(const vector &vs){ int n=vs.size(); vector ps(n,-1),ls(n,-1),rs(n,-1); int cur=0; for(int i=1;i using namespace std; #endif //BEGIN CUT HERE template struct CumulativeSum{ vector sm; CumulativeSum(const vector &as){ int n=as.size(); sm.resize(n+1); sm[0]=T(); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct DisjointSparseTable{ using F = function; vector< vector > dat; vector ht; const F f; DisjointSparseTable(F f):f(f){} void build(const vector &vs){ int n=vs.size(),h=1; while((1<(n)); ht.assign((1<>1]+1; for(int j=0;j=j;k--) dat[i][k]=f(vs[k],dat[i][k+1]); if(n<=t) break; dat[i][t]=vs[t]; int r=min(t+s,n); for(int k=t+1;k=--r) return dat[0][l]; return f(dat[ht[l^r]][l],dat[ht[l^r]][r]); } }; //END CUT HERE #ifndef call_from_test // find with non-idempotent monoid signed CODECHEF_SEGPROD(){ int T; scanf("%d",&T); int p; auto f=[&](int a,int b)->int{return (long long)a*b%p;}; DisjointSparseTable dst(f); for(int t=1;t<=T;t++){ int n,q; scanf("%d %d %d",&n,&p,&q); vector v(n); for(int i=0;i b(q/64+2); for(int i=0;i<(q/64+2);i++) scanf("%d",&b[i]); dst.build(v); int x=0,l=0,r=0; for(int i=0;ir) swap(l,r); x=dst.query(l,r+1)+1; if(x>=p) x-=p; } printf("%d\n",x); } return 0; } /* verified on 2019/10/29 https://www.codechef.com/problems/SEGPROD */ //INSERT ABOVE HERE signed main(){ //CODECHEF_SEGPROD(); return 0; } #endif ================================================ FILE: datastructure/kdtree.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct KDTree{ static const int NIL = -1; class Node{ public: int pos,p,l,r; Node(){pos=p=l=r=NIL;} }; class Point{ public: int id; T x,y; Point(int id,T x,T y): id(id),x(x),y(y){} bool operator<(const Point &p)const{ return id ps; vector ts; int np; void add_point(int i,int x,int y){ ps.emplace_back(i,x,y); ts.emplace_back(); } static bool lessX(const Point &p1,const Point &p2){return p1.x=r) return NIL; int mid=(l+r)/2; int t=np++; if(depth%2==0){ sort(ps.begin()+l,ps.begin()+r,lessX); }else{ sort(ps.begin()+l,ps.begin()+r,lessY); } ts[t].pos=mid; ts[t].l=dfs(l,mid,depth+1); ts[t].r=dfs(mid+1,r,depth+1); return t; } int build(){ np=0; return dfs(0,ps.size(),0); } // [sx, tx] * [sy, ty] void find(int v,T sx,T tx,T sy,T ty,int depth,vector &ans){ T x=ps[ts[v].pos].x; T y=ps[ts[v].pos].y; if(sx<=x and x<=tx and sy<=y and y<=ty) ans.emplace_back(ps[ts[v].pos]); if(depth%2==0){ if(ts[v].l!=NIL){ if(sx<=x) find(ts[v].l,sx,tx,sy,ty,depth+1,ans); } if(ts[v].r!=NIL){ if(x<=tx) find(ts[v].r,sx,tx,sy,ty,depth+1,ans); } }else{ if(ts[v].l!=NIL){ if(sy<=y) find(ts[v].l,sx,tx,sy,ty,depth+1,ans); } if(ts[v].r!=NIL){ if(y<=ty) find(ts[v].r,sx,tx,sy,ty,depth+1,ans); } } } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: datastructure/pb_ds_cc_hash_table.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE #include using namespace __gnu_pbds; template > using gmap = cc_hash_table; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: datastructure/prioritysum.cpp ================================================ #include using namespace std; //BEGIN CUT HERE // return sum of top K element (default: maximum) template, typename C1=less, typename C2=greater > struct PrioritySum{ size_t num; T sum; priority_queue pq1; priority_queue pq2; PrioritySum():num(0),sum(identity){} PrioritySum(size_t num):num(num),sum(identity){} void resolve(){ assert(size()>=num); while(pq2.size()num){ sum-=pq2.top(); pq1.emplace(pq2.top()); pq2.pop(); } if(pq1.empty() or pq2.empty()) return; while(C2()(pq1.top(),pq2.top())){ T t1=pq1.top();pq1.pop(); T t2=pq2.top();pq2.pop(); sum+=t1; sum-=t2; pq1.emplace(t2); pq2.emplace(t1); } } T query(){resolve();return sum;} void push(const T &x){pq1.emplace(x);} void expand(){num++;} void shrink(){assert(num);num--;} size_t size()const{return pq1.size()+pq2.size();} }; template using MaximumSum=PrioritySum, less, greater >; template using MinimumSum=PrioritySum, greater, less >; //END CUT HERE struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n; vector a(3*n); for(int i=0;i<3*n;i++) cin>>a[i]; MaximumSum ps1(n); vector dp1(3*n); for(int i=0;i<3*n;i++){ if(i>=n) dp1[i]=ps1.query(); ps1.push(a[i]); } MinimumSum ps2(n); vector dp2(3*n); for(int i=3*n-1;i>=0;i--){ ps2.push(a[i]); if(i<=2*n) dp2[i]=ps2.query(); } ll ans=dp1[n]-dp2[n]; for(int i=n;i<=2*n;i++) chmax(ans,dp1[i]-dp2[i]); cout<; int n; cin>>n; vector > G(n); for(int i=1;i>a>>b>>c; a--;b--; G[a].emplace_back(b,c); G[b].emplace_back(a,c); } auto cmp=[&](P a,P b){ return G[a.first].size()>G[b.first].size(); }; for(auto &v:G) sort(v.begin(),v.end(),cmp); vector > alive(n),death(n); for(int i=0;i > ms(n); vector par(n,-1),cst(n,0),children(n,0); auto dfs= [&](int v,int p,auto func)->void{ for(auto e:G[v]){ ll u=e.first,c=e.second; if(u==p) continue; par[u]=v; cst[u]=c; children[v]++; func(u,v,func); } }; dfs(0,-1,dfs); const ll INF = 1e18; vector used(n,0),dead(n,0); auto dfs2= [&](int v,int p,int t,auto func)->P{ used[v]=1; vector res; ll sum=0; for(auto e:G[v]){ ll u=e.first,c=e.second; if(u==p) continue; if(dead[u]) break; P tmp=func(u,v,t,func); sum+=tmp.second; res.emplace_back((tmp.first+c)-tmp.second); } sort(res.begin(),res.end()); ll x=INF,y=INF,z=0; int num=children[v]-t; assert(num>=-1); for(int i=0;i<=(int)res.size();i++){ int j=max(num-i,0); if(j<=(int)ms[v].size()){ while((int)ms[v].numj) ms[v].shrink(); chmin(x,sum+z+ms[v].query()); } int k=max(num-i+1,0); if(k<=(int)ms[v].size()){ while((int)ms[v].numk) ms[v].shrink(); chmin(y,sum+z+ms[v].query()); } if(i<(int)res.size()) z+=res[i]; } return P(x,y); }; for(int t=0;t using namespace std; #endif //BEGIN CUT HERE struct QuickFind{ vector rs,ps; vector< vector > vs; QuickFind(int n):rs(n,1),ps(n),vs(n){ iota(ps.begin(),ps.end(),0); for(int i=0;i& elements(int x) const{return vs[x];} }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: datastructure/radixheap.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // prohibited to push an element less than popped one // Key: int or long long template struct RadixHeap{ inline static constexpr int bit = sizeof(K) * 8; array >, bit> vs; int size; K last; RadixHeap():size(0),last(0){} bool empty() const{return size==0;} inline int getbit(int a){ return a?bit-__builtin_clz(a):0; } inline int getbit(long long a){ return a?bit-__builtin_clzll(a):0; } void emplace(K key,V val){ size++; vs[getbit(key^last)].emplace_back(key,val); } pair pop(){ if(vs[0].empty()){ int idx=1; while(vs[idx].empty()) idx++; last=min_element(vs[idx].begin(),vs[idx].end())->first; for(auto &p:vs[idx]) vs[getbit(p.first^last)].emplace_back(p); vs[idx].clear(); } --size; auto res=vs[0].back(); vs[0].pop_back(); return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: datastructure/rangeslide.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct RangeSlide{ vector ls,rs; vector vs; F cmp; RangeSlide(vector vs,F cmp):vs(vs),cmp(cmp){} void add_range(size_t l,size_t r){ ls.emplace_back(l); rs.emplace_back(r); } vector build(){ deque deq; vector res; for(size_t i=0,l=0,r=0;i using namespace std; #endif //BEGIN CUT HERE // no resize() because it is dangerous template struct Rotcev{ vector data; size_t size()const{return data.size();}; bool empty()const{return data.empty();} T& operator[](size_t n){return data[size()-1-n];} const T& operator[](size_t n)const{return data[size()-1-n];} void push_front(T val){data.push_back(val);} void pop_front(){data.pop_back();}; void clear(){data.clear();} template Rotcev(Args ...args):data(forward(args)...){} template void emplace_front(Args ...args){data.emplace_back(forward(args)...);} template void assign(Args ...args){data.assign(forward(args)...);} }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: datastructure/skewheap.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct SkewHeap{ using G = function; using H = function; using C = function; G g; H h; C c; T INF; E ei; SkewHeap(G g,H h,C c,T INF,E ei):g(g),h(h),c(c),INF(INF),ei(ei){} struct Node{ Node *l,*r; T val; E add; Node(T val,E add):val(val),add(add){l=r=nullptr;} }; void eval(Node *a){ if(a==nullptr) return; if(a->add==ei) return; if(a->l) a->l->add=h(a->l->add,a->add); if(a->r) a->r->add=h(a->r->add,a->add); a->val=g(a->val,a->add); a->add=ei; } T top(Node *a){ return a!=nullptr?g(a->val,a->add):INF; } T snd(Node *a){ eval(a); return a!=nullptr?min(top(a->l),top(a->r)):INF; } Node* add(Node *a,E d){ if(a!=nullptr) a->add=h(a->add,d); return a; } Node* push(T v){ return new Node(v,ei); } Node* meld(Node *a,Node *b){ if(!a or !b) return a?a:b; if(c(top(a),top(b))) swap(a,b); eval(a); a->r=meld(a->r,b); swap(a->l,a->r); return a; } Node* pop(Node* a){ eval(a); auto res=meld(a->l,a->r); delete a; return res; } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "unionfind.cpp" #undef call_from_test signed APC001_D(){ using ll = long long; using Heap = SkewHeap; ll n,m; cin>>n>>m; vector a(n); for(ll i=0;i>a[i]; auto g=[](ll a,ll b){return a+b;}; auto h=[](ll a,ll b){return a+b;}; auto c=[](ll a,ll b){return a>b;}; const ll INF = 1e16; Heap heap(g,h,c,INF,0); vector v(n); for(ll i=0;i>x>>y; x=uf.find(x);y=uf.find(y); uf.unite(x,y); if(uf.find(x)!=x) swap(x,y); v[x]=heap.meld(v[x],v[y]); v[y]=NULL; } if(m==n-1){ cout<<0< using namespace std; #endif //BEGIN CUT HERE template struct SWAG{ using F1 = function; using F2 = function; const F1 f1; const F2 f2; S id; vector lt,rt; vector ls,rs; SWAG(F1 f1,F2 f2,S id):f1(f1),f2(f2),id(id),ls(1,id),rs(1,id){} // S, T identical / commutative is not required SWAG(F1 f1,S id):f1(f1),f2([&](T y,S x){return f1(y,x);}), id(id),ls(1,id),rs(1,id){} void push(T x){ rt.emplace_back(x); rs.emplace_back(f1(rs.back(),x)); } void pop(){ if(lt.empty()){ reverse(rt.begin(),rt.end()); for(auto x:rt){ lt.emplace_back(x); ls.emplace_back(f2(x,ls.back())); } rt.resize(0); rs.resize(1); } lt.pop_back(); ls.pop_back(); } template void fold(Q q){q(ls.back(),rs.back());} }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "../tools/fastio.cpp" #include "../tools/chminmax.cpp" #undef call_from_test //INSERT ABOVE HERE class Crypto { public: Crypto() { sm = cnt = 0; seed(); } int decode(int z) { z ^= next(); z ^= (next() << 8); z ^= (next() << 16); z ^= (next() << 22); return z; } void query(long long z) { const long long B = 425481007; const long long MD = 1000000007; cnt++; sm = ((sm * B % MD + z) % MD + MD) % MD; seed(); } private: long long sm; int cnt; uint8_t data[256]; int I, J; void swap_data(int i, int j) { uint8_t tmp = data[i]; data[i] = data[j]; data[j] = tmp; } void seed() { uint8_t key[8]; for (int i = 0; i < 4; i++) { key[i] = (sm >> (i * 8)); } for (int i = 0; i < 4; i++) { key[i+4] = (cnt >> (i * 8)); } for (int i = 0; i < 256; i++) { data[i] = i; } I = J = 0; int j = 0; for (int i = 0; i < 256; i++) { j = (j + data[i] + key[i%8]) % 256; swap_data(i, j); } } uint8_t next() { I = (I+1) % 256; J = (J + data[I]) % 256; swap_data(I, J); return data[(data[I] + data[J]) % 256]; } }; signed JAG2018_DAY2_D(){ int MOD; cin>>MOD; int q; cin>>q; Crypto c; using ll = long long; const ll INF = 1e18; using T = pair; using S = array; auto f1= [&](S x,T y){ S z(x); for(int i=0;i swag(f1,f2,id); for(int i=0;i>t>>w>>v>>l>>r; t = c.decode(t); w = c.decode(w); v = c.decode(v); l = c.decode(l); r = c.decode(r); if(t == 1) swag.push(T(w,v)); else swag.pop(); r++; auto ask= [&](S x,S y){ SWAG rmq([](ll a,ll b){return max(a,b);},-INF); for(int i=0;i0;i--){ rmq.fold([&](ll a,ll b){chmax(ans,max(a,b)+y[i%MOD]);}); rmq.push(x[(r+(MOD-i))%MOD]); rmq.pop(); } c.query(ans); cout< using namespace std; #endif //BEGIN CUT HERE // https://maspypy.com/slope-trick-1-%e8%a7%a3%e8%aa%ac%e7%b7%a8 template struct Slope{ template typename Comp_> struct PQ{ template using Comp = Comp_; inline static constexpr Comp comp{}; using P = pair; priority_queue, Comp

> pq; bool empty()const{return pq.empty();} T offset; PQ():offset(0){} bool compare(T a){return comp(a,pq.top().first+offset);} // f_{new}(x) = f_{old}(x - diff) void shift(T diff){offset+=diff;} void push(T pos,T num){ if(num!=T(0)) pq.emplace(pos-offset,num); } P pop(){ auto[pos,num]=pq.top();pq.pop(); return P(pos+offset,num); } }; PQ L; PQ R; T entire; Slope():entire(0){} inline T relu(T x){return max(0,x);} template void fix(T a,T cnt,From &from,To &to){ T use(0); while(use> vp; vp.reserve(pq.pq.size()); while(!pq.empty()) vp.emplace_back(pq.pop()); return vp; }; for(auto[pos,num]:vectorize(L)) res+=relu(pos-x)*num; for(auto[pos,num]:vectorize(R)) res+=relu(x-pos)*num; return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE // test shift(a, b) signed ABC217_H(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; Slope S; S.add_a_minus_x(0,1e9); S.add_x_minus_a(0,1e9); ll n; cin>>n; ll l=0; for(ll i=0;i>t>>d>>x; S.shift(l-t,t-l); l=t; if(d==0) S.add_a_minus_x(x); if(d==1) S.add_x_minus_a(x); } cout< using namespace std; #endif //BEGIN CUT HERE template struct SparseTable{ using F = function; vector< vector > dat; vector ht; const F f; SparseTable(F f):f(f){} void build(const vector &v){ int n=v.size(),h=1; while((1<(n)); ht.assign(n+1,0); for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1; for(int j=0;j using namespace std; #endif //BEGIN CUT HERE struct UnionFind{ int num; vector rs,ps; UnionFind(int n):num(n),rs(n,1),ps(n,0){ iota(ps.begin(),ps.end(),0); } int find(int x){ return (x==ps[x]?x:ps[x]=find(ps[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; if(rs[x] using namespace std; #endif //BEGIN CUT HERE struct FullyIndexableDictionary{ int len,blk; vector bit; vector sum; FullyIndexableDictionary(){} FullyIndexableDictionary(int len) :len(len),blk((len+31)>>5),bit(blk,0),sum(blk,0){} void set(int k){ bit[k>>5]|=1u<<(k&31); } void build(){ sum[0]=0; for(int i=1;i>5]>>(k&31))&1); } int rank(int k){ return sum[k>>5]+__builtin_popcount(bit[k>>5]&((1u<<(k&31))-1)); } int rank(bool v,int k){ return (v?rank(k):k-rank(k)); } int select(bool v,int k){ if(k<0 or rank(v,len)<=k) return -1; int l=0,r=len; while(l+1>1; if(rank(v,m)>=k+1) r=m; else l=m; } return r-1; } int select(bool v,int i,int l){ return select(v,i+rank(v,l)); } }; template struct WaveletMatrix{ int len; FullyIndexableDictionary mat[MAXLOG]; int zs[MAXLOG],buff1[MAXLOG],buff2[MAXLOG]; static const T npos=-1; WaveletMatrix(vector data){ len=data.size(); vector ls(len),rs(len); for(int dep=0;dep>(MAXLOG-(dep+1)))&1; if(k) rs[q++]=data[i],mat[dep].set(i); else ls[p++]=data[i]; } zs[dep]=p; mat[dep].build(); swap(ls,data); for(int i=0;i>(MAXLOG-(dep+1)))&1; l=mat[dep].rank(bit,l)+zs[dep]*bit; r=mat[dep].rank(bit,r)+zs[dep]*bit; } return r-l; } // return the position of k-th v int select(T v,int k){ rank(v,len); for(int dep=MAXLOG-1;dep>=0;dep--){ bool bit=(v>>(MAXLOG-(dep+1)))&1; k=mat[dep].select(bit,k,buff1[dep]); if(k>=buff2[dep] or k<0) return -1; k-=buff1[dep]; } return k; } int select(T v,int k,int l){ return select(v,k+rank(v,l)); } // return k-th largest value in [l,r) T quantile(int l,int r,int k){ if(r-l<=k or k<0) return -1; T res=0; for(int dep=0;depk){ l=p+zs[dep]; r=q+zs[dep]; res|=T(1)<<(MAXLOG-(dep+1)); }else{ k-=(q-p); l-=p; r-=q; } } return res; } T rquantile(int l,int r,int k){ return quantile(l,r,r-l-k-1); } int freq_dfs(int d,int l,int r,T val,T a,T b){ if(l==r) return 0; if(d==MAXLOG) return (a<=val and val ll(int l,int r,T v){ int res=0; for(int dep=0;dep>(MAXLOG-(dep+1)))&1; if(bit) res+=r-l+mat[dep].rank(bit,l)-mat[dep].rank(bit,r); l=mat[dep].rank(bit,l)+zs[dep]*bit; r=mat[dep].rank(bit,r)+zs[dep]*bit; } return make_pair(res,r-l); } int lt(int l,int r,T v){ auto p=ll(l,r,v); return p.first; } int le(int l,int r,T v){ auto p=ll(l,r,v); return p.first+p.second; } T succ(int l,int r,T v){ int k=le(l,r,v); return k==r-l?npos:rquantile(l,r,k); } T pred(int l,int r,T v){ int k=lt(l,r,v); return k?rquantile(l,r,k-1):npos; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: datastructure/weightedunionfind.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct WeightedUnionFind{ vector rs,ps; vector ws; WeightedUnionFind(int n):rs(n,1),ps(n),ws(n,T(0)){ iota(ps.begin(),ps.end(),0); } int find(int x){ if(x==ps[x]) return x; int t=find(ps[x]); ws[x]+=ws[ps[x]]; return ps[x]=t; } T weight(int x){ find(x); return ws[x]; } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y,T w){ w+=weight(x); w-=weight(y); x=find(x);y=find(y); if(x==y) return; if(rs[x] using namespace std; #define call_from_test #include "../mod/mint.cpp" #include "../convolution/numbertheoretictransform.cpp" #include "../combinatorics/enumeration.cpp" #include "base.cpp" #undef call_from_test #endif //BEGIN CUT HERE namespace fps_998244353{ NTT<2> ntt; using M = decltype(ntt)::M; using E = Enumeration; auto conv=[](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: formalpowerseries/base.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #undef call_from_test #endif // http://beet-aizu.hatenablog.com/entry/2019/09/27/224701 //BEGIN CUT HERE template struct FormalPowerSeries : Enumeration { using M = M_; using super = Enumeration; using super::fact; using super::finv; using super::invs; using Poly = vector; using Conv = function; Conv conv; FormalPowerSeries(Conv conv):conv(conv){} Poly pre(const Poly &as,int deg){ return Poly(as.begin(),as.begin()+min((int)as.size(),deg)); } Poly add(Poly as,Poly bs){ int sz=max(as.size(),bs.size()); Poly cs(sz,M(0)); for(int i=0;i<(int)as.size();i++) cs[i]+=as[i]; for(int i=0;i<(int)bs.size();i++) cs[i]+=bs[i]; return cs; } Poly sub(Poly as,Poly bs){ int sz=max(as.size(),bs.size()); Poly cs(sz,M(0)); for(int i=0;i<(int)as.size();i++) cs[i]+=as[i]; for(int i=0;i<(int)bs.size();i++) cs[i]-=bs[i]; return cs; } Poly mul(Poly as,Poly bs){ return conv(as,bs); } Poly mul(Poly as,M k){ for(auto &a:as) a*=k; return as; } bool is_zero(Poly as){ return as==Poly(as.size(),0); } void shrink(Poly &as){ assert(not is_zero(as)); while(as.back()==M(0)) as.pop_back(); } // F(0) must not be 0 Poly inv(Poly as,int deg); // not zero Poly div(Poly as,Poly bs); // not zero Poly mod(Poly as,Poly bs); // F(0) must be 1 Poly sqrt(Poly as,int deg); Poly diff(Poly as); Poly integral(Poly as); // F(0) must be 1 Poly log(Poly as,int deg); // F(0) must be 0 Poly exp(Poly as,int deg); // not zero Poly pow(Poly as,long long k,int deg); // x <- x + c Poly shift(Poly as,M c); }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: formalpowerseries/diff.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::diff(Poly as){ int n=as.size(); Poly rs(n); for(int i=1;i using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #include "inv.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::div(Poly as,Poly bs){ shrink(as);shrink(bs); if(as.size() using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #include "inv.cpp" #include "diff.cpp" #include "integral.cpp" #include "log.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::exp(Poly as,int deg){ Poly fs({M(1)}); as[0]+=M(1); for(int i=1;i using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::integral(Poly as){ super::init(as.size()+1); int n=as.size(); Poly rs(n+1); rs[0]=M(0); for(int i=0;i using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::inv(Poly as,int deg){ assert(as[0]!=M(0)); Poly rs({M(1)/as[0]}); for(int i=1;i using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #include "inv.cpp" #include "diff.cpp" #include "integral.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::log(Poly as,int deg){ return pre(integral(mul(diff(as),inv(as,deg))),deg); } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: formalpowerseries/mod.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #include "inv.cpp" #include "div.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::mod(Poly as,Poly bs){ if(is_zero(as)) return Poly({0}); shrink(as);shrink(bs); as=sub(as,mul(div(as,bs),bs)); if(is_zero(as)) return Poly({0}); shrink(as); return as; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: formalpowerseries/pow.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #include "inv.cpp" #include "diff.cpp" #include "integral.cpp" #include "log.cpp" #include "exp.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::pow(Poly as,long long k,int deg){ if(is_zero(as)) return Poly(deg,M(0)); shrink(as); int cnt=0; while(as[cnt]==M(0)) cnt++; if(cnt*k>=deg) return Poly(deg,M(0)); as.erase(as.begin(),as.begin()+cnt); deg-=cnt*k; M c=as[0]; Poly zs(cnt*k,M(0)); Poly rs=mul(exp(mul(log(mul(as,c.inv()),deg),M(k)),deg),c.pow(k)); zs.insert(zs.end(),rs.begin(),rs.end()); return pre(zs,deg+cnt*k); } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: formalpowerseries/shift.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::shift(Poly as,M c){ super::init(as.size()+1); int n=as.size(); for(int i=0;i using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "base.cpp" #include "inv.cpp" #undef call_from_test #endif //BEGIN CUT HERE template vector FormalPowerSeries::sqrt(Poly as,int deg){ assert(as[0]==M(1)); M inv2=M(1)/M(2); Poly ss({M(1)}); for(int i=1;i using namespace std; //BEGIN CUT HERE #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b)) < EPS) #define PI 3.141592653589793238 struct Point3D{ double x,y,z; Point3D(){} Point3D(double x,double y,double z):x(x),y(y),z(z){} Point3D operator+(Point3D p) {return Point3D(x+p.x,y+p.y,z+p.z);} Point3D operator-(Point3D p) {return Point3D(x-p.x,y-p.y,z-p.z);} Point3D operator*(double k){return Point3D(x*k,y*k,z*k);} Point3D operator/(double k){return Point3D(x/k,y/k,z/k);} Point3D operator*(Point3D p){ return Point3D(y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x); } double operator^(Point3D p){ return x*p.x+y*p.y+z*p.z; } double norm(){return x*x+y*y+z*z;} double abs(){return sqrt(norm());} bool operator < (const Point3D &p) const{ if(x!=p.x) return x> (istream &is,Point3D &p){ is>>p.x>>p.y>>p.z; return is; } ostream &operator << (ostream &os,Point3D p){ os< Polygon3D; struct Segment3D{ Point3D p1,p2; Segment3D(){} Segment3D(Point3D p1, Point3D p2):p1(p1),p2(p2){} }; typedef Segment3D Line3D; istream &operator >> (istream &is,Segment3D &s){ is>>s.p1>>s.p2; return is; } struct Sphere{ Point3D c; double r; Sphere(){} Sphere(Point3D c,double r):c(c),r(r){} }; istream &operator >> (istream &is,Sphere &c){ is>>c.c>>c.r; return is; } double norm(Vector3D a){ return a.x*a.x+a.y*a.y+a.z*a.z; } double abs(Vector3D a){ return sqrt(norm(a)); } double dot(Vector3D a,Vector3D b){ return a.x*b.x+a.y*b.y+a.z*b.z; } Vector3D cross(Vector3D a,Vector3D b){ return Vector3D(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x); } Point3D project(Line3D l,Point3D p){ Point3D b=l.p2-l.p1; double t=dot(p-l.p1,b)/norm(b); return l.p1+b*t; } Point3D reflect(Line3D l,Point3D p){ return p+(project(l,p)-p)*2.0; } double getDistanceLP(Line3D l,Point3D p){ return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1)); } double getDistanceSP(Segment3D s,Point3D p){ if(dot(s.p2-s.p1,p-s.p1) < 0.0 ) return abs(p-s.p1); if(dot(s.p1-s.p2,p-s.p2) < 0.0 ) return abs(p-s.p2); return getDistanceLP(s,p); } bool intersectSC(Segment3D s,Sphere c){ double d=getDistanceSP(s,c.c); if(d>c.r) return 0; return !((abs(s.p1-c.c)<=c.r) and (abs(s.p2-c.c)<=c.r)); } struct ConvexHull3D{ struct face{ int a,b,c; bool ok; face(){} face(int a,int b,int c,bool ok):a(a),b(b),c(c),ok(ok){} }; int n,num; vector p; vector f; vector > g; ConvexHull3D(int n):n(n),p(n),f(n*8),g(n,vector(n)){} void input(){ for(int i=0;i>p[i]; } double dblcmp(Point3D q,face f){ Point3D m=p[f.b]-p[f.a]; Point3D n=p[f.c]-p[f.a]; Point3D t=q-p[f.a]; return (m*n)^t; } void deal(int q,int a,int b){ int idx=g[a][b]; face add; if(f[idx].ok){ if(dblcmp(p[q],f[idx])>EPS) dfs(q,idx); else{ add=face(b,a,q,1); g[q][b]=g[a][q]=g[b][a]=num; f[num++]=add; } } } void dfs(int q,int now){ f[now].ok=0; deal(q,f[now].b,f[now].a); deal(q,f[now].c,f[now].b); deal(q,f[now].a,f[now].c); } void build(){ num=0; if(n<4) return; bool flg=1; for(int i=1;iEPS){ swap(p[1],p[i]); flg=0; break; } } if(flg) return; flg=1; for(int i=2;iEPS){ swap(p[2],p[i]); flg=0; break; } } if(flg) return; flg=1; for(int i=3;iEPS){ swap(p[3],p[i]); flg=0; break; } } if(flg) return; face add; for(int i=0;i<4;i++){ add=face((i+1)%4,(i+2)%4,(i+3)%4,1); if(dblcmp(p[i],add)>0) swap(add.b,add.c); g[add.a][add.b]=g[add.b][add.c]=g[add.c][add.a]=num; f[num++]=add; } for(int i=4;iEPS){ dfs(i,j); break; } } } int tmp=num; num=0; for(int i=0;i>n){ ConvexHull3D ch(n); ch.input(); ch.build(); cout< using namespace std; #endif //BEGIN CUT HERE // (-pi, pi], atan2(0, 0) = 0 template void argsort(vector

&ps){ auto getA= [&](P p){ if(p.x>=0 and p.y>=0) return 0; if(p.y>=0) return 1; if(p.x<=0) return -2; return -1; }; auto cross=[&](P a,P b){return a.x*b.y-a.y*b.x;}; auto cmp= [&](P a,P b){ if(getA(a)!=getA(b)) return getA(a)0; }; sort(ps.begin(),ps.end(),cmp); } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: geometry/geometry.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE #define equals(a,b) (fabs((a)-(b)) Polygon; struct Segment{ Point p1,p2; Segment(){} Segment(Point p1, Point p2):p1(p1),p2(p2){} }; typedef Segment Line; struct Circle{ Point c; double r; Circle(){} Circle(Point c,double r):c(c),r(r){} }; double norm(Vector a){ return a.x*a.x+a.y*a.y; } double abs(Vector a){ return sqrt(norm(a)); } double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; } double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; } Point orth(Point p){return Point(-p.y,p.x);} bool isOrthogonal(Vector a,Vector b){ return equals(dot(a,b),0.0); } bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){ return isOrthogonal(a1-a2,b1-b2); } bool isOrthogonal(Segment s1,Segment s2){ return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0); } bool isParallel(Vector a,Vector b){ return equals(cross(a,b),0.0); } bool isParallel(Point a1,Point a2,Point b1,Point b2){ return isParallel(a1-a2,b1-b2); } bool isParallel(Segment s1,Segment s2){ return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0); } Point project(Segment s,Point p){ Vector base=s.p2-s.p1; double r=dot(p-s.p1,base)/norm(base); return s.p1+base*r; } Point reflect(Segment s,Point p){ return p+(project(s,p)-p)*2.0; } double arg(Vector p){ return atan2(p.y,p.x); } Vector polar(double a,double r){ return Point(cos(r)*a,sin(r)*a); } // COUNTER CLOCKWISE static const int CCW_COUNTER_CLOCKWISE = 1; static const int CCW_CLOCKWISE = -1; static const int CCW_ONLINE_BACK = 2; static const int CCW_ONLINE_FRONT = -2; static const int CCW_ON_SEGMENT = 0; int ccw(Point p0,Point p1,Point p2){ Vector a = p1-p0; Vector b = p2-p0; if(cross(a,b) > EPS) return CCW_COUNTER_CLOCKWISE; if(cross(a,b) < -EPS) return CCW_CLOCKWISE; if(dot(a,b) < -EPS) return CCW_ONLINE_BACK; if(a.norm()r) return ICC_SEPERATE; if(equals(d+c2.r,c1.r)) return ICC_INSCRIBE; if(d+c2.rEPS) return 0; double d1=abs(c.c-s.p1),d2=abs(c.c-s.p2); if(d1c.r+EPS) or (d1>c.r+EPS and d21u){ if(dot(l.p1-res[0],l.p2-res[0])>0) swap(res[0],res[1]); res.pop_back(); } return res; } Polygon getCrossPointCC(Circle c1,Circle c2){ Polygon p(2); double d=abs(c1.c-c2.c); double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d)); double t=arg(c2.c-c1.c); p[0]=c1.c+polar(c1.r,t+a); p[1]=c1.c+polar(c1.r,t-a); return p; } // IN:2 ON:1 OUT:0 int contains(Polygon g,Point p){ int n=g.size(); bool x=false; for(int i=0;ib.y) swap(a,b); if(a.y < EPS and EPS < b.y and cross(a,b) > EPS ) x = !x; } return (x?2:0); } Polygon andrewScan(Polygon s){ Polygon u,l; if(s.size()<3) return s; sort(s.begin(),s.end()); u.push_back(s[0]); u.push_back(s[1]); l.push_back(s[s.size()-1]); l.push_back(s[s.size()-2]); for(int i=2;i<(int)s.size();i++){ for(int n=u.size(); n>=2 and ccw(u[n-2],u[n-1],s[i])!=CCW_CLOCKWISE; n--){ u.pop_back(); } u.push_back(s[i]); } for(int i=s.size()-3;i>=0;i--){ for(int n=l.size(); n>=2 and ccw(l[n-2],l[n-1],s[i])!=CCW_CLOCKWISE; n--){ l.pop_back(); } l.push_back(s[i]); } reverse(l.begin(),l.end()); for(int i=u.size()-2;i>=1;i--) l.push_back(u[i]); return l; } Polygon convex_hull(Polygon ps){ int n=ps.size(); sort(ps.begin(),ps.end(),sort_y); int k=0; Polygon qs(n*2); for(int i=0;i1 and cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--; qs[k++]=ps[i]; } for(int i=n-2,t=k;i>=0;i--){ while(k>t and cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--; qs[k++]=ps[i]; } qs.resize(k-1); return qs; } double diameter(Polygon s){ Polygon p=s; int n=p.size(); if(n==2) return abs(p[0]-p[1]); int i=0,j=0; for(int k=0;k0) swap(p[0],p[1]); return Line(p[0],p[1]); } Vector translate(Vector v,double theta){ Vector res; res.x=cos(theta)*v.x-sin(theta)*v.y; res.y=sin(theta)*v.x+cos(theta)*v.y; return res; } vector corner(Line l1,Line l2){ vector res; if(isParallel(l1,l2)){ double d=getDistanceLP(l1,l2.p1)/2.0; Vector v1=l1.p2-l1.p1; v1=v1/v1.abs()*d; Point p=l2.p1+translate(v1,90.0*(PI/180.0)); double d1=getDistanceLP(l1,p); double d2=getDistanceLP(l2,p); if(fabs(d1-d2)>d){ p=l2.p1+translate(v1,-90.0*(PI/180.0)); } res.push_back(Line(p,p+v1)); }else{ Point p=getCrossPointLL(l1,l2); Vector v1=l1.p2-l1.p1,v2=l2.p2-l2.p1; v1=v1/v1.abs(); v2=v2/v2.abs(); res.push_back(Line(p,p+(v1+v2))); res.push_back(Line(p,p+translate(v1+v2,90.0*(PI/180.0)))); } return res; } Polygon tangent(Circle c1,Point p2){ Circle c2=Circle(p2,sqrt(norm(c1.c-p2)-c1.r*c1.r)); Polygon p=getCrossPointCC(c1,c2); sort(p.begin(),p.end()); return p; } vector tangent(Circle c1,Circle c2){ vector ls; if(c1.r=-1;s-=2){ double h=(c1.r+s*c2.r)/sqrt(g); if(equals(1-h*h,0)){ ls.emplace_back(c1.c+u*c1.r,c1.c+(u+v)*c1.r); }else if(1-h*h>0){ Point uu=u*h,vv=v*sqrt(1-h*h); ls.emplace_back(c1.c+(uu+vv)*c1.r,c2.c-(uu+vv)*c2.r*s); ls.emplace_back(c1.c+(uu-vv)*c1.r,c2.c-(uu-vv)*c2.r*s); } } return ls; } double closest_pair(Polygon &a,int l=0,int r=-1){ if(r<0){ r=a.size(); sort(a.begin(),a.end(),sort_x); } if(r-l<=1) return abs(a[0]-a[1]); int m=(l+r)>>1; double x=a[m].x; double d=min(closest_pair(a,l,m),closest_pair(a,m,r)); inplace_merge(a.begin()+l,a.begin()+m,a.begin()+r,sort_y); Polygon b; for(int i=l;i=d) continue; for(int j=0;j<(int)b.size();j++){ double dy=a[i].y-next(b.rbegin(),j)->y; if(dy>=d) break; d=min(d,abs(a[i]-*next(b.rbegin(),j))); } b.emplace_back(a[i]); } return d; } vector> segmentArrangement(vector &ss, Polygon &ps){ int n=ss.size(); for(int i=0;i > G(ps.size()); for(int i=0;i > ls; for(int j=0;j<(int)ps.size();j++) if(getDistanceSP(ss[i],ps[j]) ss,const int INF){ const int BTM = 0; const int LFT = 1; const int RGH = 2; const int TOP = 3; int n=ss.size(); vector ep; for(int i=0;iss[i].p2.x) swap(ss[i].p1,ss[i].p2); ep.emplace_back(ss[i].p1,i,LFT); ep.emplace_back(ss[i].p2,i,RGH); }else{ if(ss[i].p1.y>ss[i].p2.y) swap(ss[i].p1,ss[i].p2); ep.emplace_back(ss[i].p1,i,BTM); ep.emplace_back(ss[i].p2,i,TOP); } } sort(ep.begin(),ep.end()); set bt; bt.insert(INF); int cnt=0; for(int i=0;i dfs= [&](Circle c,Point a,Point b){ Vector va=c.c-a,vb=c.c-b; double f=cross(va,vb),res=0; if(equals(f,0.0)) return res; if(max(abs(va),abs(vb))c.r-EPS) return c.r*c.r*atan2(d.y,d.x); auto u=getCrossPointCS(c,Segment(a,b)); if(u.empty()) return res; if(u.size()>1u and dot(u[1]-u[0],a-u[0])>0) swap(u[0],u[1]); u.emplace(u.begin(),a); u.emplace_back(b); for(int i=1;i<(int)u.size();i++) res+=dfs(c,u[i-1],u[i]); return res; }; double res=0; for(int i=0;i<(int)ps.size();i++) res+=dfs(c,ps[i],ps[(i+1)%ps.size()]); return res/2; } } using namespace geometry; namespace geometry{ istream &operator>>(istream &is,Point &p){ is>>p.x>>p.y; return is; } istream &operator>>(istream &is,Polygon &p){ for(int i=0;i<(int)p.size();i++) is>>p[i]; return is; } istream &operator>>(istream &is,Segment &s){ is>>s.p1>>s.p2; return is; } istream &operator>>(istream &is,Circle &c){ is>>c.c>>c.r; return is; } ostream &operator<<(ostream &os,Point p){ os< using namespace std; #endif //BEGIN CUT HERE // throw from origin to (x,y) with verocity v (x>0) // g: gravity template vector< pair > projectile_motion(D v,D g,D x,D y){ D a=x*x+y*y; D b=g*x*x*y-v*v*x*x; D c=g*g*x*x*x*x/4; if(b*b<4*a*c) return {}; vector< pair > res; { D p=(-b+sqrt(b*b-4*a*c))/(2*a); if(0

using namespace std; #define call_from_test #include "stronglyconnectedcomponent.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Arborescence{ struct edge{ int to; T cost; edge(int to,T cost):to(to),cost(cost){} }; vector> B; Arborescence(int n):B(n){} void add_edge(int u,int v,T cost){ assert(u!=v); B[u].emplace_back(v,cost); } T build(int r){ T res=0; auto G=B; const T INF = numeric_limits::max()/2; while(1){ int n=G.size(); vector ws(n,INF); vector rs(n,-1); for(int v=0;v> H(m); for(int v=0;v using namespace std; #endif //BEGIN CUT HERE template struct Arborescence{ struct SkewHeap{ using P = pair; const P INF; const T add_identity; SkewHeap(T inf):INF(inf,-1),add_identity(0){} struct Node{ Node *l,*r; P val; T add; Node(P val,T add):val(val),add(add){l=r=nullptr;} }; P reflect(P x,T y){return P(x.first+y,x.second);} void eval(Node *a){ if(a==nullptr) return; if(a->add==add_identity) return; if(a->l) a->l->add+=a->add; if(a->r) a->r->add+=a->add; a->val=reflect(a->val,a->add); a->add=add_identity; } P top(Node *a){ return a?reflect(a->val,a->add):INF; } P snd(Node *a){ eval(a); return a?min(top(a->l),top(a->r)):INF; } Node* add(Node *a,T d){ if(a) a->add+=d; return a; } Node* push(T v,int i){ return new Node(P(v,i),add_identity); } Node* meld(Node *a,Node *b){ if(!a or !b) return a?a:b; if(top(b)r=meld(a->r,b); swap(a->l,a->r); return a; } Node* pop(Node* a){ eval(a); auto res=meld(a->l,a->r); delete a; return res; } }; struct UnionFind{ vector r,p; UnionFind(int sz):r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);} int find(int x){ return (x==p[x]?x:p[x]=find(p[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; r[x]+=r[y]; p[y]=x; } }; struct edge{ int from,to; T cost; edge(int from,int to,T cost):from(from),to(to),cost(cost){} }; int n; vector es; Arborescence(int n):n(n){}; void add_edge(int from,int to,T cost){ es.emplace_back(from,to,cost); } T build(int r){ UnionFind uf(n); const T INF = numeric_limits::max()/2; SkewHeap hp(INF); vector come(n,nullptr); vector used(n,0),from(n,-1); vector cost(n,-1); used[r]=2; for(int i=0;i<(int)es.size();i++){ edge &e=es[i]; come[e.to]=hp.meld(come[e.to],hp.push(e.cost,i)); } T res=0; for(int i=0;i l; while(used[v]!=2){ used[v]=1; l.emplace_back(v); if(!come[v]) return T(-1); from[v]=uf.find(es[come[v]->val.second].from); cost[v]=hp.top(come[v]).first; come[v]=hp.pop(come[v]); if(from[v]==v) continue; res+=cost[v]; if(used[from[v]]==1){ int p=v; do{ if(come[p]!=nullptr) hp.add(come[p],-cost[p]); if(p!=v){ uf.unite(v,p); come[v]=hp.meld(come[v],come[p]); } p=uf.find(from[p]); }while(p!=v); }else{ v=from[v]; } } for(int u:l) used[u]=2; } return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed UVA_11183(){ using ll = long long; int T; cin>>T; for(int t=1;t<=T;t++){ int n,m; cin>>n>>m; Arborescence G(n); for(int i=0;i>s>>t>>w; G.add_edge(s,t,w); } ll ans=G.build(0); cout<<"Case #"< using namespace std; #endif //BEGIN CUT HERE template struct BellmanFord{ struct edge{ int u,v; T w; edge(int u,int v,T w):u(u),v(v),w(w){} }; vector< vector > G; vector used,reach; BellmanFord(int n):G(n),used(n,0),reach(n,1){} vector es; void add_edge(int u,int v,T c){ es.emplace_back(u,v,c); G[u].emplace_back(v); } vector build(int from,int &neg_loop){ const T INF = numeric_limits::max(); int n=G.size(); vector ds(n,INF); ds[from]=0; for(int j=0;jds[e.u]+e.w){ ds[e.v]=ds[e.u]+e.w; update=1; } } if(!update) break; if(j==n-1){ neg_loop=1; return ds; } } neg_loop=0; return ds; } void dfs(int v){ if(used[v]) return; used[v]=1; for(int u:G[v]) dfs(u); } T shortest_path(int from,int to,int &neg_loop){ int n=G.size(); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE vector bfs(int s,vector< vector > G){ int n=G.size(); vector dp(n,-1); queue que; dp[s]=0; que.emplace(s); while(!que.empty()){ int v=que.front();que.pop(); for(int u:G[v]){ if(~dp[u]) continue; dp[u]=dp[v]+1; que.emplace(u); } } return dp; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: graph/bipartitedecomposition.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // O(n) struct BipartiteDecomposition{ vector> G; BipartiteDecomposition(int n):G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } vector> build(){ vector> res; vector used(G.size(),-1); for(int i=0;i<(int)G.size();i++){ if(~used[i]) continue; queue que; used[i]=0; que.emplace(i); pair cnt; while(!que.empty()){ int v=que.front();que.pop(); if(used[v]==0) cnt.first++; else cnt.second++; for(int u:G[v]){ if(~used[u]){ if(used[u]==used[v]) return {}; continue; } used[u]=used[v]^1; que.emplace(u); } } res.emplace_back(cnt); } return res; } }; //END CUT HERE #ifndef call_from_test int main(){ return 0; } #endif ================================================ FILE: graph/chromatic.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE int chromatic(vector< vector > G){ int n=G.size(); if(n==0) return 0; assert(n<=30); vector es(n,0); for(int i=0;i dp(s); for(int b=0;b res(s); res[0]=1; for(int b=1;b=MOD) res[b]-=MOD; } return res; }; constexpr int MOD1 = 1077563119; constexpr int MOD2 = 1e9+7; vector ind1=calc(MOD1); vector ind2=calc(MOD2); using ll = long long; vector dp1=dp,dp2=dp; for(int i=1;i using namespace std; #endif //BEGIN CUT HERE template struct Cycle{ vector used; vector> G; Cycle(int n_):used(n_,0),G(n_){} void add_edge(int u,int v){ G[u].emplace_back(v); if(not directed) G[v].emplace_back(u); } vector vs; int dfs(int v,int p){ used[v]=1; vs.emplace_back(v); for(int u:G[v]){ if((not directed) and u==p) continue; if(used[u]==2) continue; if(used[u]==1) return u; int res=dfs(u,v); if(~res) return res; } used[v]=2; vs.pop_back(); return -1; } vector build(){ for(int i=0;i<(int)G.size();i++){ if(used[i]) continue; int start=dfs(i,-1); if(start<0) continue; vs.erase(vs.begin(),find(vs.begin(),vs.end(),start)); return vs; } return {}; } }; using DirectedCycle = Cycle; using UndirectedCycle = Cycle; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: graph/dijkstra.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Dijkstra{ struct Edge{ int to; T cost; Edge(int to,T cost):to(to),cost(cost){} bool operator<(const Edge &o)const{return cost>o.cost;} }; vector< vector > G; vector ds; vector bs; Dijkstra(int n):G(n){} void add_edge(int u,int v,T c){ G[u].emplace_back(v,c); } void build(int s){ int n=G.size(); ds.assign(n,numeric_limits::max()); bs.assign(n,-1); priority_queue pq; ds[s]=0; pq.emplace(s,ds[s]); while(!pq.empty()){ auto p=pq.top();pq.pop(); int v=p.to; if(ds[v]ds[v]+e.cost){ ds[e.to]=ds[v]+e.cost; bs[e.to]=v; pq.emplace(e.to,ds[e.to]); } } } } T operator[](int k){return ds[k];} vector restore(int to){ vector res; if(bs[to]<0) return res; while(~to) res.emplace_back(to),to=bs[to]; reverse(res.begin(),res.end()); return res; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: graph/dominatortree.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct DominatorTree{ struct UnionFind{ vector ; vector ps,ms; UnionFind(vector &semi): semi(semi),ps(semi.size()),ms(semi.size()){ iota(ps.begin(),ps.end(),0); iota(ms.begin(),ms.end(),0); } int find(int v){ if(ps[v]==v) return v; int r=find(ps[v]); if(semi[ms[v]]>semi[ms[ps[v]]]) ms[v]=ms[ps[v]]; return ps[v]=r; } int eval(int v){ find(v); return ms[v]; } void link(int p,int v){ps[v]=p;} }; vector< vector > G,R; vector ord,par,idom,semi; DominatorTree(int n): G(n),R(n),par(n),idom(n,-1),semi(n,-1){ ord.reserve(n); } void add_edge(int u,int v){ G[u].emplace_back(v); R[v].emplace_back(u); } void dfs(int v){ semi[v]=ord.size(); ord.emplace_back(v); for(int u:G[v]){ if(~semi[u]) continue; par[u]=v; dfs(u); } } void build(int rt){ int n=G.size(); dfs(rt); vector< vector > bkt(n); UnionFind uf(semi); vector us(n); for(int i=(int)ord.size()-1;i>=0;i--){ int v=ord[i]; for(int u:R[v]){ if(semi[u]<0) continue; u=uf.eval(u); if(semi[v]>semi[u]) semi[v]=semi[u]; } bkt[ord[semi[v]]].emplace_back(v); for(int u:bkt[par[v]]) us[u]=uf.eval(u); bkt[par[v]].clear(); uf.link(par[v],v); } for(int i=1;i<(int)ord.size();i++){ int v=ord[i],u=us[v]; idom[v]=(semi[v]==semi[u]?semi[v]:idom[u]); } for(int i=1;i<(int)ord.size();i++){ int v=ord[i]; idom[v]=ord[idom[v]]; } idom[rt]=rt; } int operator[](int k){return idom[k];} }; //END CUT HERE #ifndef call_from_test int main(){ return 0; } #endif ================================================ FILE: graph/dynamicconnectivity.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct PersistentUnionFind{ using T = pair; vector rs,ps; stack st; PersistentUnionFind(int n): rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);} int find(int x){ return x==ps[x]?ps[x]:find(ps[x]); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); st.emplace(-1,-1); if(x==y) return; if(rs[x]; using range = pair; int q; PersistentUnionFind puf; vector< vector > edges; vector > prc; map cnt,app; DynamicConnectivity(int n,int q_):q(1),puf(n){ while(q>1; add(a,b,e,(k<<1)|0,l,m); add(a,b,e,(k<<1)|1,m,r); } void add(range r,edge e){ add(r.first,r.second,e,1,0,q); } void build(){ for(auto &e:cnt){ if(!e.second) continue; prc.emplace_back(range(app[e.first],q),e.first); } for(auto &s:prc) add(s.first,s.second); } template void exec(const F &f,int k=1){ for(auto &e:edges[k]) puf.unite(e.first,e.second); if(k using namespace std; //BEGIN CUT HERE // size of minimum cycle in undirected graph int girth(vector< vector > G){ int n=G.size(); int res=n+1; vector dp(n),pr(n); for(int s=0;s que; dp[s]=0; que.emplace(s); while(!que.empty()){ int v=que.front();que.pop(); if(res<=dp[v]*2) break; for(int u:G[v]){ if(u==pr[v]) continue; if(~dp[u]){ res=min(res,dp[u]+dp[v]+1); continue; } dp[u]=dp[v]+1; pr[u]=v; que.emplace(u); } } } if(res>n) res=-1; return res; } //END CUT HERE //INSERT ABOVE HERE signed CFR580_B(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector as(n); for(int i=0;i>as[i]; sort(as.rbegin(),as.rend()); if(as[0]==0){ cout<<-1<=200){ cout<<3< > G(n); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct Grid{ const int h,w; const F f; Grid(int h_,int w_,F f_):h(h_),w(w_),f(f_){} int idx(int y,int x){return y*w+x;} using T = typename invoke_result::type; T operator[](int k){return f(k/w,k%w);} decltype(auto) edges(){ vector> es; for(int i=0;i using namespace std; #endif //BEGIN CUT HERE struct IndependentSet{ int n; vector deg,used,dead,pre,ans; vector > G; IndependentSet(int n): n(n),deg(n),used(n,0),dead(n,0),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } int res,cnt,alive; void dfs(){ if(cnt+alive<=res) return; int v=-1; for(int i=0;i using namespace std; #define call_from_test #include "../datastructure/unionfind.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct Kruskal : UnionFind{ using UnionFind::UnionFind; struct Edge{ int src,dst; T cost; int used; Edge(int src,int dst,T cost): src(src),dst(dst),cost(cost),used(0){} bool operator<(const Edge& o) const{ return cost es; void add_edge(int u,int v,T c){ es.emplace_back(u,v,c); } T build(){ sort(es.begin(),es.end()); T res=0; for(auto &e:es){ if(same(e.src,e.dst)) continue; res+=e.cost; unite(e.src,e.dst); e.used=1; } return res; } }; //END CUT HERE #ifndef call_from_test int main(){ return 0; } #endif ================================================ FILE: graph/lowlink.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct LowLink{ int n,pos; vector ord,low,par,blg,num; vector > G,C,T; vector > > E; vector ap; vector > bs,cand; LowLink(int n):n(n),pos(0),ord(n,-1),low(n), par(n,-1),blg(n,-1),num(n,1),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } bool is_bridge(int u,int v){ if(ord[u]>ord[v]) swap(u,v); return ord[u]=ord[v]){ E.emplace_back(); while(1){ auto e=cand.back(); cand.pop_back(); E.back().emplace_back(e); if(make_pair(min(u,v),max(u,v))==e) break; } } } } void fill_component(int v){ C[blg[v]].emplace_back(v); for(int u:G[v]){ if(~blg[u] or is_bridge(u,v)) continue; blg[u]=blg[v]; fill_component(u); } } void add_component(int v,int &k){ if(~blg[v]) return; blg[v]=k++; C.emplace_back(); fill_component(v); } int build(){ for(int i=0;i cnt(n,0); for(int i=0;i1) ap.emplace_back(i); sort(ap.begin(),ap.end()); ap.erase(unique(ap.begin(),ap.end()),ap.end()); int k=0; for(int i=0;i()); for(auto e:bs){ int u=blg[e.first],v=blg[e.second]; T[u].emplace_back(v); T[v].emplace_back(u); } return k; } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "../datastructure/unionfind.cpp" #include "../mod/mint.cpp" #include "../combinatorics/enumeration.cpp" #undef call_from_test //INSERT ABOVE HERE // test num signed ARC045_D(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector xs(2*n+1),ys(2*n+1); for(int i=0;i<2*n+1;i++) cin>>xs[i]>>ys[i]; vector > R(2*n+2),C(2*n+2); for(int i=0;i<2*n+1;i++) R[xs[i]].emplace_back(i); for(int i=0;i<2*n+1;i++) C[ys[i]].emplace_back(i); UnionFind uf(2*n+1); for(auto &v:R) for(auto u:v) uf.unite(v[0],u); for(auto &v:C) for(auto u:v) uf.unite(v[0],u); vector vs; for(int i=0;i<2*n+1;i++){ if(uf.find(i)!=i) continue; if(uf.size(i)&1) vs.emplace_back(i); } assert(!vs.empty()); if(vs.size()>1u){ for(int i=0;i<2*n+1;i++) cout<<"NG\n"; cout<void{ for(auto &v:V){ if(v.empty()) continue; if(!uf.same(vs[0],v[0])) continue; if(v.size()>0u) for(auto u:v) G.add_edge(v[0],u); if(v.size()>1u) for(auto u:v) G.add_edge(v[1],u); } }; add_edge(R); add_edge(C); G.build(); auto ap=G.ap; vector ans(2*n+1,0); for(int i=0;i<2*n+1;i++) if(uf.same(vs[0],i)) ans[i]=1; for(int v:ap){ if(!uf.same(vs[0],v)) continue; for(int u:G.G[v]){ if(G.par[u]!=v) continue; if(~G.par[v] and G.ord[v]>G.low[u]) continue; if(G.num[u]&1) ans[v]=0; } } for(int i=0;i<2*n+1;i++) cout<<(ans[i]?"OK\n":"NG\n"); cout<>n>>m>>k; using P = pair; map idx; LowLink G(n); for(int i=0;i>a>>b; a--;b--; G.add_edge(a,b); idx[P(a,b)]=idx[P(b,a)]=i; } G.build(); UnionFind uf(m); for(auto vs:G.E) for(auto p:vs) uf.unite(idx[p],idx[vs[0]]); vector> cnt(m); for(auto vs:G.E){ for(auto p:vs){ cnt[uf.find(idx[p])].emplace(p.first); cnt[uf.find(idx[p])].emplace(p.second); } } using M = Mint; using E = Enumeration; E::init(1000); auto calc1= [&](int x)->M{ M res{0}; for(int i=0;i (int)cnt[i].size()) ans*=E::H(uf.size(i),k); } cout< using namespace std; #endif //BEGIN CUT HERE template vector> manhattanmst(vector xs,vector ys){ using P = pair; vector

es; int n=xs.size(); // xs[i] <- xs[i] + \eps^i, ys[i] <- ys[i] + \eps^(n+i), for(int s=0;s<2;s++){ for(int t=0;t<2;t++){ vector ord(n); iota(ord.begin(),ord.end(),0); auto cmp=[&](int i,int j)->bool{ if(xs[i]+ys[i]!=xs[j]+ys[j]) return xs[i]+ys[i]j); }; sort(ord.begin(),ord.end(),cmp); map, int> idx; for(int i:ord){ for(auto it=idx.lower_bound({-ys[i],(s&t)?+i:-i}); it!=idx.end();it=idx.erase(it)){ int j=it->second; if(xs[i]-xs[j] using namespace std; #endif //BEGIN CUT HERE // no muliple edge template bool hasMultipleEulerianTrail(Graph &G){ int n=G.size(); vector ind(n,0),outd(n,0),pre(n,-1),loop(n,0); for(int v=0;v=3 or outd[i]>=3) return true; if(ind[i]outd[i]) en=i; if(ind[i]+outd[i]) sz++; } if(sz<2) return false; if(st<0) return true; while(ind[en]==1+loop[en] and st!=en) en=pre[en]; if(st==en) return false; queue que; vector rs(n,0); que.emplace(st); rs[st]=1; while(!que.empty()){ int v=que.front();que.pop(); for(int u:G[v]){ if(u==en or rs[u]) continue; rs[u]=1; que.emplace(u); } } vector us(n,0); que.emplace(en); us[en]=1; while(!que.empty()){ int v=que.front();que.pop(); if(rs[v]) return true; for(int u:G[v]){ if(u==en or us[u]) continue; us[u]=1; que.emplace(u); } } return false; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE #endif ================================================ FILE: graph/nicetree.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct NiceTree{ vector< vector > G; vector< set > ex; vector buff; NiceTree(int n):G(n),ex(n),buff(n){} void add_edge(int u,int v){ if(u>v) swap(u,v); if(ex[u].count(v)) return; G[u].emplace_back(v); G[v].emplace_back(u); ex[u].emplace(v); } enum Type{LEAF, JOIN, INTRODUCE, FORGET}; struct Node{ int type,is_root; Node():type(-1),is_root(1){} // index for G vector bag; void add_vertex(int v){bag.emplace_back(v);} // index for T vector child; void add_child(int v){child.emplace_back(v);} }; vector T; void to_nice(){ for(auto &vs:T){ sort(vs.bag.begin(),vs.bag.end()); for(int c:vs.child) T[c].is_root=0; } stack st; for(int i=0;i<(int)T.size();i++) if(T[i].is_root) st.emplace(i); while(!st.empty()){ int v=st.top();st.pop(); while(T[v].child.size()>2){ Node r; r.add_child(T[v].child.back()); T[v].child.pop_back(); r.add_child(T[v].child.back()); T[v].child.pop_back(); r.bag=T[v].bag; T[v].add_child(T.size()); T.emplace_back(r); } if(T[v].child.size()==2){ for(auto &u:T[v].child){ if(T[u].bag!=T[v].bag){ Node r; r.add_child(u); r.bag=T[v].bag; u=T.size(); T.emplace_back(r); } } T[v].type=JOIN; } if(T[v].child.size()==1){ int &u=T[v].child[0]; vector latte,malta; auto &ps=T[v].bag; auto &qs=T[u].bag; set_difference(ps.begin(),ps.end(),qs.begin(),qs.end(), back_inserter(latte)); set_difference(qs.begin(),qs.end(),ps.begin(),ps.end(), back_inserter(malta)); if(latte.size()+malta.size()>1){ Node r; r.add_child(u); r.bag=T[v].bag; if(!latte.empty()){ r.bag.erase(find(r.bag.begin(),r.bag.end(),latte.back())); }else{ r.bag.emplace_back(malta.back()); } u=T.size(); T.emplace_back(r); } if(T[v].bag.size()T[u].bag.size()) T[v].type=INTRODUCE; } if(T[v].child.empty()){ if(T[v].bag.size()>1){ Node r; r.bag=T[v].bag; r.bag.pop_back(); T[v].type=INTRODUCE; T[v].add_child(T.size()); T.emplace_back(r); }else{ T[v].type=LEAF; } } for(auto &u:T[v].child) st.emplace(u); } for(auto &vs:T) for(int c:vs.child) T[c].is_root=0; } // root = 0 (if connected) void build(){ int n=G.size(); if(n<=3){ Node r; for(int i=0;i({r}); return to_nice(); } vector deg(n); queue que; for(int i=0;i used(n,-1); T.emplace_back(); while(!que.empty()){ int v=que.front();que.pop(); if(deg[v]>2 or used[v]!=-1) continue; Node r; r.add_vertex(v); int p=-1,q=-1; for(int u:G[v]){ if(used[u]==-1){ (p==-1?p:q)=u; r.add_vertex(u); }else if(used[u]>=0){ r.add_child(used[u]); used[u]=-2; } } if(deg[v]==0){ used[v]=T.size(); T.emplace_back(r); continue; } if(q==-1){ deg[p]--; }else{ if(p>q) swap(p,q); if(!ex[p].count(q)){ add_edge(p,q); }else{ deg[p]--; deg[q]--; } } for(int u:G[v]) if(deg[u]<=2) que.emplace(u); deg[v]=0; used[v]=T.size(); T.emplace_back(r); } for(int i=0;i0){ T={}; return; } } T.front()=T.back();T.pop_back(); to_nice(); } template void dfs(int v,F1 &leaf,F2 &join,F3 &introduce,F4 &forget){ const auto &chd=T[v].child; for(int u:chd) dfs(u,leaf,join,introduce,forget); if(T[v].type==LEAF){ leaf(v); return; } if(T[v].type==JOIN){ join(v); return; } const auto &bag=T[v].bag; for(int i=0;i<(int)bag.size();i++) buff[bag[i]]=1<>n>>m; NiceTree G(n); using P = pair; set

es; for(int i=0;i>a>>b; a--;b--; G.add_edge(a,b); es.emplace(a,b); es.emplace(b,a); } G.build(); auto &T=G.T; auto &buff=G.buff; vector< vector > dps(T.size()); const int INF = 1e9; auto base= [&](int v){ const auto &bag=T[v].bag; auto &dp=dps[v]; dp.assign(1<>j)&1) continue; bit|=buff[chd_bag[j]]; valid&=!es.count(P(chd_bag[j],add)); } assert(!(bit&buff[add])); if(valid) chmax(dp[bit|buff[add]],pr[i]+1); chmax(dp[bit],pr[i]); } }; auto forget= [&](int v,int rmv){ base(v); const auto &chd=T[v].child; const auto &chd_bag=T[chd[0]].bag; const auto &pr=dps[chd[0]]; auto &dp=dps[v]; for(int i=0;i<(int)pr.size();i++){ int bit=0; for(int j=0;j<(int)chd_bag.size();j++){ if((~i>>j)&1) continue; if(rmv!=chd_bag[j]) bit|=buff[chd_bag[j]]; } chmax(dp[bit],pr[i]); } }; int ans=n; for(int i=0;i<(int)T.size();i++){ if(!T[i].is_root) continue; G.dfs(i,leaf,join,introduce,forget); ans-=*max_element(dps[i].begin(),dps[i].end()); } cout< using namespace std; #endif // https://lorent-kyopro.hatenablog.com/entry/2020/07/24/170656 //BEGIN CUT HERE struct RangeToRange{ const int n; int ptr; RangeToRange(int n):n(n),ptr(3*n){} // (0n, 2n) : top segtree (to) // (2n, 4n) : bottom segtree (from) // map [3n, 4n) -> [n, 2n) template void add_edge(int u,int v,F f){ if(3*n<=u and u<4*n) u-=2*n; f(u,v); } template void init(F f){ for(int i=1;i [l2, r2) template void add_edge(int l1,int r1,int l2,int r2,F f,G g){ int k=ptr++; for(l1+=n,r1+=n;l1>=1,r1>>=1){ if(l1&1) add_edge(2*n+(l1++),k,f); if(r1&1) add_edge(2*n+(--r1),k,f); } for(l2+=n,r2+=n;l2>=1,r2>>=1){ if(l2&1) g(k,l2++); if(r2&1) g(k,--r2); } } int idx(int v)const{return 1*n+v;} size_t size()const{return ptr;} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: graph/semikernel.cpp ================================================ #include using namespace std; //BEGIN CUT HERE // https://link.springer.com/content/pdf/10.1007%2FBFb0066192.pdf struct SemiKernel{ int n; vector > G,R; vector used,dp,S; SemiKernel(int n):n(n),G(n),R(n),used(n,0),dp(n){} void add_edge(int u,int v){ G[u].emplace_back(v); R[v].emplace_back(u); } void dfs(int v){ if(v==n) return; if(used[v]){ dfs(v+1); return; } used[v]=1; for(int u:G[v]) used[u]=1; dfs(v+1); dp[v]=1; for(int u:R[v]) dp[v]&=!dp[u]; if(dp[v]) S.emplace_back(v); } vector build(){ dfs(0); reverse(S.begin(),S.end()); return S; } }; //END CUT HERE //INSERT ABOVE HERE signed CFR503_C(){ int n,m; scanf("%d %d",&n,&m); SemiKernel sk(n); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE struct SCC{ vector< vector > G,R,H,C; vector vs,used,blg; SCC(int n):G(n),R(n),used(n),blg(n){} void add_edge(int u,int v){ G[u].emplace_back(v); R[v].emplace_back(u); } void dfs(int v){ used[v]=1; for(int u:G[v]) if(!used[u]) dfs(u); vs.emplace_back(v); } void rdfs(int v,int k){ used[v]=1; blg[v]=k; C[k].emplace_back(v); for(int u:R[v]) if(!used[u]) rdfs(u,k); } int build(bool uniq=true){ int n=G.size(); for(int v=0;v=0;i--){ if(!used[vs[i]]){ H.emplace_back(); C.emplace_back(); rdfs(vs[i],k++); } } for(int v=0;v using namespace std; #endif //BEGIN CUT HERE struct TopologicalSort{ vector> G; vector indeg; TopologicalSort(int n):G(n),indeg(n,0){} void add_edge(int s,int t){ G[s].emplace_back(t); indeg[t]++; } vector build(){ int n=G.size(); queue que; vector used(n,0); auto push=[&](int v){ if(used[v]) return; que.emplace(v); used[v]=1; }; for(int i=0;i ps; while(!que.empty()){ int v=que.front();que.pop(); ps.emplace_back(v); for(int u:G[v]){ indeg[u]--; if(indeg[u]==0) push(u); } } if(n!=(int)ps.size()) return {}; return ps; } }; //END CUT HERE #ifndef call_from_test #endif ================================================ FILE: graph/triangle.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct Triangle{ // if not simple, use vector> vector> G; Triangle(int n):G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } template void build(F f){ int n=G.size(); using P = pair; vector

vp(n); for(int i=0;i> H(n); for(int i=0;ivp[j]) H[i].emplace_back(j); vector used(n,0); // x->y->z for(int x=0;x using namespace std; #endif //BEGIN CUT HERE // work with multigraph struct TwoEdgeConnectedComponents{ vector ord,low,par,blg,sz; vector> G,C; TwoEdgeConnectedComponents(int n): ord(n,-1),low(n),par(n,-1),blg(n,-1),sz(n,1),G(n){} void add_edge(int u,int v){ if(u==v) return; G[u].emplace_back(v); G[v].emplace_back(u); } bool is_bridge(int u,int v){ if(ord[u]>ord[v]) swap(u,v); return ord[u]& operator[](int i)const{return C[i];} vector> forest(){ int n=G.size(),k=C.size(); vector> T(k); for(int v=0;v using namespace std; #define call_from_test #include "stronglyconnectedcomponent.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct TwoSat{ int n; SCC scc; TwoSat(int n):n(n),scc(n*2){} int negate(int v){return (n+v)%(n*2);} void add_if(int u,int v){ // u -> v <=> !v -> !u scc.add_edge(u,v); scc.add_edge(negate(v),negate(u)); } void add_or(int u,int v){ // u or v <=> !u -> v add_if(negate(u),v); } void add_nand(int u,int v){ // u nand v <=> u -> !v add_if(u,negate(v)); } void set_true(int v){ // v <=> !v -> v scc.add_edge(negate(v),v); } void set_false(int v){ // !v <=> v -> !v scc.add_edge(v,negate(v)); } vector build(){ scc.build(); vector res(n); for(int i=0;iscc[n+i]; } return res; } }; //END CUT HERE #ifndef call_from_test // test add_if, set_true, set_false signed CFR441_C(){ int n,m; scanf("%d %d",&n,&m); vector> G(n); for(int i=0;i &as,vector &bs){ int x=min(as.size(),bs.size()); int i; for(i=0;ibs.size())) NG(); }; for(int i=0;i+1 ans; for(int i=0;i>n; vector u(n); for(int i=0;i>u[i]; auto NO=[](){cout<<"Impossible"<=100) NO(); TwoSat ts(n); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct VoronoiMST{ int n; using E = pair; using P = pair; vector > G; VoronoiMST(vector &x){ n=x.size(); G.assign(n<<1,vector()); for(int i=0;i > build(){ priority_queue, greater

> pq; const T INF = numeric_limits::max(); vector dist(n<<1,INF); vector from(n<<1,-1); for(int i=0;i > H(n); for(int v=0;v<(n<<1);v++){ for(E e:G[v]){ int u=e.first; T c=e.second; if(from[v]==from[u]) continue; int x=from[v],y=from[u]; T z=dist[v]+dist[u]+c; H[x].emplace_back(y,z); H[y].emplace_back(x,z); } } return H; } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "kruskal.cpp" #undef call_from_test //INSERT ABOVE HERE signed CF17FINAL_J(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector x(n); for(int i=0;i>x[i]; VoronoiMST vo(x); for(int i=1;i>a>>b>>c; a--;b--; vo.add_edge(a,b,c); } auto G=vo.build(); Kruskal ks(n); for(int v=0;v using namespace std; /** * @ignore */ //BEGIN CUT HERE using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; // AtCoder const i64 CYCLES_PER_SEC = 2800000000; struct Timer { i64 start; Timer(){reset();} void reset(){start=getCycle();} inline double get(){return (double)(getCycle()-start)/CYCLES_PER_SEC;} inline i64 getCycle(){ u32 low,high; __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high)); return ((i64)low)|((i64)high<<32); } }; Timer timer; //END CUT HERE //INSERT ABOVE HERE void nxt(){ static i64 x = 0; static i64 y = 1; x=(x<<10)+y; y=x/3; } signed main(){ cout< using namespace std; /** * @ignore */ //BEGIN CUT HERE uint32_t xor128(){ static uint32_t x = 123456789; static uint32_t y = 362436069; static uint32_t z = 521288629; static uint32_t w = 88675123; uint32_t t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } //END CUT HERE //INSERT ABOVE HERE signed main(){ return 0; } ================================================ FILE: includes/formalpowerseries.h ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE #define call_from_test #include "../mod/mint.cpp" #include "../combinatorics/enumeration.cpp" #include "../formalpowerseries/base.cpp" #include "../formalpowerseries/inv.cpp" #include "../formalpowerseries/div.cpp" #include "../formalpowerseries/mod.cpp" #include "../formalpowerseries/sqrt.cpp" #include "../formalpowerseries/diff.cpp" #include "../formalpowerseries/integral.cpp" #include "../formalpowerseries/log.cpp" #include "../formalpowerseries/exp.cpp" #include "../formalpowerseries/pow.cpp" #include "../formalpowerseries/shift.cpp" #undef call_from_test //END CUT HERE ================================================ FILE: io/precision.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct Precision{ Precision(){ cout< using namespace std; #endif //BEGIN CUT HERE template vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: io/space.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template void space(const vector &vs){ for(size_t i=0;i using namespace std; #endif //BEGIN CUT HERE template void read_tuple_impl(TV&) {} template void read_tuple_impl(TV& ts) { get(ts).emplace_back(*(istream_iterator(cin))); read_tuple_impl(ts); } template decltype(auto) read_tuple(size_t n) { tuple...> ts; for(size_t i=0;i(ts); return ts; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: io/yesno.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct BoolPrinter{ const string a,b; BoolPrinter(string a_,string b_):a(a_),b(b_){} string operator[](int k){return k?a:b;} }; BoolPrinter yesno("yes","no"); BoolPrinter YesNo("Yes","No"); BoolPrinter YESNO("YES","NO"); //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: leetcode/treenode.cpp ================================================ #include using namespace std; /** * @ignore */ //BEGIN CUT HERE struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; int dfs(TreeNode* v,int &k,vector > &G,vector &x){ if(!v) return -1; int s=k++; x.emplace_back(v->val); G.emplace_back(vector()); int a=dfs(v->left,k,G,x); int b=dfs(v->right,k,G,x); if(~a){ G[s].emplace_back(a); G[a].emplace_back(s); } if(~b){ G[s].emplace_back(b); G[b].emplace_back(s); } return s; } void build(TreeNode* v,vector > &G,vector &x){ assert(G.empty()); int k=0; dfs(v,k,G,x); } //END CUT HERE //INSERT ABOVE HERE signed main(){ return 0; } ================================================ FILE: linearalgebra/binarymatrix.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE const int MAX = 2002; using BS = bitset; using mat = vector; void gauss(mat &v){ int n=v.size(); for(int i=0;i=m) break; swap(v[i],v[s]); for(int j=0;j > tmp(n,vector(n,0)); mat res(n,BS(0)); for(int i=0;i>=1; } return res; } //END CUT HERE #ifndef call_from_test #define call_from_test #include "../tools/fastio.cpp" #undef call_from_test signed CFR382_D(){ int n,m; cin>>n>>m; mat v(n,BS(0)); for(int i=0;i as(m),bs(m); for(int i=0;i>as[i]>>bs[i]; as[i]--;bs[i]--; v[as[i]][bs[i]]=1; } gauss(v); for(int i=0;i>n; mat v(n,BS(0)); for(int i=0;i>c; v[i][j]=c-'0'; } } int ans=mrank(v,n); cout<<(ans==n?"Odd":"Even")< using namespace std; #endif //BEGIN CUT HERE template struct Matrix{ typedef vector arr; typedef vector mat; mat dat; Matrix(size_t r,size_t c):dat(r,arr(c,K())){} Matrix(mat dat):dat(dat){} size_t size() const{return dat.size();} bool empty() const{return size()==0;} arr& operator[](size_t k){return dat[k];} const arr& operator[](size_t k) const {return dat[k];} static Matrix matmul(const Matrix &A,const Matrix &B){ Matrix res(A.size(),B[0].size()); for(int i=0;i<(int)A.size();i++) for(int j=0;j<(int)B[0].size();j++) for(int k=0;k<(int)B.size();k++) res[i][j]+=A[i][k]*B[k][j]; return res; } static Matrix identity(size_t n){ Matrix res(n,n); for(int i=0;i<(int)n;i++) res[i][i]=K(1); return res; } Matrix pow(long long n) const{ assert(n>=0); assert(dat.size()==dat[0].size()); Matrix a(dat),res=identity(size()); while(n){ if(n&1) res=matmul(res,a); a=matmul(a,a); n>>=1; } return res; } template using ET = enable_if::value>; template using EF = enable_if::value>; template::type* = nullptr> static bool is_zero(T x){return abs(x)<1e-8;} template::type* = nullptr> static bool is_zero(T x){return x==T(0);} template::type* = nullptr> static bool compare(T x,T y){return abs(x)::type* = nullptr> static bool compare(T,T y){return !is_zero(y);} // assume regularity static Matrix gauss_jordan(const Matrix &A,const Matrix &B){ int n=A.size(),l=B[0].size(); Matrix C(n,n+l); for(int i=0;i; M::set_mod(p); using MM = Matrix; MM A(n,n); for(int i=0;i; M::set_mod(1e9+7); using MM = Matrix; MM A(n,n); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct SquareMatrix{ typedef array arr; typedef array mat; mat dat; SquareMatrix(){ for(size_t i=0;i>=1; } return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: linearalgebra/tree_theorem.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "matrix.cpp" #include "../datastructure/unionfind.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct MatrixTreeTheorem{ using M = Matrix; struct edge{ int a,b; T c; edge(int a,int b,T c):a(a),b(b),c(c){} bool operator<(const edge &e)const{ return c es; vector used; vector > H; UnionFind uf; MatrixTreeTheorem(int n):used(n),H(n),uf(n){} void add_edge(int a,int b,T c){ es.emplace_back(a,b,c); } vector bfs(int v){ vector vs; queue q; used[v]=1; q.emplace(v); while(!q.empty()){ v=q.front();q.pop(); vs.emplace_back(v); for(int u:H[v]){ if(used[u]) continue; used[u]=1; q.emplace(u); } } return vs; } tuple build(){ sort(es.begin(),es.end()); fill(used.begin(),used.end(),0); K res(1); T cost(0); for(int i=0;i<(int)es.size();){ queue q,r; for(auto &h:H) h.clear(); int p=i; while(i<(int)es.size() and es[i].c==es[p].c){ int u=uf.find(es[i].a); int v=uf.find(es[i++].b); H[u].emplace_back(v); H[v].emplace_back(u); q.emplace(u);q.emplace(v); r.emplace(u);r.emplace(v); } while(!q.empty()){ int v=q.front();q.pop(); if(used[v]) continue; vector vs=bfs(v); int m=vs.size(); if(m==1) continue; sort(vs.begin(),vs.end()); auto idx=[&](int x){ return lower_bound(vs.begin(),vs.end(),x)-vs.begin(); }; M A(m,m); for(int x:vs) for(int y:H[x]) if(x!=y) A[idx(x)][idx(y)]-=K(1); for(int x=0;x; int n,m; scanf("%d %d",&n,&m); MatrixTreeTheorem mtt(n); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct LinkCutTreeBase{ alignas(Node) inline static char pool[sizeof(Node) * LIM]; inline static Node* ptr = (Node*)pool; inline static size_t size = 0; template inline Node* create(Args&&... args){ return new (ptr+size++) Node(std::forward(args)...); } inline size_t idx(Node *t){return t-ptr;} Node* operator[](size_t k){return ptr+k;} inline void toggle(Node *t){ static_cast(this)->toggle(t); } inline Node* eval(Node *t){ return static_cast(this)->eval(t); } inline void pushup(Node *t){ static_cast(this)->pushup(t); } inline Node* expose(Node *t){ return static_cast(this)->expose(t); } void rotR(Node *t){ Node *x=t->p,*y=x->p; if((x->l=t->r)) t->r->p=x; t->r=x;x->p=t; pushup(x);pushup(t); if((t->p=y)){ if(y->l==x) y->l=t; if(y->r==x) y->r=t; pushup(y); } } void rotL(Node *t){ Node *x=t->p,*y=x->p; if((x->r=t->l)) t->l->p=x; t->l=x;x->p=t; pushup(x);pushup(t); if((t->p=y)){ if(y->l==x) y->l=t; if(y->r==x) y->r=t; pushup(y); } } // for splay tree (not original tree) bool is_root(Node *t){ return !t->p or (t->p->l!=t and t->p->r!=t); } void splay(Node *t){ eval(t); while(!is_root(t)){ Node *q=t->p; if(is_root(q)){ eval(q);eval(t); if(q->l==t) rotR(t); else rotL(t); }else{ auto *r=q->p; eval(r);eval(q);eval(t); if(r->l==q){ if(q->l==t) rotR(q),rotR(t); else rotL(t),rotR(t); }else{ if(q->r==t) rotL(q),rotL(t); else rotR(t),rotL(t); } } } } // c must be root on LCT void link(Node *par,Node *c){ expose(c); expose(par); c->p=par; par->r=c; pushup(par); } void cut(Node *c){ expose(c); Node *par=c->l; c->l=nullptr; pushup(c); par->p=nullptr; } void evert(Node *t){ expose(t); toggle(t); eval(t); } Node *parent(Node *t){ expose(t); if(!(t->l)) return nullptr; t=eval(t->l); while(t->r) t=eval(t->r); splay(t); return t; } Node *root(Node *t){ expose(t); while(t->l) t=eval(t->l); splay(t); return t; } bool is_connected(Node *a,Node *b){ return root(a)==root(b); } Node *lca(Node *a,Node *b){ expose(a); return expose(b); } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: linkcuttree/farthest.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "base.cpp" #undef call_from_test #endif // https://ei1333.hateblo.jp/entry/2019/06/13/133736 //BEGIN CUT HERE template struct NodeBase{ using T = Tp; NodeBase *l,*r,*p; bool rev; T val,ld,rd,smd; multiset td; NodeBase(T val):rev(0),val(val){ l=r=p=nullptr; ld=rd=smd=val; td.emplace(0); } }; template struct Farthest : LinkCutTreeBase>{ using super = LinkCutTreeBase; using Node = Np; using T = typename Node::T; Node* create(T val){ return super::create(Node(val)); } inline void toggle(Node *t){ swap(t->l,t->r); swap(t->ld,t->rd); t->rev^=1; } inline Node* eval(Node *t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } return t; } inline void pushup(Node *t){ if(t==nullptr) return; t->smd=t->val; if(t->l) t->smd+=t->l->smd; if(t->r) t->smd+=t->r->smd; T lld=t->l?t->l->ld:0; T rrd=t->r?t->r->rd:0; T lsmd=t->l?t->l->smd:0; T rsmd=t->r?t->r->smd:0; t->ld=max(lld,lsmd+t->val+*(t->td).rbegin()); if(t->r) t->ld=max(t->ld,lsmd+t->val+t->r->ld); t->rd=max(rrd,rsmd+t->val+*(t->td).rbegin()); if(t->l) t->rd=max(t->rd,rsmd+t->val+t->l->rd); } using super::splay; inline Node* expose(Node *t){ Node *rp=nullptr; for(Node *c=t;c;c=c->p){ splay(c); if(c->r) c->td.emplace(c->r->ld); c->r=rp; if(c->r) c->td.erase(c->td.find(c->r->ld)); pushup(c); rp=c; } splay(t); return rp; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed TKPPC2015_J(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; using Node = NodeBase; constexpr size_t LIM = 1e6+200; using LCT = Farthest; LCT lct; vector vs; vector es; vs.reserve(5e5+100); es.reserve(5e5+100); int num=0; vs.emplace_back(lct.create(0)); es.emplace_back(lct.create(0)); num++; int q; cin>>q; for(int i=0;i>t>>a>>c; if(t==1){ vs.emplace_back(lct.create(0)); es.emplace_back(lct.create(c)); lct.link(vs[a],es[num]); lct.link(es[num],vs[num]); num++; } if(t==2){ lct.expose(es[a]); es[a]->val=c; lct.pushup(es[a]); } if(t==3){ lct.evert(vs[a]); cout<<(vs[a]->ld)<<"\n"; } } cout< using namespace std; #define call_from_test #include "base.cpp" #undef call_from_test #endif // https://ei1333.hateblo.jp/entry/2018/05/29/011140 //BEGIN CUT HERE template struct NodeBase{ using T = Tp; using E = Ep; NodeBase *l,*r,*p; bool rev; T val,dat; E laz; NodeBase(T val,E laz): rev(0),val(val),dat(val),laz(laz){ l=r=p=nullptr;} }; template struct Path : LinkCutTreeBase>{ using super = LinkCutTreeBase; using Node = Np; using T = typename Node::T; using E = typename Node::E; using F = function; using G = function; using H = function; using S = function; F f; G g; H h; S flip; E ei; Path(F f,G g,H h,S flip,E ei): f(f),g(g),h(h),flip(flip),ei(ei){} Path(F f,G g,H h,E ei): Path(f,g,h,[](T a){return a;},ei){} Node* create(T val){ return super::create(Node(val,ei)); } inline void propagate(Node *t,E v){ t->laz=h(t->laz,v); t->val=g(t->val,v); t->dat=g(t->dat,v); } inline void toggle(Node *t){ swap(t->l,t->r); t->dat=flip(t->dat); t->rev^=1; } inline Node* eval(Node *t){ if(t->laz!=ei){ if(t->l) propagate(t->l,t->laz); if(t->r) propagate(t->r,t->laz); t->laz=ei; } if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } return t; } inline void pushup(Node *t){ t->dat=t->val; if(t->l) t->dat=f(t->l->dat,t->dat); if(t->r) t->dat=f(t->dat,t->r->dat); } using super::splay; inline Node* expose(Node *t){ Node *rp=nullptr; for(Node *c=t;c;c=c->p){ splay(c); c->r=rp; pushup(c); rp=c; } splay(t); return rp; } T query(Node *t){ expose(t); return t->dat; } void update(Node *t,E v){ expose(t); propagate(t,v); eval(t); } void set_val(Node *t,T v){ expose(t); t->val=v; eval(t); } }; //END CUT HERE #ifndef call_from_test // test dynamic tree signed SPOJ_DYNACON1(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; using Node = NodeBase; constexpr size_t LIM = 1e6; using LCT = Path; auto f=[](int a,int b){return a+b;}; LCT lct(f,f,f,0); for(int i=0;i>s>>a>>b; a--;b--; if(s=="add"s){ lct.evert(lct[b]); lct.link(lct[a],lct[b]); } if(s=="rem"s){ auto v=lct.lca(lct[a],lct[b])==lct[a]?lct[b]:lct[a]; lct.cut(v); } if(s=="conn"s) cout<<(lct.is_connected(lct[a],lct[b])?"YES\n":"NO\n"); } cout< using namespace std; #define call_from_test #include "base.cpp" #undef call_from_test #endif // http://beet-aizu.hatenablog.com/entry/2019/06/08/221833 //BEGIN CUT HERE template struct NodeBase{ using A = Ap; NodeBase *l,*r,*p; bool rev; A val,dat,sum; NodeBase(A val,A dat,A sum): rev(0),val(val),dat(dat),sum(sum){ l=r=p=nullptr;} }; template struct Subtree : LinkCutTreeBase>{ using super = LinkCutTreeBase; using Node = Np; using A = typename Node::A; Node* create(A val){ return super::create(Node(val,A(),val)); } inline void toggle(Node *t){ swap(t->l,t->r); t->rev^=1; } inline Node* eval(Node *t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } return t; } inline A resolve(Node *t){ return t?t->sum:A(); } inline void pushup(Node *t){ if(t==nullptr) return; t->sum=t->val+t->dat; t->sum+=resolve(t->l); t->sum+=resolve(t->r); } using super::splay; inline Node* expose(Node *t){ Node *rp=nullptr; for(Node *c=t;c;c=c->p){ splay(c); c->dat+=resolve(c->r); c->r=rp; c->dat-=resolve(c->r); pushup(c); rp=c; } splay(t); return rp; } A query(Node *t){ expose(t); return t->sum; } void set_val(Node *t,A a){ expose(t); t->val=a; pushup(t); } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "../tools/fastio.cpp" #undef call_from_test //INSERT ABOVE HERE // sum of square signed CFR564_E(){ int n,m; cin>>n>>m; vector> modv(n),modt(n); vector cs(n); for(int i=0;i>cs[i]; cs[i]--; modv[cs[i]].emplace_back(i); modt[cs[i]].emplace_back(0); } vector > G(n+1); for(int i=1;i>a>>b; a--;b--; G[a].emplace_back(b); G[b].emplace_back(a); } G[n].emplace_back(0); for(int i=1;i<=m;i++){ int v,x; cin>>v>>x; v--;x--; modv[cs[v]].emplace_back(v); modt[cs[v]].emplace_back(i); cs[v]=x; modv[cs[v]].emplace_back(v); modt[cs[v]].emplace_back(i); } using ll = long long; struct A{ ll sz1,sz2; A():sz1(0),sz2(0){} A(ll sz1,ll sz2):sz1(sz1),sz2(sz2){} A operator+(const A &a)const{ return A(sz1+a.sz1,sz2+a.sz2); }; A& operator+=(const A &a){ sz1+=a.sz1; sz2+=a.sz1*a.sz1; return (*this); } A& operator-=(const A &a){ sz1-=a.sz1; sz2-=a.sz1*a.sz1; return (*this); } }; using Node = NodeBase; constexpr size_t LIM = 1e6; using LCT = Subtree; LCT lct; for(int i=0;i par(n+1,0); { using P = pair; queue

q; q.emplace(n,-1); while(!q.empty()){ int v,p; tie(v,p)=q.front();q.pop(); par[v]=p; if(~p) lct.link(lct[p],lct[v]); for(int u:G[v]) if(u!=p) q.emplace(u,v); } } vector delta(m+1,0); vector color(n+1,0); for(int c=0;c>n>>m; vector xs(n); for(int i=0;i>xs[i]; using T = tuple; vector vt; for(int i=0;i>a>>b>>y; a--;b--; vt.emplace_back(y,a,b); } sort(vt.begin(),vt.end()); using ll = long long; using Node = NodeBase; constexpr size_t LIM = 1e6; using LCT = Subtree; LCT lct; for(int i=0;i; set

es; for(auto t:vt){ int a,b; tie(ignore,a,b)=t; if(lct.is_connected(lct[a],lct[b])) continue; lct.evert(lct[b]); lct.link(lct[a],lct[b]); es.emplace(a,b); } int ans=0; reverse(vt.begin(),vt.end()); for(auto t:vt){ int y,a,b; tie(y,a,b)=t; auto rt=lct.root(lct[a]); ll sum=lct.query(rt); if(sum>=y) continue; ans++; if(es.count(P(a,b))){ lct.evert(lct[a]); lct.cut(lct[b]); } } cout< using namespace std; #endif //BEGIN CUT HERE // O(N M) struct Bipartite{ int time; vector< vector > G; vector match,used,dead; Bipartite(int n): time(0),G(n),match(n,-1),used(n,-1),dead(n,0){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } int dfs(int v){ used[v]=time; for(int u:G[v]){ if(dead[u]) continue; int w=match[u]; if((w<0) or (used[w]

pq; dist[s]=0; pq.emplace(dist[s],s); while(!pq.empty()){ P p=pq.top();pq.pop(); int v=p.second; if(dist[v] init=[](decltype(h) &p){ fill(p.begin(),p.end(),0); }){ res=0; init(h); const Cost INF = numeric_limits::max(); while(f>0){ fill(dist.begin(),dist.end(),INF); dijkstra(s); if(dist[t]==INF) return false; for(int v=0;v<(int)h.size();v++) if(dist[v] using namespace std; #define call_from_test #include "../mod/mint.cpp" #include "../convolution/numbertheoretictransform.cpp" #include "../convolution/garner.cpp" #include "../mod/rint.cpp" #undef call_from_test #endif //BEGIN CUT HERE // MOD: prime int factorial(long long n,const int MOD){ if(n>=MOD) return 0; Garner arb; using R = Rint; R::set_mod(MOD); int d=1<<15; vector fact(d*2+1,1),finv(d*2+1,1); for(int i=1;i<=d*2;i++) fact[i]=fact[i-1]*R(i); finv[d*2]=fact[d*2].inv(); for(int i=d*2-1;i>=0;i--) finv[i]=finv[i+1]*R(i+1); vector seq({1,d+1}); seq.reserve(d+1); int sz=1; while(sz aux(sz,1); vector f(sz*4,0),g(sz*4,0); for(int i=0;i<=sz;i++){ f[i]=finv[i]*finv[sz-i]*seq[i]; if(((sz+i)&1) and (f[i].v!=0)) f[i]=-f[i]; } vector pf(f); vector as; as.emplace_back(R(sz+1)); as.emplace_back(R(sz)/R(d)); as.emplace_back(R(sz)/R(d)+R(sz+1)); for(int idx=0;idx<3;idx++){ for(int i=0;i using namespace std; #define call_from_test #include "../math/extgcd.cpp" #undef call_from_test #endif //BEGIN CUT HERE // a, MOD coprime template T mod_inverse(T a,const T MOD){ T x,y; extgcd(a,MOD,x,y); return (x%MOD+MOD)%MOD; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: mod/log.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // find x s.t. a^x = b (x >= 0) // return MOD if not found // MOD can be composite numbers template T mod_log(T a,T b,const T MOD){ using ll = long long; ll g=1; { ll m=MOD; while(m){ g=(ll)g*a%MOD; m>>=1; } } g=__gcd(g,(ll)MOD); ll c=0,t=1; while(t%g){ if(t==b) return c; t=t*a%MOD; c++; } // not found if(b%g) return MOD; t/=g;b/=g; const ll n=MOD/g; ll h=0,gs=1; while(h*h bs; { ll s=0,e=b; while(s using namespace std; #endif //BEGIN CUT HERE template struct Mint{ inline static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator+() const{return *this;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} static Mint comb(long long n,int k){ Mint num(1),dom(1); for(int i=0;i ostream& operator<<(ostream &os,Mint m){os< using namespace std; #endif //BEGIN CUT HERE // number of permutations with p_i != i template struct Montmort{ using ll = long long; vector dp; // MOD can be composite numbers Montmort(int n,const int MOD):dp(n+1,0){ for(int k=2;k<=n;k++){ dp[k]=(ll)dp[k-1]*k%MOD; if(~k&1) dp[k]+=1; else dp[k]+=MOD-1; if(dp[k]>=MOD) dp[k]-=MOD; } } T operator[](int n){return dp[n];} }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: mod/order.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "pow.cpp" #undef call_from_test #endif //BEGIN CUT HERE // mod can be composite numbers template T order(T x,const T MOD){ static map> dp; static map phi; vector &ps=dp[MOD]; if(ps.empty()){ T res=MOD,n=MOD; for(T i=2;i*i<=n;i++){ if(n%i) continue; while(n%i==0) n/=i; res=res/i*(i-1); } if(n!=1) res=res/n*(n-1); phi[MOD]=res; for(T i=2;i*i<=res;i++){ if(res%i) continue; while(res%i==0) res/=i; ps.emplace_back(i); } if(res!=1) ps.emplace_back(res); } T res=phi[MOD]; for(T p:ps){ while(res%p==0){ if(mod_pow(x,res/p,MOD)!=1) break; res/=p; } } return res; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: mod/pow.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // MOD can be composite numbers template T mod_pow(T a,long long n,const T MOD){ using ll = long long; T res(1); while(n){ if(n&1) res=(ll)res*a%MOD; a=(ll)a*a%MOD; n>>=1; } return res; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: mod/rint.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Rint{ inline static T mod; static void set_mod(T nmod){mod=nmod;} T v; Rint():v(0){} Rint(signed v):v(v){} Rint(long long t){v=t%mod;if(v<0) v+=mod;} Rint pow(long long k){ Rint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Rint add_identity(){return Rint(0);} static Rint mul_identity(){return Rint(1);} Rint inv(){return pow(mod-2);} Rint& operator+=(Rint a){v+=a.v;if(v>=mod)v-=mod;return *this;} Rint& operator-=(Rint a){v+=mod-a.v;if(v>=mod)v-=mod;return *this;} Rint& operator*=(Rint a){v=1LL*v*a.v%mod;return *this;} Rint& operator/=(Rint a){return (*this)*=a.inv();} Rint operator+(Rint a) const{return Rint(v)+=a;} Rint operator-(Rint a) const{return Rint(v)-=a;} Rint operator*(Rint a) const{return Rint(v)*=a;} Rint operator/(Rint a) const{return Rint(v)/=a;} Rint operator-() const{return v?Rint(mod-v):Rint(v);} bool operator==(const Rint a)const{return v==a.v;} bool operator!=(const Rint a)const{return v!=a.v;} bool operator <(const Rint a)const{return v ostream& operator<<(ostream &os,Rint m){os< using namespace std; #endif //BEGIN CUT HERE template int jacobi(T a,T m){ int s=1; if(a<0) a=a%m+m; while(m>1){ a%=m; if(a==0) return 0; int r=__builtin_ctz(a); if((r&1) and ((m+2)&4)) s=-s; a>>=r; if(a&m&2) s=-s; swap(a,m); } return s; } // MOD: prime template vector mod_sqrt(T a,const T MOD){ if(MOD==2) return {a&1}; int j=jacobi(a,MOD); if(j== 0) return {0}; if(j==-1) return {}; using ll = long long; mt19937 mt; ll b,d; while(1){ b=mt()%MOD; d=(b*b-a)%MOD; if(d<0) d+=MOD; if(jacobi(d,MOD)==-1) break; } ll f0=b,f1=1,g0=1,g1=0; for(ll e=(MOD+1)>>1;e;e>>=1){ if(e&1){ ll tmp=(g0*f0+d*((g1*f1)%MOD))%MOD; g1=(g0*f1+g1*f0)%MOD; g0=tmp; } ll tmp=(f0*f0+d*((f1*f1)%MOD))%MOD; f1=(2*f0*f1)%MOD; f0=tmp; } if(g0>MOD-g0) g0=MOD-g0; return {T(g0),T(MOD-g0)}; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: mod/tetration.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../math/totient.cpp" #undef call_from_test #endif //BEGIN CUT HERE template T mpow(T a,T n,T m,T &f){ using ull = unsigned long long; if(a==1 or n==0) return 1; ull v=1,x=a,z=m; f|=x>=z; x%=m; while(1){ if(n&1) v*=x; if(v>=z) f=1,v%=m; n>>=1; if(!n) break; x=x*x; if(x>=z) f=1,x%=m; } return v; } // a^a^a^... (repeat n times) // MOD can be composite numbers template T tetration(T a,T n,const T MOD,T &f){ if(a==0) return ~n&1; if(MOD==1) return f=1; if(a==1 or n==0) return 1; if(n==1){ f|=a>=MOD; return a%MOD+f*MOD; } T z=tetration(a,n-1,totient(MOD),f); T r=mpow(a,z,MOD,f); return r+f*MOD; } // MOD can be composite numbers template T tetration(T a,T n,const T MOD){ T f=0; return tetration(a,n,MOD,f)%MOD; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: polynomial/berlekampmassey.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // construct a charasteristic equation from sequence // return a monic polynomial in O(n^2) template vector berlekamp_massey(vector &as){ using Poly = vector; int n=as.size(); Poly bs({-T(1)}),cs({-T(1)}); T y(1); for(int ed=1;ed<=n;ed++){ int l=cs.size(),m=bs.size(); T x(0); for(int i=0;i using namespace std; #define call_from_test #include "../mod/mint.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct PolynomialHash{ struct V{ M1 v1; M2 v2; M3 v3; V(int x):v1(x),v2(x),v3(x){} V(long long x):v1(x),v2(x),v3(x){} V(M1 v1,M2 v2,M3 v3):v1(v1),v2(v2),v3(v3){} V& operator+=(V a){v1+=a.v1;v2+=a.v2;v3+=a.v3;;return *this;} V& operator-=(V a){v1-=a.v1;v2-=a.v2;v3-=a.v3;;return *this;} V& operator*=(V a){v1*=a.v1;v2*=a.v2;v3*=a.v3;;return *this;} V& operator/=(V a){v1/=a.v1;v2/=a.v2;v3/=a.v3;;return *this;} V operator+(V a) const{return V(*this)+=a;} V operator-(V a) const{return V(*this)-=a;} V operator*(V a) const{return V(*this)*=a;} V operator/(V a) const{return V(*this)/=a;} tuple norm() const{return make_tuple(v1,v2,v3);} bool operator==(const V a)const{return norm()==a.norm();} bool operator!=(const V a)const{return norm()!=a.norm();} bool operator <(const V a)const{return norm() po1,op1; vector po2,op2; vector po3,op3; template void init(int n,vector& po,vector& op){ po.assign(n+1,1); op.assign(n+1,1); M x(BASE); M y=M(x).inv(); for(int i=1;i<=(int)n;i++) po[i]=po[i-1]*x; for(int i=1;i<=(int)n;i++) op[i]=op[i-1]*y; } PolynomialHash(size_t n){ init(n,po1,op1); init(n,po2,op2); init(n,po3,op3); } V build(const vector &v){ int n=v.size(); M1 r1;M2 r2;M3 r3; for(int i=0;i void drop(const T &x){cout<; int h,w,q; cin>>h>>w>>q; vector s(h); for(int i=0;i>s[i]; vector rs(h),cs(w); for(int i=0;i a(k); for(int i=0;i; using M2 = Mint; using M3 = Mint; PolynomialHash ph(MAX); using V = decltype(ph)::V; vector vrs(h,0),vcs(w,0); vector tmp(w,1); V ri=ph.build(tmp); tmp.assign(h,1); V ci=ph.build(tmp); for(int i=0;i > mrs, mcs; for(int i=0;i &s=latte->second; latte++; set &t=latte->second; if(*--s.end()-*s.begin()+1==(int)s.size()){ a1=*s.begin(); b1=*--s.end(); } if(*--t.end()-*t.begin()+1==(int)t.size()){ a2=*t.begin(); b2=*--t.end(); } A=*s.begin(); B=*t.begin(); } if(a1<0 and a2<0){ print("No"); return; } { auto latte=mcs.begin(); set &s=latte->second; latte++; set &t=latte->second; if(*--s.end()-*s.begin()+1==(int)s.size()){ c1=*s.begin(); d1=*--s.end(); } if(*--t.end()-*t.begin()+1==(int)t.size()){ c2=*t.begin(); d2=*--t.end(); } C=*s.begin(); D=*t.begin(); } if(c1<0 and c2<0){ print("No"); return; } { int flg=0; if(~c1){ BS r=rs[A]^rs[B]; r>>=c1; int k=r.count(); r>>=(d1-c1+1); k-=r.count(); flg|=(d1-c1+1)==k; } if(~c1){ BS r=rs[A]^~rs[B]; r>>=c1; int k=r.count(); r>>=(d1-c1+1); k-=r.count(); flg|=(d1-c1+1)==k; } if(~c2){ BS r=rs[A]^rs[B]; r>>=c2; int k=r.count(); r>>=(d2-c2+1); k-=r.count(); flg|=(d2-c2+1)==k; } if(~c2){ BS r=rs[A]^~rs[B]; r>>=c2; int k=r.count(); r>>=(d2-c2+1); k-=r.count(); flg|=(d2-c2+1)==k; } if(!flg){ print("No"); return; } } { int flg=0; if(~a1){ BS r=cs[C]^cs[D]; r>>=a1; int k=r.count(); r>>=(b1-a1+1); k-=r.count(); flg|=(b1-a1+1)==k; } if(~a1){ BS r=cs[C]^~cs[D]; r>>=a1; int k=r.count(); r>>=(b1-a1+1); k-=r.count(); flg|=(b1-a1+1)==k; } if(~a2){ BS r=cs[C]^cs[D]; r>>=a2; int k=r.count(); r>>=(b2-a2+1); k-=r.count(); flg|=(b2-a2+1)==k; } if(~a2){ BS r=cs[C]^~cs[D]; r>>=a2; int k=r.count(); r>>=(b2-a2+1); k-=r.count(); flg|=(b2-a2+1)==k; } if(!flg){ print("No"); return; } } print("Yes"); }; auto calc= [&](){ if(mrs.size()>2u or mcs.size()>2u){ print("No"); return; } if(mrs.size()==1u or mcs.size()==1u){ print("Yes"); return; } if(mrs.size()==2u or mcs.size()==2u){ check(); return; } print("No"); }; calc(); for(int i=1;i>r>>c; r--;c--; mrs[vrs[r]].erase(r); if(mrs[vrs[r]].empty()) mrs.erase(vrs[r]); mcs[vcs[c]].erase(c); if(mcs[vcs[c]].empty()) mcs.erase(vcs[c]); if(rs[r][0]) vrs[r]=ri-vrs[r]; if(cs[c][0]) vcs[c]=ci-vcs[c]; if(rs[r][c]){ vrs[r]-=ph.term(c,1); vcs[c]-=ph.term(r,1); }else{ vrs[r]+=ph.term(c,1); vcs[c]+=ph.term(r,1); } rs[r][c].flip(); cs[c][r].flip(); if(rs[r][0]) vrs[r]=ri-vrs[r]; if(cs[c][0]) vcs[c]=ci-vcs[c]; mrs[vrs[r]].emplace(r); mcs[vcs[c]].emplace(c); calc(); } cout<; using M2 = Mint; using M3 = Mint; PolynomialHash ph(2000); using V = decltype(ph)::V; struct Point{ V x,y; Point():x(0),y(0){} Point(V x,V y):x(x),y(y){} }; using Vector = Point; Point getP(){ int x,y; cin>>x>>y; return Point(V((long long)x),V((long long)y)); } signed JAG2018SUMMER_DAY2_F(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; Point d=getP(); vector a(n),b(n),c(n); for(int i=0;i using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "../formalpowerseries/base.cpp" #include "../formalpowerseries/inv.cpp" #include "../formalpowerseries/div.cpp" #include "../formalpowerseries/mod.cpp" #include "../formalpowerseries/diff.cpp" #include "multieval.cpp" #undef call_from_test #endif //BEGIN CUT HERE // O(N log^2 N) template struct Interpolate : MultiEval{ using super = MultiEval; using typename super::Poly; using super::super, super::FPS, super::mem; Poly interpolate(const vector &xs,const vector &ws,int l,int r){ if(l+1==r) return Poly({ws[l]}); int m=(l+r)>>1; return FPS.add(FPS.mul(interpolate(xs,ws,l,m),mem[{m,r}]), FPS.mul(interpolate(xs,ws,m,r),mem[{l,m}])); } vector build(const vector &xs,const vector &ys){ int n=xs.size(); mem.clear(); super::dfs(xs,0,n); auto ls=FPS.diff(mem[{0,n}]); ls.resize(n,T(0)); vector ws(n); super::multi_eval(ls,ws,0,n); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template M lagrange_interpolation(vector &y,M t){ int n=y.size()-1; if(t.v<=n) return y[t.v]; vector dp(n+1,1),pd(n+1,1); for(int i=0;i0;i--) pd[i-1]=pd[i]*(t-M(i)); vector fact(n+1,1),finv(n+1,1); for(int i=1;i<=n;i++) fact[i]=fact[i-1]*M(i); finv[n]=M(1)/fact[n]; for(int i=n;i>=1;i--) finv[i-1]=finv[i]*M(i); M res(0); for(int i=0;i<=n;i++){ M tmp=y[i]*dp[i]*pd[i]*finv[i]*finv[n-i]; if((n-i)&1) res-=tmp; else res+=tmp; } return res; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: polynomial/multieval.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../combinatorics/enumeration.cpp" #include "../formalpowerseries/base.cpp" #include "../formalpowerseries/inv.cpp" #include "../formalpowerseries/div.cpp" #include "../formalpowerseries/mod.cpp" #undef call_from_test #endif //BEGIN CUT HERE // O(N log^2 N) template struct MultiEval{ FormalPowerSeries FPS; using Poly = typename FormalPowerSeries::Poly; using Conv = typename FormalPowerSeries::Conv; MultiEval(Conv conv):FPS(conv){} using P = pair; map mem; void dfs(const vector &cs,int l,int r){ if(l+1==r){ mem[{l,r}]=Poly({-cs[l],T(1)}); return; } int m=(l+r)>>1; dfs(cs,l,m); dfs(cs,m,r); mem[{l,r}]=FPS.mul(mem[{l,m}],mem[{m,r}]); } void multi_eval(Poly ps,vector &ws,int l,int r){ if(l+1==r){ ws[l]=FPS.mod(ps,mem[{l,r}])[0]; return; } int m=(l+r)>>1; multi_eval(FPS.mod(ps,mem[{l,m}]),ws,l,m); multi_eval(FPS.mod(ps,mem[{m,r}]),ws,m,r); } vector build(Poly ps,const vector &cs){ int n=cs.size(); mem.clear(); dfs(cs,0,n); vector ws(n); multi_eval(ps,ws,0,n); return ws; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: polynomial/polynomial.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Polynomial{ using P = Polynomial; vector co; Polynomial():co(1,T(1)){} Polynomial(int sz):co(sz,0){} Polynomial(vector co):co(co){} size_t size() const{ return co.size(); }; void shrink(){ while(co.size()>1u and !co.back()) co.pop_back(); } void reduce(){ T g=abs(co.back()); if(!g) return; for(T c:co) if(c!=0) g=__gcd(g,abs(c)); if(co.back()<0) g*=-1; for(T &c:co) c/=g; } void print(){ shrink(); reduce(); int n=size(),flg=0; for(int i=n-1;i>0;i--){ if(!co[i]) continue; flg=1; if(i!=n-1 and co[i]>0) cout<<"+"; if(co[i]==-1) cout<<"-"; else if(co[i]!=1) cout<0) cout<<"+"; cout< divide(const P &a) const{ int n=size(),m=a.size(),s=n-m+1; if(s<0) return make_pair(P(1),*this); P div(s); P rest=*this; for(int i=0;i0;j--) rest[n-(i+j)]-=a[m-j]*d; } return make_pair(div,rest); } P operator/(const P &a) const{return divide(a).first;}; P operator%(const P &a) const{return divide(a).second;}; }; template Polynomial gcd(Polynomial a,Polynomial b){ a.shrink();a.reduce(); b.shrink();b.reduce(); if(a.size() using namespace std; #endif //BEGIN CUT HERE // add recursive sequence template struct RecursiveSequence{ vector> add,sub; RecursiveSequence(int n):add(n),sub(n+1){} // add a_0, ..., a_{r-l-1} to [l, r) void query(int l,int r){ add[l].emplace_back(0); sub[r].emplace_back(r-l); } // a_i = \sum_{k} c_k a_{i-k} vector build(vector as,vector cs){ assert(as.size()==cs.size()); int n=add.size(); int k=as.size(); reverse(cs.begin(),cs.end()); as.resize(n+k); for(int i=0;i ss(n+k,T(0)); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct SegmentTree2D{ using F = typename SegmentTree::F; using T = typename F::result_type; const F f; const T ti; SegmentTree2D(F f_,T ti_):f(f_),ti(ti_){} vector> vp; void preupdate(index_t p,index_t q){ vp.emplace_back(p,q); } void compress(vector &vs){ sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); } int idx(index_t v,const vector &vs){ return lower_bound(vs.begin(),vs.end(),v)-vs.begin(); } int sz; vector ps; vector> I; vector> L,R; vector seg; void build(){ for(auto[p,q]:vp) ps.emplace_back(p); compress(ps); sz=1; while(sz<(int)ps.size()) sz<<=1; I.resize(sz<<1); for(auto[p,q]:vp) I[sz+idx(p,ps)].emplace_back(q); for(int k=(int)I.size()-1;k>=sz;k--) compress(I[k]); L.resize(sz); R.resize(sz); for(int k=sz-1;k>0;k--){ auto& cur=I[k]; const auto& lft=I[(k<<1)|0]; const auto& rgh=I[(k<<1)|1]; cur.resize(lft.size()+rgh.size()); merge(lft.begin(),lft.end(),rgh.begin(),rgh.end(),cur.begin()); cur.erase(unique(cur.begin(),cur.end()),cur.end()); L[k].resize(cur.size()+1); R[k].resize(cur.size()+1); int tl=0,tr=0; for(int i=0;i<(int)cur.size();i++){ while(tl<(int)lft.size() and lft[tl](I[k].size(),ti)); } } void update(int p,int q,T v,int k,int l,int r){ if(r<=p||p+1<=l) return; if(p<=l&&r<=p+1) return seg[k].set_val(q,v); int m=(l+r)>>1; update(p,L[k][q],v,(k<<1)|0,l,m); update(p,R[k][q],v,(k<<1)|1,m,r); T res=ti; const auto& cur=I[k]; const auto& lft=I[(k<<1)|0]; const auto& rgh=I[(k<<1)|1]; if(L[k][q]<(int)lft.size() and cur[q]==lft[L[k][q]]) res=f(res,seg[(k<<1)|0].query(L[k][q],L[k][q]+1)); if(R[k][q]<(int)rgh.size() and cur[q]==rgh[R[k][q]]) res=f(res,seg[(k<<1)|1].query(R[k][q],R[k][q]+1)); seg[k].set_val(q,res); } void update(index_t p,index_t q,T v){ update(idx(p,ps),idx(q,I[1]),v,1,0,sz); } T query(int pa,int pb,int qa,int qb,int k,int l,int r){ if(r<=pa||pb<=l) return ti; if(pa<=l&&r<=pb) return seg[k].query(qa,qb); int m=(l+r)>>1; return f(query(pa,pb,L[k][qa],L[k][qb],(k<<1)|0,l,m), query(pa,pb,R[k][qa],R[k][qb],(k<<1)|1,m,r)); } // [pa, pb) x [qa, qb) T query(index_t pa,index_t pb,index_t qa,index_t qb){ return query(idx(pa,ps),idx(pb,ps),idx(qa,I[1]),idx(qb,I[1]),1,0,sz); } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "../basic/ushi.cpp" #include "../../vector/zip.cpp" #include "../../tools/chminmax.cpp" #undef call_from_test signed ABC266_H(){ int n; cin>>n; vector ts(n),xs(n),ys(n),as(n); for(int i=0;i>ts[i]>>xs[i]>>ys[i]>>as[i]; { auto zs=zip(ys,ts,xs,as); sort(zs.begin(),zs.end()); for(int i=0;i bs(n),cs(n); for(int i=0;i> seg(f,0LL); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct SegmentTree{ using H = function; int n,height; H h; E ei; vector laz; SegmentTree(H h,E ei):h(h),ei(ei){} void init(int n_){ n=1;height=0; while(n>i); } void update(int a,int b,E x){ if(a>=b) return; thrust(a+=n); thrust(b+=n-1); for(int l=a,r=b+1;l>=1,r>>=1){ if(l&1) laz[l]=h(laz[l],x),l++; if(r&1) --r,laz[r]=h(laz[r],x); } } E get_val(int a){ thrust(a+=n); return laz[a]; } void set_val(int a,E x){ thrust(a+=n); laz[a]=x; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: segtree/basic/lazy.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct SegmentTree{ using F = function; using G = function; using H = function; int n,height; F f; G g; H h; T ti; E ei; vector dat; vector laz; SegmentTree(F f,G g,H h,T ti,E ei): f(f),g(g),h(h),ti(ti),ei(ei){} void init(int n_){ n=1;height=0; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>i); } inline void recalc(int k){ while(k>>=1) dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1)); } void update(int a,int b,E x){ if(a>=b) return; thrust(a+=n); thrust(b+=n-1); for(int l=a,r=b+1;l>=1,r>>=1){ if(l&1) laz[l]=h(laz[l],x),l++; if(r&1) --r,laz[r]=h(laz[r],x); } recalc(a); recalc(b); } void set_val(int a,T x){ thrust(a+=n); dat[a]=x;laz[a]=ei; recalc(a); } T query(int a,int b){ if(a>=b) return ti; thrust(a+=n); thrust(b+=n-1); T vl=ti,vr=ti; for(int l=a,r=b+1;l>=1,r>>=1) { if(l&1) vl=f(vl,reflect(l++)); if(r&1) vr=f(reflect(--r),vr); } return f(vl,vr); } template int find(int st,C &check,T &acc,int k,int l,int r){ if(l+1==r){ acc=f(acc,reflect(k)); return check(acc)?k-n:-1; } propagate(k); int m=(l+r)>>1; if(m<=st) return find(st,check,acc,(k<<1)|1,m,r); if(st<=l and !check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } int vl=find(st,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return find(st,check,acc,(k<<1)|1,m,r); } template int find(int st,C &check){ T acc=ti; return find(st,check,acc,1,0,n); } }; //END CUT HERE #ifndef call_from_test signed CFR569_C(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; vector as(n),bs(m); for(int i=0;i>as[i]; for(int i=0;i>bs[i]; auto f=[](int a,int b){return max(a,b);}; auto g=[](int a,int b){return a+b;}; int ti=0,ei=0; SegmentTree seg(f,g,g,ti,ei); const int sz = 1<<20; seg.build(vector(sz,0)); for(int i=0;i>q; auto check=[](int d){return d>0;}; for(int i=0;i>t>>k>>v; k--; if(t==1){ seg.update(sz-as[k],sz,-1); as[k]=v; seg.update(sz-as[k],sz,+1); } if(t==2){ seg.update(sz-bs[k],sz,+1); bs[k]=v; seg.update(sz-bs[k],sz,-1); } int pos=seg.find(0,check); cout<<(pos<0?pos:sz-pos)<<"\n"; } cout< using namespace std; #endif //BEGIN CUT HERE template struct SegmentTree{ using F = function; int n; F f; T ti; vector dat; SegmentTree(F f,T ti):f(f),ti(ti){} void init(int n_){ n=1; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(int a,int b){ if(a>=b) return ti; T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } template int max_right(int s,C &check,T &acc,int k,int l,int r){ if(l+1==r){ acc=f(acc,dat[k]); return check(acc)?-1:k-n; } int m=(l+r)>>1; if(m<=s) return max_right(s,check,acc,(k<<1)|1,m,r); if(s<=l and check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } int vl=max_right(s,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return max_right(s,check,acc,(k<<1)|1,m,r); } // max t s.t. check(query(s,t)) // O(\log N) template int max_right(int s,C &check){ assert(s using namespace std; #endif //BEGIN CUT HERE template struct RangeCount{ struct BIT{ vector dat; BIT(int n){dat.assign(++n,0);} T sum(int k){ T res=0; for(;k;k-=k&-k) res+=dat[k]; return res; } void add(int k,T v){ for(++k;k<(int)dat.size();k+=k&-k) dat[k]+=v; } }; int n; vector< vector > val; vector dat; RangeCount(int n):n(n){ val.assign(n<<1,vector()); dat.reserve(n<<1); } void preupdate(int a,Key x){ a+=n; while(a){ val[a].emplace_back(x); a>>=1; } } void build(){ for(int i=0;i>=1; } } T calc(int k,Key x,Key y){ auto &vs=val[k]; int p=lower_bound(vs.begin(),vs.end(),x)-vs.begin(); int q=lower_bound(vs.begin(),vs.end(),y)-vs.begin(); return dat[k].sum(q)-dat[k].sum(p); } // [a, b) * [x, y) T query(int a,int b,Key x,Key y){ T res=0; for(int l=a+n,r=b+n;l>=1,r>>=1){ if(l&1) res+=calc(l++,x,y); if(r&1) res+=calc(--r,x,y); } return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE //END CUT HERE signed main(){ return 0; } #endif ================================================ FILE: segtree/count/static.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct SegmentTree{ using P = pair; int n; vector< vector > dat; SegmentTree(int n,vector

vs):n(n){ dat.assign(n<<1,vector()); for(auto p:vs) dat[p.first+n].emplace_back(p.second); for(int i=0;i &xs){ auto latte=lower_bound(xs.begin(),xs.end(),d); auto malta=lower_bound(xs.begin(),xs.end(),c); return int(latte-malta); }; for(int l=a+n,r=b+n;l>=1,r>>=1){ if(l&1) res+=calc(dat[l++]); if(r&1) res+=calc(dat[--r]); } return res; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: segtree/persistent/ushi.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct SegmentTree{ using F = function; F f; T ti; SegmentTree(F f,T ti):f(f),ti(ti){} struct Node{ Node *l,*r; T dat; Node(T dat):dat(dat){l=r=nullptr;} }; Node* clone(Node *a){ return new Node(*a); } Node* reflect(Node *a){ a->dat=f(a->l->dat,a->r->dat); return a; } int n,height; Node* build(const vector &v){ int n_=v.size(); n=1;height=0; while(n vs(n<<1); for(int i=0;il=vs[(i<<1)|0]; vs[i]->r=vs[(i<<1)|1]; reflect(vs[i]); } return vs[1]; } Node* set_val(Node* t,int k,T x,int h){ t=clone(t); if(h<0){ t->dat=x; return t; } if((k>>h)&1) t->r=set_val(t->r,k,x,h-1); else t->l=set_val(t->l,k,x,h-1); return reflect(t); } T query(Node* t,int l,int r,int lb,int ub){ if(r<=lb or ub<=l) return ti; if(l<=lb and ub<=r) return t->dat; int m=(lb+ub)>>1; return f(query(t->l,l,r,lb,m),query(t->r,l,r,m,ub)); } Node* set_val(Node* t,int k,T x){ return set_val(t,k,x,height-1); } T query(Node* t,int l,int r){ return query(t,l,r,0,n); } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: segtree/types/offline.cpp ================================================ #include using namespace std; #define IGNORE template struct RangeCount{ struct BIT{ vector dat; BIT(int n){dat.assign(++n,0);} T sum(int k){ T res=0; for(;k;k-=k&-k) res+=dat[k]; return res; } void add(int k,T v){ for(++k;k<(int)dat.size();k+=k&-k) dat[k]+=v; } }; int n; vector > val; vector dat; RangeCount(int n_){ n=1; while(n()); dat.reserve(n<<1); } void preupdate(int a,int x){ a+=n; while(a){ val[a].emplace_back(x); a>>=1; } } void build(){ for(int i=0;i>=1; } } T calc(int k,int x,int y){ auto &v=val[k]; int p=lower_bound(v.begin(),v.end(),x)-v.begin(); int q=lower_bound(v.begin(),v.end(),y)-v.begin(); return dat[k].sum(q)-dat[k].sum(p); } // [a, b) * [x, y) T query(int a,int b,int x,int y){ T res=0; for(int l=a+n,r=b+n;l>=1,r>>=1){ if(l&1) res+=calc(l++,x,y); if(r&1) res+=calc(--r,x,y); } return res; } }; struct RangeTypes{ struct range{ int l,r,c; range(int l,int r,int c):l(l),r(r),c(c){} bool operator<(const range &a)const{ return l nxt,dat,upd; set sx; set sr; vector > se; RangeCount rc; using T = tuple; vector mvs; RangeTypes(int n_,int m):m(m),time(0),se(m+1),rc(n_){ n=1; while(n>=1) if(t vx,vc; if(a) vc.emplace_back(get(a-1)); vc.emplace_back(c); for(auto it=sx.lower_bound(a);it!=sx.end();++it){ if(*it>=b) break; vx.emplace_back(*it); vc.emplace_back(get(*it)); } if(vx.empty() or vx.back()!=b-1){ vx.emplace_back(b-1); vc.emplace_back(get(b-1)); } vector vr; { auto it=sr.lower_bound(range(a,0,0)); if(it!=sr.begin()) --it; if(it->lr) vr.emplace_back(*it); } for(auto it=sr.lower_bound(range(a,0,0));it!=sr.end();++it){ if(it->l>=b) break; vr.emplace_back(*it); } // update information for(int l=a+n,r=b+n;l>=1,r>>=1){ if(l&1) dat[l]=c,upd[l]=time,l++; if(r&1) --r,dat[r]=c,upd[r]=time; } for(auto r:vr){ sr.erase(r); se[r.c].erase(r); } sr.emplace(a,b,c); se[c].emplace(a,b,c); { auto r=vr.front(); if(r.ll; reset(b-1,nb); if(nb!=b) sx.emplace(b-1); } sort(vc.begin(),vc.end()); vc.erase(unique(vc.begin(),vc.end()),vc.end()); for(int x:vc){ auto it=se[x].lower_bound(range(a,0,0)); if(it==se[x].begin()) continue; int ny=(it==se[x].end()?n:it->l),y=(--it)->r-1; reset(y,ny); if(ny!=y+1) sx.emplace(y); } } void count(const int a,const int b){ mvs.emplace_back(-1,a,b); } vector build(){ rc.build(); for(int i=0;i res; for(auto mv:mvs){ int a,b,c; tie(a,b,c)=mv; if(~a){ rc.update(a,b,-1); rc.update(a,c, 1); }else{ res.emplace_back(rc.query(b,c,c,n<<1)); } } return res; } }; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a > G; vector ls,rs; EulerTour(int n):n(n),G(n),ls(n),rs(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(int v,int p){ ls[v]=pos++; for(int u:G[v]) if(u!=p) dfs(u,v); rs[v]=pos; } void build(int r=0){ pos=0; dfs(r,-1); } }; //INSERT ABOVE HERE signed main(){ int T; scanf("%d",&T); for(int t=1;t<=T;t++){ printf("Case #%d:\n",t); int n; scanf("%d",&n); EulerTour et(n); for(int i=1;i c(n); for(int i=0;i val(n),used(n+1,-1); for(int i=0;i dfs= [&](int v,int p){ rt.update(et.ls[v],et.rs[v],c[v]); for(int u:et.G[v]) if(p!=u) dfs(u,v); }; dfs(0, -1); for(int i=0;i using namespace std; #define IGNORE #include #include #include using namespace __gnu_pbds; struct RangeTypes{ template using gtree = tree, rb_tree_tag, tree_order_statistics_node_update>; struct range{ int l,r,c; range(int l,int r,int c):l(l),r(r),c(c){} bool operator<(const range &a)const{ return l nxt,dat,upd; set sx; set sr; vector > se; vector > rc; RangeTypes(int n_,int m):m(m),time(0),se(m+1){ n=1; while(n>=1) rc[k].insert(nxt[i]); for(int i=0;i>=1) if(t>=1; } nxt[a]=v; } void update(const int a,const int b,const int c){ assert(a vx,vc; if(a) vc.emplace_back(get(a-1)); vc.emplace_back(c); for(auto it=sx.lower_bound(a);it!=sx.end();++it){ if(*it>=b) break; vx.emplace_back(*it); vc.emplace_back(get(*it)); } if(vx.empty() or vx.back()!=b-1){ vx.emplace_back(b-1); vc.emplace_back(get(b-1)); } vector vr; { auto it=sr.lower_bound(range(a,0,0)); if(it!=sr.begin()) --it; if(it->lr) vr.emplace_back(*it); } for(auto it=sr.lower_bound(range(a,0,0));it!=sr.end();++it){ if(it->l>=b) break; vr.emplace_back(*it); } // update information for(int l=a+n,r=b+n;l>=1,r>>=1){ if(l&1) dat[l]=c,upd[l]=time,l++; if(r&1) --r,dat[r]=c,upd[r]=time; } for(auto r:vr){ sr.erase(r); se[r.c].erase(r); } sr.emplace(a,b,c); se[c].emplace(a,b,c); { auto r=vr.front(); if(r.ll; reset(b-1,nb); if(nb!=b) sx.emplace(b-1); } sort(vc.begin(),vc.end()); vc.erase(unique(vc.begin(),vc.end()),vc.end()); for(int x:vc){ auto it=se[x].lower_bound(range(a,0,0)); if(it==se[x].begin()) continue; int ny=(it==se[x].end()?n+(++time):it->l),y=(--it)->r-1; reset(y,ny); if(ny!=y+1) sx.emplace(y); } } int query(const int a,const int b,const int c,const int d) const{ int res=0; auto calc=[&](const gtree &g){ int lb=*g.lower_bound(c); int ub=*g.upper_bound(d); return g.order_of_key(ub)-g.order_of_key(lb); }; for(int l=a+n,r=b+n;l>=1,r>>=1){ if(l&1) res+=calc(rc[l++]); if(r&1) res+=calc(rc[--r]); } return res; } int count(const int a,const int b) const{ return query(a,b,b,INT_MAX-1); } }; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a > G; vector ls,rs; EulerTour(int n):n(n),G(n),ls(n),rs(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(int v,int p){ ls[v]=pos++; for(int u:G[v]) if(u!=p) dfs(u,v); rs[v]=pos; } void build(int r=0){ pos=0; dfs(r,-1); } }; //INSERT ABOVE HERE signed main(){ int T; scanf("%d",&T); int casecnt=0; for(int t=1;t<=T;t++){ printf("Case #%d:\n",t); int n; scanf("%d",&n); EulerTour et(n); for(int i=1;i c(n); for(int i=0;i=2){ vector val(n),used(n+1,-1); for(int i=0;i dfs= [&](int v,int p){ rt.update(et.ls[v],et.rs[v],c[v]); for(int u:et.G[v]) if(p!=u) dfs(u,v); }; dfs(0, -1); for(int i=0;i using namespace std; #define call_from_test #include "trie.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct AhoCorasick : Trie{ using super = Trie; using super::super, super::next, super::size; using super::vs, super::conv; vector cnt,ord; // O(\sigma \sum |T_i|) void build(){ int n=vs.size(); cnt.resize(n); for(int i=0;i que; for(int i=0;i<(int)X;i++){ if(~next(0,i)){ next(next(0,i),X)=0; que.emplace(next(0,i)); }else{ next(0,i)=0; } } while(!que.empty()){ ord.emplace_back(que.front()); auto &x=vs[que.front()]; int fail=x.nxt[X]; cnt[que.front()]+=cnt[fail]; que.pop(); for(int i=0;i<(int)X;i++){ int &nx=x.nxt[i]; if(nx<0){ nx=next(fail,i); continue; } que.emplace(nx); next(nx,X)=next(fail,i); if(heavy){ auto &idx=vs[nx].idxs; auto &idy=vs[next(fail,i)].idxs; vector idz; set_union(idx.begin(),idx.end(), idy.begin(),idy.end(), back_inserter(idz)); idx=idz; } } } reverse(ord.begin(),ord.end()); } int count(int pos){ return cnt[pos]; } // O(|S|) long long match(string s){ long long res=0; int pos=0; for(auto &c:s){ pos=next(pos,conv(c)); res+=count(pos); } return res; } // O(|S| + \sum |T_i|) vector frequency(string s){ vector res(size(),0); int pos=0; for(auto &c:s){ pos=next(pos,conv(c)); res[pos]++; } for(int p:ord) res[vs[p].nxt[X]]+=res[p]; return res; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: string/editdistance.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../tools/chminmax.cpp" #undef call_from_test #endif //BEGIN CUT HERE int edit_distance(string s,string t){ int n=s.size(),m=t.size(); vector< vector > dp(n+1,vector(m+1,n+m+1)); dp[0][0]=0; for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ if(i using namespace std; #endif // https://snuke.hatenablog.com/entry/2017/07/18/101026 //BEGIN CUT HERE vector knuth_morris_pratt(const string &s){ int n=s.size(); vector kmp(n+1,-1); for(int i=0,j=-1;i pattern_match(string s,string t){ int n=s.size(),m=t.size(); vector kmp=knuth_morris_pratt(s); vector res; int i=0,j=0; while(i+j inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>s>>t; int n=s.size(),m=t.size(); string b; while(b.size() match(n); for(int i=m+1;i<=m+n;i++) match[i-(m+1)]=kmp[i+m]==m; vector< vector > G(n); for(int i=0;i indeg(n,0); for(int i=0;i que; for(int i=0;i dp(n,0); while(!que.empty()){ int v=que.front();que.pop(); for(int u:G[v]){ chmax(dp[u],dp[v]+1); indeg[u]--; if(indeg[u]==0) que.emplace(u); } } for(int i=0;i using namespace std; #define call_from_test #include "suffixarray.cpp" #undef call_from_test #endif //BEGIN CUT HERE template struct LongestCommonPrefix{ SuffixArray sa; vector ht; vector< vector > dat; LongestCommonPrefix(const Seq &s):sa(s){ int n=s.size(); vector lcp(n,0); int t=0; lcp[0]=0; for(int i=0;i0) t--; for(;j+t(n)); ht.assign(n+1,0); for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1; for(int j=0;jb) swap(a,b); int l=b-a; return min(dat[ht[l]][a],dat[ht[l]][b-(1< using namespace std; #endif //BEGIN CUT HERE // O(nm) string longest_common_substring(string s,string t){ int n=s.size(),m=t.size(); s+='$';t+='%'; vector< vector > dp(n+2,vector(m+2,-(n+m))); dp[0][0]=0; auto chmax=[&](int &a,int b){if(a>s>>t; cout< using namespace std; #endif // https://snuke.hatenablog.com/entry/2014/12/02/235837 //BEGIN CUT HERE vector manacher(string s){ int n=s.size(); vector vs(n); for(int i=0,j=0;i=0 and i+j=0 and i+k using namespace std; #endif // https://snuke.hatenablog.com/entry/2014/12/01/235807 // https://kopricky.github.io/code/String/kmp.html //BEGIN CUT HERE // longest prefix suffix matching of [0, i) vector morris_pratt(const string &s){ int n=s.size(); vector mp(n+1,-1); for(int i=0,j=-1;i minimum_period(const string &s){ auto mp=morris_pratt(s); for(int i=1;i<(int)mp.size();i++) mp[i]=i-mp[i]; return mp; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE // test minimum_period signed ARC060_F(){ cin.tie(0); ios::sync_with_stdio(0); string w; cin>>w; int n=w.size(); if(w==string(n,w[0])){ cout<kmp[i]) continue; if(j%kmp_rev[j]==0 and j>kmp_rev[j]) continue; cnt++; } cout<<2< using namespace std; #endif //BEGIN CUT HERE struct PalindromicTree{ struct node{ map nxt; int len,suf,app,cnt; node():len(-1){} node(int len,int suf,int app,int cnt) :len(len),suf(suf),app(app),cnt(cnt){} }; vector vs; vector ord; int n,ptr; PalindromicTree(const string &s) :vs(s.size()+10),n(2),ptr(1){ vs[0]=node(-1,0,-1,0); vs[1]=node( 0,0,-1,0); for(int i=0;i<(int)s.size();i++) add_char(s,i); calc_order(); calc_count(); } bool add_char(const string &s,int pos){ char ch=s[pos]; int cur=ptr; while(1){ int rev=pos-1-vs[cur].len; if(rev>=0 and s[rev]==ch) break; cur=vs[cur].suf; } if(vs[cur].nxt.count(ch)){ ptr=vs[cur].nxt[ch]; vs[ptr].cnt++; return false; } ptr=n++; vs[ptr]=node(vs[cur].len+2,-1,pos-vs[cur].len-1,1); vs[cur].nxt[ch]=ptr; if(vs[ptr].len==1){ vs[ptr].suf=1; return true; } while(1){ cur=vs[cur].suf; int rev=pos-1-vs[cur].len; if(rev>=0 and s[rev]==ch){ vs[ptr].suf=vs[cur].nxt[ch]; break; } } return true; } void calc_order(){ ord.clear(); ord.emplace_back(0); ord.emplace_back(1); for(int i=0;i<(int)ord.size();i++) for(auto &p:vs[ord[i]].nxt) ord.emplace_back(p.second); } void calc_count(){ for(int i=(int)ord.size()-1;i>=0;i--) vs[vs[ord[i]].suf].cnt+=vs[ord[i]].cnt; } size_t size()const{return n;} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: string/parse.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE int expression(string&,int&); int term(string&,int&); int factor(string&,int&); int number(string&,int&); bool f; int expression(string& s,int& p){ int res=term(s,p); while(p<(int)s.size()){ if(s[p]=='+'){ p++; res+=term(s,p); continue; } if(s[p]=='-'){ p++; res-=term(s,p); continue; } break; } return res; } int term(string& s,int& p){ int res=factor(s,p); while(p<(int)s.size()){ if(s[p]=='*'){ p++; res*=factor(s,p); continue; } if(s[p]=='/'){ p++; int tmp=factor(s,p); if(tmp==0){ f=1; break; } res/=tmp; continue; } break; } return res; } int factor(string& s,int& p){ int res; if(s[p]=='('){ p++; res=expression(s,p); p++; }else{ res=number(s,p); } return res; } int number(string& s,int& p){ int res=0; while(p<(int)s.size() and isdigit(s[p])) res=res*10+s[p++]-'0'; return res; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: string/rectanglehash.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "rollinghash.cpp" #undef call_from_test #endif //BEGIN CUT HERE template auto rectangle_hash(vector vs,int r,int c){ vector< RollingHash > hs; for(string s:vs) hs.emplace_back(s); int h=vs.size(),w=vs[0].size(); vector< vector > res(h-r+1,vector(w-c+1)); for(int j=0;j+c<=w;j++){ vector ts(h); for(int i=0;i rh(ts); for(int i=0;i+r<=h;i++) res[i][j]=rh.find(i,i+r); } return res; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: string/rollinghash.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct RollingHash{ using ll = long long; vector hash,po; RollingHash(vector vs){init(vs);} RollingHash(string &s){ vector vs; for(char c:s) vs.emplace_back(c); init(vs); } void init(vector vs){ int n=vs.size(); hash.assign(n+1,0); po.assign(n+1,1); for(int i=0;i=MOD?res-MOD:res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: string/run.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "zalgorithm.cpp" #undef call_from_test #endif //BEGIN CUT HERE namespace Run{ using T = tuple; using P = pair; vector> run; template vector sub(const vector &xs,const vector &ys){ auto ps=xs; auto qs=ys; reverse(ps.begin(),ps.end()); qs.insert(qs.end(),xs.begin(),xs.end()); qs.insert(qs.end(),ys.begin(),ys.end()); auto zp=zalgorithm(ps); auto zq=zalgorithm(qs); vector res; for(int i=0;i<(int)xs.size();i++){ int a=xs.size()-i; int b=i-zp[a]; int c=max(0,(int)ys.size()-zq[ys.size()+i]); if((int)(xs.size()+ys.size())-b-c>=2*a) res.emplace_back(a,b,c); } return res; } template void dfs(int l,int r,const vector &cs){ if(l+1>=r) return; int m=(l+r)>>1; vector xs(cs.begin()+l,cs.begin()+m); vector ys(cs.begin()+m,cs.begin()+r); { auto zs=sub(xs,ys); for(auto w:zs){ int a,b,c; tie(a,b,c)=w; run[a].emplace_back(l+b,r-c); } } reverse(xs.begin(),xs.end()); reverse(ys.begin(),ys.end()); { auto zs=sub(ys,xs); for(auto w:zs){ int a,b,c; tie(a,b,c)=w; run[a].emplace_back(l+c,r-b); } } dfs(l,m,cs); dfs(m,r,cs); } // return all t (not only minimal) template vector> enumerate(const vector &cs){ int n=cs.size(); run.clear(); run.resize(n+1); dfs(0,n,cs); auto cmp=[&](P a,P b){return P(a.first,-a.second) tmp; for(auto p:rs){ if(mx> enumerate(string ss){ return enumerate(vector(ss.begin(),ss.end())); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: string/split.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE vector split(string& s,char c){ int n=s.size(); vector res; for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct SuffixArray{ const Seq s; vector sa,rev; SuffixArray(const Seq &s_):s(s_){ int n=s.size(); auto cmp=[&](int a,int b){ if(a==b) return false; if(a==n) return true; if(b==n) return false; if(s[a]==s[b]) return a>b; return s[a] rs(n+1); { Seq t(s); sort(t.begin(),t.end()); t.erase(unique(t.begin(),t.end()),t.end()); for(int i=0;i cs(n+1); for(int i=0;i<=n;i++){ cs[sa[i]]=i; if(i==0) continue; if(rs[sa[i-1]]!=rs[sa[i]]) continue; if(sa[i-1]+len>=n) continue; if(rs[sa[i-1]+len/2]!=rs[sa[i]+len/2]) continue; cs[sa[i]]=cs[sa[i-1]]; } vector cnt(n+1); iota(cnt.begin(),cnt.end(),0); copy(sa.begin(),sa.end(),rs.begin()); for(int i=0;i<=n;i++){ int s1=rs[i]-len; if(s1>=0) sa[cnt[cs[s1]]++]=s1; } cs.swap(rs); } rev.resize(n+1); for(int i=0;i<=n;i++) rev[sa[i]]=i; } int operator[](int i) const{return sa[i];} bool lt_substr(const Seq &t,int si,int ti){ int sn=s.size(),tn=t.size(); while(sit[ti]) return 0; si++;ti++; } return si==sn and ti>1; if(lt_substr(t,sa[m],0)) l=m; else r=m; } return r; } int upper_bound(Seq t){ t.back()++; int res=lower_bound(t); t.back()--; return res; } // O(|t| \log|s|) int count(Seq t){ return upper_bound(t)-lower_bound(t); } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ vector vs({1, 2, 3, 1, 2, 1}); SuffixArray sa(vs); for(int i=0;i<=(int)vs.size();i++) cout< using namespace std; #endif //BEGIN CUT HERE template struct Trie{ struct Node{ array nxt; vector idxs; int idx; Node():idx(-1){fill(nxt.begin(),nxt.end(),-1);} }; using F = function; vector vs; F conv; Trie(F conv):conv(conv){vs.emplace_back();} Trie(char start):Trie([=](char a){return a-start;}){} inline int &next(int i,int j){ return vs[i].nxt[j]; } void add(const string &s,int x){ int pos=0; for(char c:s){ int k=conv(c); if(~next(pos,k)){ pos=next(pos,k); continue; } int npos=vs.size(); next(pos,k)=npos; vs.emplace_back(); pos=npos; } vs[pos].idx=x; vs[pos].idxs.emplace_back(x); } int find(const string &s){ int pos=0; for(char c:s){ int k=conv(c); if(next(pos,k)<0) return -1; pos=next(pos,k); } return pos; } int move(int pos,char c){ assert(pos<(int)vs.size()); return pos<0?-1:next(pos,conv(c)); } int size(){return vs.size();} int idx(int pos){ return pos<0?-1:vs[pos].idx; } vector idxs(int pos){ return pos<0?vector():vs[pos].idxs; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: string/zalgorithm.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // longest common prefix of s and s[i:n] // return n + 1 elements for run enumerate template vector zalgorithm(vector vs){ int n=vs.size(); vector as(n+1,0); as[0]=n; int i=1,j=0; while(i zalgorithm(string s){ return zalgorithm(vector(s.begin(),s.end())); } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: test/aoj/0109.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109 #include using namespace std; #define call_from_test #include "../../string/parse.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; while(n--){ string s; int p=0; cin>>s; s.pop_back(); cout< using namespace std; #define call_from_test #include "../../convolution/naive.cpp" #include "../../math/bostanmori.cpp" #undef call_from_test signed main(){ using ll = long long; BostanMori bm(naive()); using Poly = vector; Poly as({0,0,1}),cs({-1,-1,-1,1}); int n; while(cin>>n,n) cout<<(bm.build(n+2,as,cs)+3650-1)/3650< using namespace std; #define call_from_test #include "../../math/convertbase.cpp" #undef call_from_test signed main(){ long long p; while(cin>>p,p){ auto ans=convert_base(p,-10LL); for(auto x:ans) cout< using namespace std; #define call_from_test #include "../../graph/dominatortree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; DominatorTree G(n); for(int i=0;i>a>>b; a--;b--; G.add_edge(a,b); } G.build(0); int q; cin>>q; for(int i=0;i>r; r--; cout<<(G[r]?G[r]:r)+1<<"\n"; } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../linearalgebra/matrix.cpp" #include "../../datastructure/unionfind.cpp" #include "../../linearalgebra/tree_theorem.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; using M = Mint; using edge=MatrixTreeTheorem::edge; vector es; for(int i=0;i>s>>t>>d; s--;t--; es.emplace_back(s,t,d); } sort(es.begin(),es.end()); UnionFind uf(n); int cost=0; for(auto e:es){ uf.unite(e.a,e.b); cost=e.c; if(uf.count()==1) break; } cout< rs; for(int i=0;i>i)&1)==((b>>j)&1)) tmp.unite(rs[i],rs[j]); MatrixTreeTheorem G(n); for(auto e:es) if(tmp.same(e.a,e.b)) G.add_edge(e.a,e.b,0); auto[k,res,_]=G.build(); if(k==2) ans+=res; } cout< using namespace std; #define call_from_test #include "../../vector/compress.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,c; cin>>n>>c; vector ts(c),is(c),ps(c); for(int i=0;i>ts[i]>>is[i]; if(ts[i]==0) cin>>ps[i],is[i]--; } vector ss(n,0); using P = pair; vector

vp; for(int i=0;i bit(vp.size()); fill(ss.begin(),ss.end(),0); for(int i=0;i using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,k; cin>>n>>k; using T = tuple; vector ws(n,0); vector< unordered_map > m(n); auto mget=[&](ll a,ll b){ if(!m[a].count(b)) return 0LL; ll res=ws[a]+ws[b]+m[a][b]; if(res%k) return res; return 0LL; }; auto f=[&](T a,T b){ ll al,ar,av; tie(al,ar,av)=a; ll bl,br,bv; tie(bl,br,bv)=b; return T(al,br,av+bv+mget(ar,bl)); }; auto g=[&](T a,ll){return a;}; auto h=[&](ll a,ll){return a;}; auto s=[&](T a){ ll al,ar,av; tie(al,ar,av)=a; return T(ar,al,av); }; using Node = NodeBase; constexpr size_t LIM = 1e6; using LCT = Path; LCT lct(f,g,h,s,0); for(int i=0;i>a>>b>>c; lct.evert(lct[b]); lct.link(lct[a],lct[b]); m[a][b]=m[b][a]=c; } int q; cin>>q; for(int i=0;i>op; if(op=="add"){ int x,d; cin>>x>>d; lct.expose(lct[x]); ws[x]+=d; lct.pushup(lct[x]); } if(op=="send"){ int s,t; cin>>s>>t; lct.evert(lct[s]); cout<(lct.query(lct[t]))<<"\n"; } } cout< using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../tools/trio.cpp" #include "../../tree/heavylightdecomposition.cpp" #include "../../segtree/basic/ushi.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,k; cin>>n>>k; HLD hld(n); using P = pair; map es; for(int i=1;i>a>>b>>c; hld.add_edge(a,b); es[P(a,b)]=es[P(b,a)]=c; } hld.build(); vector dep(n); MFP([&](auto dfs,int v,int p,ll d)->void{ dep[v]=d; for(int u:hld.G[v]) if(u!=p) dfs(u,v,d+es[P(u,v)]); })(0,-1,0); vector ws(n,0); auto con=[&](int a,int b){return hld.par[a]==b||hld.par[b]==a;}; auto cst= [&](int a,int b)->ll{ if(!con(a,b)) return 0; ll res=ws[a]+ws[b]+abs(dep[a]-dep[b]); return res%k?res:0; }; using T = trio; T ti(-1,-1,-1); auto f= [&](T a,T b){ if(a.first<0||a.second<0) return b; if(b.first<0||b.second<0) return a; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ if(con(a.first,b.first)) return T(a.second,b.second,a.third+b.third+cst(a.first,b.first)); swap(a.first,a.second); } swap(b.first,b.second); } return ti; }; SegmentTree seg(f,ti); vector vt; for(int i=0;i>q; for(int i=0;i>op; if(op=="add"){ int x,d; cin>>x>>d; ws[x]+=d; seg.set_val(hld.vid[x],T(x,x,0)); } if(op=="send"){ int s,t; cin>>s>>t; int u=hld.lca(s,t); T r1(ti),r2(ti); hld.for_each(s,u,[&](int l,int r){r1=f(r1,seg.query(l,r));}); hld.for_each_edge(t,u,[&](int l,int r){r2=f(r2,seg.query(l,r));}); cout< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #undef call_from_test using ll = long long; ll K; ll calc(ll val){return val%K?val:0;} struct Vertex{ ll w; void* handle; Vertex(ll w=0):w(w),handle(nullptr){} }; struct Cluster{ ll edge,all,lft,rgh; Cluster(ll edge=-1):edge(edge),all(0),lft(0),rgh(0){} void toggle(){ swap(lft,rgh); } static Cluster compress(Cluster x,Vertex *v,Cluster y){ Cluster nxt; nxt.all=x.all+y.all; if(~x.edge) x.lft=x.edge+(v->w); else nxt.all+=calc(x.rgh+(v->w)); if(~y.edge) y.rgh=(v->w)+y.edge; else nxt.all+=calc((v->w)+y.lft); nxt.lft=x.lft; nxt.rgh=y.rgh; return nxt; } static Cluster rake(Cluster x,Cluster){ return x; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n; cin>>n>>K; const size_t N = 1e5; TopTree T; vector vs(n); for(int i=0;i>a>>b>>c; T.link(vs[a],Cluster(c),vs[b]); } vector ws(n,0); int q; cin>>q; for(int i=0;i>op; if(op=="add"){ int x,d; cin>>x>>d; ws[x]+=d; T.set_vertex(vs[x],Vertex(ws[x])); } if(op=="send"){ int s,t; cin>>s>>t; Cluster res=T.get_path(vs[s],vs[t]); if(~res.edge) cout< using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../graph/twoedgeconnectedcomponents.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; TwoEdgeConnectedComponents tecc(n); for(int i=0;i>a>>b; tecc.add_edge(a,b); } int k=tecc.build(); auto G=tecc.forest(); vector cs(k); for(int i=0;i> dp(2,vector(k,0)); vector used(k,0); auto dfs= MFP([&](auto dfs,int v,int p)->void{ if(used[v]) return; used[v]=1; dp[0][v]=0; dp[1][v]=cs[v]; for(int u:G[v]){ if(u==p) continue; dfs(u,v); dp[0][v]+=max(dp[0][u],dp[1][u]); dp[1][v]+=dp[0][u]; } return; }); int ans=0; for(int i=0;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../tree/levelancestor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; using P = pair; vector > G(n); LevelAncestor la(n); for(int i=1;i>u>>v>>w; u--;v--; la.add_edge(u,v); G[u].emplace_back(v,w); G[v].emplace_back(u,w); } la.build(); vector dep(n,0); { queue

q; q.emplace(0,-1); while(!q.empty()){ int v,p; tie(v,p)=q.front();q.pop(); for(auto e:G[v]){ int u,c; tie(u,c)=e; if(u==p) continue; dep[u]=dep[v]+c; q.emplace(u,v); } } } auto dist=[&](int u,int v){return dep[u]+dep[v]-2*dep[la.lca(u,v)];}; auto path= [&](int u,int v,int d){ if(d==0) return u; int r=la.lca(u,v); int x=la.distance(u,r),y=la.distance(r,v); if(d<=x) return la.up(u,d); return la.up(v,(x+y)-d); }; for(int i=0;i>a>>b>>c; a--;b--;c--; auto calc= [&](int v,int u=-1){ return max({dist(a,v)*(a!=u), dist(b,v)*(b!=u), dist(c,v)*(c!=u)}); }; int p=la.lca(a,b),q=la.lca(b,c),r=la.lca(c,a); int v=la.dep[p]>la.dep[q]?p:(la.dep[q]>la.dep[r]?q:r); int ans=min({calc(a),calc(b),calc(c),calc(v)}); for(int u:{a,b,c}){ if(calc(v,u)>=ans) continue; int l=0,r=la.distance(u,v); while(l+1>1; int x=path(u,v,m); if(calc(x,u) using namespace std; #define call_from_test #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/xor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; ll n,k; cin>>n>>k; vector as(n); for(int i=0;i>as[i]; const int LOG = 20; const int sz = 1< cnt(sz,0); cnt[0]++; for(int i=0,s=0;i=0;v--){ cnt[v]/=2; if(cnt[v]<=k){ k-=cnt[v]; continue; } cout< using namespace std; #define call_from_test #include "../../graph/manhattanmst.cpp" #include "../../datastructure/unionfind.cpp" #include "../../graph/kruskal.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector xs(n),ys(n); for(int i=0;i>xs[i]>>ys[i]; vector us(n),vs(n); for(int i=0;i G(n); for(auto [u,v]:manhattanmst(us,vs)){ int c=max(abs(xs[u]-xs[v]),abs(ys[u]-ys[v])); G.add_edge(u,v,c); } cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../graph/twoedgeconnectedcomponents.cpp" #include "../../tree/diameterforvertex.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,m; cin>>n>>m; vector vs(n); for(int i=0;i>vs[i]; TwoEdgeConnectedComponents C(n); for(int i=0;i>s>>t; s--;t--; C.add_edge(s,t); } int k=C.build(); vector sm(k,0); for(int i=0;i used(k,-1); for(int i=0;i que; used[i]=sz++; que.emplace(i); vector vv; vector ws; while(!que.empty()){ int v=que.front();que.pop(); vv.emplace_back(v); ws.emplace_back(sm[v]); for(int u:T[v]){ if(~used[u]) continue; used[u]=sz++; que.emplace(u); } } DiameterForVertex H(ws); for(int v:vv) for(int u:T[v]) if(u using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../mod/rint.cpp" #undef call_from_test signed main(){ int n,k,m; cin>>n>>k>>m; using R = Rint; R::set_mod(m); if(n>k*2) drop(R(k).pow(n)); int sz=1<<(k*2-1); vector< vector > dp(k,vector(sz,0)); for(int i=0;i>d)&1) continue; dp[j][bit|(1< using namespace std; #define call_from_test #include "../../graph/dijkstra.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; vector ts(n),es(n); for(int i=0;i>ts[i]>>es[i]; Dijkstra G(n+1); for(int i=0;i>a>>b>>c; a--;b--;c--; G.add_edge(b,a,c); } for(int i=0;i using namespace std; #define call_from_test #include "../../matching/hopcroft_karp.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector ss(n); for(int i=0;i>ss[i]; int L=0,R=0; map mp; for(int i=0;i using namespace std; #define call_from_test #include "../../algorithm/mo.cpp" #include "../../vector/identity.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,k,q; cin>>n>>k>>q; vector as(k),bs(k); for(int i=0;i>as[i]>>bs[i],as[i]--,bs[i]--; vector ord=identity(n); vector pos=identity(n); auto moveL= [&](int i){ int x=pos[as[i]],y=pos[bs[i]]; swap(ord[x],ord[y]); swap(pos[ord[x]],pos[ord[y]]); }; auto moveR= [&](int i){ int x=as[i],y=bs[i]; swap(ord[x],ord[y]); swap(pos[ord[x]],pos[ord[y]]); }; Mo mo(q,400,moveL,moveR,moveL,moveR); vector qs(q),ls(q),rs(q),xs(q); for(int i=0;i>qs[i]>>ls[i]>>rs[i]>>xs[i]; ls[i]--;xs[i]--; mo.add(ls[i],rs[i]); } mo.build(); vector ans(q,-1); for(int i=0;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/ushi.cpp" #include "../../bbst/rbst/impl/persistent.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; auto f=[&](ll a,ll b){return a+b;}; auto flip=[&](ll a){return a;}; using Data = Ushi; using Node = Data::Node; const size_t LIM = 3e6; Persistent G(f,flip,0); int n,m; cin>>n>>m; auto as=read(n); auto bs=read(n); auto A=G.build(vector(as.begin(),as.end())); auto B=G.build(vector(bs.begin(),bs.end())); auto R=G.merge(A,B); for(int i=0;i>t; tie(A,B)=G.split(R,n); if(t==0){ int x,y,z; cin>>x>>y>>z; x--;y--; auto pa=G.split(A,x); auto qa=G.split(pa.second,z); auto pb=G.split(B,y); auto qb=G.split(pb.second,z); A=G.merge(pa.first,G.merge(qb.first,qa.second)); } if(t==1){ int p,q; cin>>p>>q; p--; cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/array.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test struct T; using Node = Array::Node; struct T{ Node* nxt; char c; T():nxt(nullptr){} T(Node* nxt,char c):nxt(nxt),c(c){} }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; auto cs=read(n); vector> G(n); for(int i=0;i+1>u>>v; u--;v--; G[u].emplace_back(v); } const size_t LIM = 1e6; using Data = Array; Basic H; vector ps(n,nullptr); ps[n-1]=H.create(Node(T(nullptr,cs[n-1]))); auto R=ps[n-1]; for(int i=n-2;i>=0;i--){ auto nxt=ps[i+1]; auto comp1=[&](Node* a,Node* b){ return H.order_of_key(a)val.c!=b->val.c) return (a->val.c)<(b->val.c); if(a->val.nxt==b->val.nxt) return false; if(!a->val.nxt) return true; if(!b->val.nxt) return false; return comp1(a->val.nxt,b->val.nxt); }; int l=-1,r=n-(i+1); // comp(ps[i], l) : false // comp(ps[i], r) : true while(l+1>1; auto p=H.find_by_order(R,m); if(comp2(ps[i],p)) r=m; else l=m; } auto s=H.split(R,r); R=H.merge(H.merge(s.first,ps[i]),s.second); } auto cur=ps[0]; while(cur){ cout<<(cur->val.c); cur=cur->val.nxt; } cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../tools/chminmax.cpp" #include "../../tree/lowestcommonancestor.cpp" #include "../../tree/auxiliarytree.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n; cin>>n; auto cs=read(n); AuxiliaryTree G(n); for(int i=1;i>s>>t; s--;t--; G.add_edge(s,t); } G.build(); auto dep=G.dep; vector> C(n); for(int i=0;i ds(n),idx(n); auto dijkstra=[&](auto &vs,auto &ss){ using P = pair; priority_queue, greater

> pq; for(int v:vs) ds[v]=n,idx[v]=-1; for(int s:ss) ds[s]=0,idx[s]=s,pq.emplace(ds[s],s); while(!pq.empty()){ int d=pq.top().first; int v=pq.top().second; pq.pop(); if(ds[v]ds[v]+c){ ds[u]=ds[v]+c; idx[u]=idx[v]; pq.emplace(ds[u],u); } } } }; vector ans(n,n); for(int c=0;c1); auto vs=C[c]; G.query(vs); dijkstra(vs,C[c]); for(int v:vs){ for(int u:G.T[v]){ if(idx[v]==idx[u]) continue; chmin(ans[idx[v]],G.distance(idx[v],idx[u])); chmin(ans[idx[u]],G.distance(idx[v],idx[u])); } } G.clear(vs); } for(int a:ans) cout< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; while(cin>>n,n){ Die d; for(int i=0;i<6;i++) d.fs[i]=i+1; int ans=d.top(); for(int i=0;i>s; d.roll(s[0]); ans+=d.top(); } cout< using namespace std; #define call_from_test #include "../../tools/gridbfs.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w,n; cin>>h>>w>>n; vector st(h); for(int i=0;i>st[i]; for(int i=0;i ys(n+1),xs(n+1); for(int i=0;i using namespace std; #define call_from_test #include "../../bbst/pb_ds_tree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int w,h,n; cin>>w>>h>>n; vector xs(n),ys(n); for(int i=0;i>xs[i]>>ys[i]; using P = pair; gtree

gx,gy; for(int i=0;i mx,my; for(int i=0;ifirst; int ty=gy.find_by_order(n-1)->first; if(!mx.count(tx)){ mx[tx]=0; for(int j=0;j using namespace std; #define call_from_test #include "../../graph/bfs.cpp" #include "../../tools/chminmax.cpp" #undef call_from_test signed main(){ int n,k; cin>>n>>k; vector cs(n),rs(n); for(int i=0;i>cs[i]>>rs[i]; vector > G(n); for(int i=0;i>x>>y; x--;y--; G[x].emplace_back(y); G[y].emplace_back(x); } vector< vector > di(n); for(int i=0;i dp(n,INF); vector used(n,0); dp[0]=0; for(int i=0;idp[j]) u=j; } if(u<0) break; used[u]=1; for(int j=0;jrs[u]) continue; chmin(dp[j],dp[u]+cs[u]); } } cout< using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../tools/chminmax.cpp" #include "../../vector/compress.cpp" #include "../../datastructure/rangeslide.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; ll d; cin>>n>>d; vector xs(n),ys(n); for(int i=0;i>xs[i]>>ys[i]; if(n==1){ cout<<(xs[0]<=d?ys[0]:0)<; auto calc= [&](int a,int b){ vector

res; MFP([&](auto dfs,int k,ll s,ll t)->void{ if(k==b){ res.emplace_back(s,t); return; } dfs(k+1,s,t); dfs(k+1,s+xs[k],t+ys[k]); dfs(k+1,s-xs[k],t-ys[k]); })(a,0,0); sort(res.begin(),res.end()); return res; }; auto v1=calc(0,h); auto v2=calc(h,n); reverse(v2.begin(),v2.end()); const ll INF = 1e17; vector vs; for(auto p:v1) vs.emplace_back(p.first); vs.emplace_back(-INF); vs.emplace_back(+INF); vs=compress(vs); vector ws(vs.size(),-INF); { int k=0; for(auto p:v1){ while(vs[k]b;}; RangeSlide slide(ws,cmp); vector ks; { int l=0,r=0; for(auto p:v2){ ll x=p.first,k=p.second; while(l<(int)vs.size()&&vs[l]< -x-d) l++; while(r<(int)vs.size()&&vs[r]<=-x+d) r++; if(l==r) continue; slide.add_range(l,r); ks.emplace_back(k); } } vs.clear(); v2.clear(); auto res=slide.build(); ll ans=0; for(int i=0;i<(int)res.size();i++) chmax(ans,ws[res[i]]+ks[i]); cout< using namespace std; #define call_from_test #include "../../tools/int128.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif using ll = __int128_t; ll sqrt(ll x){ assert(x>=0); if(x<=1) return x; ll l=0,r=x; while(l+1>1; if(m<=x/m&&m*m<=x) l=m; else r=m; } return l; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; while(cin>>n,n){ int m=n*(n+1)/2; vector bs(m),es,os; for(int i=0;i>bs[i]; for(ll b:bs) ((b&1)?os:es).emplace_back(b); sort(es.begin(),es.end()); sort(os.begin(),os.end()); ll a=sqrt(es[0]*es[1]/os[0]); cout< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); vector ts(6); do{ for(int i=0;i<6;i++) cin>>ts[i]; int sum=0; for(int t:ts) sum+=t; if(sum==0) break; auto check= [&](Die d)->int{ for(int i=0;i<6;i++) if(d.fs[i]<0) return 0; int a=d.top()+d.bottom(); int b=d.east()+d.west(); int c=d.south()+d.north(); if(a>b+c) return 0; if(b>(a+1)+c) return 0; if(c>(a+1)+b) return 0; return 1; }; string ans(sum,'Z'); sort(ts.begin(),ts.end()); do{ Die d; for(int i=0;i<6;i++) d.fs[i]=ts[i]; if(!check(d)) continue; string res(sum,'Z'); int flg=0; for(int i=0;ians[i]) break; } if(flg) ans=res; }while(next_permutation(ts.begin(),ts.end())); int p,q; cin>>p>>q; p--; if(ans[0]!='Z') cout< using namespace std; #define call_from_test #include "../../graph/chromatic.cpp" #undef call_from_test const double EPS = 1e-10; struct Point{ double x,y; Point(){} Point(double x,double y) :x(x),y(y){} Point operator+(Point p) {return Point(x+p.x,y+p.y);} Point operator-(Point p) {return Point(x-p.x,y-p.y);} Point operator*(double k){return Point(x*k,y*k);} Point operator/(double k){return Point(x/k,y/k);} }; typedef Point Vector; typedef vector Polygon; double norm(Vector a){ return a.x*a.x+a.y*a.y; } double abs(Vector a){ return sqrt(norm(a)); } double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; } bool calc(Point a1,Point a2,Point b1,Point b2){ if(abs(cross(a2-a1,b1-a1))>EPS) return 0; if(abs(cross(a2-a1,b2-a1))>EPS) return 0; double ml=0; ml=max(ml,abs(a1-a2)); ml=max(ml,abs(a1-b1)); ml=max(ml,abs(a1-b2)); ml=max(ml,abs(a2-b1)); ml=max(ml,abs(a2-b2)); ml=max(ml,abs(b1-b2)); return (ml+EPS>n,n){ vector p(n); vector name(n); map m; for(int i=0;i>name[i]; if(!m.count(name[i])){ int k=m.size(); m[name[i]]=k; } int x,y; while(cin>>x,~x){ cin>>y; p[i].emplace_back(x,y); } } vector > G(m.size(),vector(m.size(),0)); for(int i=0;i using namespace std; #define call_from_test #include "../../polynomial/polynomial.cpp" #undef call_from_test using P = Polynomial; P expr(string s,int &p); P factor(string s,int &p); P term(string s,int &p); int number(string s,int &p); P expr(string s,int &p){ P res; if(s[p]=='-'){ p++; res=-factor(s,p); }else res=factor(s,p); while(p<(int)s.size()){ if(s[p]=='+'){ p++; res=res+factor(s,p); continue; } if(s[p]=='-'){ p++; res=res-factor(s,p); continue; } break; } return res; } P factor(string s,int &p){ P res=term(s,p); while(p<(int)s.size()){ if(s[p]=='+') break; if(s[p]=='-') break; if(s[p]==')') break; res=res*term(s,p); } return res; } P term(string s,int &p){ if(s[p]=='('){ p++; P res=expr(s,p); assert(s[p]==')'); p++; if(s[p]=='^'){ p++; int k=number(s,p); res=res.pow(res,k); } return res; } int v=(s[p]=='x'?1:number(s,p)); if(p<(int)s.size()&&s[p]=='x'){ p++; if(p<(int)s.size()&&s[p]=='^'){ p++; int k=number(s,p); P res(k+1); res[k]=v; return res; } P res(2); res[1]=v; return res; } P res; res[0]=v; return res; } int number(string s,int &p){ int res=0; while(p<(int)s.size()&&isdigit(s[p])) res=res*10+(s[p++]-'0'); return res; } P calc(string s){ int p=0; return expr(s,p); } signed main(){ string s,t; while(cin>>s,s!="."){ cin>>t; P ps=calc(s); P pt=calc(t); P ans=gcd(ps,pt); ans.print(); } return 0; } ================================================ FILE: test/aoj/1300.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1300 #include using namespace std; #define call_from_test #include "../../string/split.cpp" #include "../../vector/compress.cpp" #include "../../mod/mint.cpp" #undef call_from_test using S = map; S add(S x,S y){ for(auto p:y) x[p.first]+=p.second; return x; } S mul(S x,int k){ for(auto &p:x) p.second*=k; return x; } S term(string s){ S res; int n=s.size(); for(int i=0;i conv(string s){ vector res; for(auto t:split(s,'+')) res.emplace_back(term(t)); return res; } signed solve(string s){ s.pop_back(); string x=s.substr(0,s.find("->")); string y=s.substr(s.find("->")+2); auto t1=conv(x); auto t2=conv(y); vector ms; for(auto rs:t1) for(auto p:rs) ms.emplace_back(p.first); for(auto rs:t2) for(auto p:rs) ms.emplace_back(p.first); ms=compress(ms); auto dc=dict(ms); int n=ms.size(); int m=t1.size()+t2.size(); using M = Mint; vector< vector > mat(n,vector(m)); for(int i=0;i<(int)t1.size();i++) for(auto p:t1[i]) mat[dc[p.first]][i]=M(p.second); for(int i=0;i<(int)t2.size();i++) for(auto p:t2[i]) mat[dc[p.first]][t1.size()+i]=-M(p.second); for(int j=0;j+1=j;k--) mat[j][k]/=mat[j][j]; for(int i=j+1;i=0;j--){ for(int i=0;i cof)->int{ map res; for(int i=0;i<(int)t1.size();i++) for(auto p:t1[i]) res[p.first]+=p.second*cof[i]; for(int i=0;i<(int)t2.size();i++) for(auto p:t2[i]) res[p.first]-=p.second*cof[t1.size()+i]; for(auto p:res) if(p.second!=0) return 0; return 1; }; const int MAX = 40000; for(ll l=1;l<=MAX;l++){ vector cof(m,0); cof[m-1]=l; for(int i=0;i+1MAX) continue; if(check(cof)){ for(int i=0;i>s,s!=".") solve(s); return 0; } ================================================ FILE: test/aoj/1308.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1308 #include using namespace std; #define call_from_test #include "../../linearalgebra/binarymatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int m,n,d; while(cin>>m>>n>>d,m){ vector > s(n,vector(m)); for(int i=0;i>s[i][j]; mat v(n*m,BS(0)); auto idx=[&](int y,int x){return y*m+x;}; auto in=[&](int y,int x){return 0<=y&&y > dp(n,vector(m,-1)); using P = pair; queue

q; dp[y][x]=0; q.emplace(y,x); int dy[]={0,0,1,-1}; int dx[]={1,-1,0,0}; while(!q.empty()){ tie(y,x)=q.front();q.pop(); if(dp[y][x]==d) v[z][idx(y,x)]=1; for(int k=0;k<4;k++){ int ny=y+dy[k],nx=x+dx[k]; if(!in(ny,nx)||~dp[ny][nx]) continue; dp[ny][nx]=dp[y][x]+1; q.emplace(ny,nx); } } }; for(int i=0;i using namespace std; #define call_from_test #include "../../string/rollinghash.cpp" #include "../../string/rectanglehash.cpp" #undef call_from_test int conv(char c){ if(isupper(c)) return c-'A'; if(islower(c)) return 26+c-'a'; if(isdigit(c)) return 52+c-'0'; if(c=='+') return 62; if(c=='/') return 63; assert(0); } vector decode(vector vs,int h,int w){ vector rs(h,string(w,'$')); for(int i=0;i>(5-k))&1)); return rs; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); int w,h,p; while(cin>>w>>h>>p,w){ vector ss(h); for(int i=0;i>ss[i]; vector ts(p); for(int i=0;i>ts[i]; const int MOD = 1e9+7; const int B1 = 1777771; const int B2 = 1e8+7; auto srh=rectangle_hash(decode(ss,h,w),p,p); vector< vector > found(h,vector(w,0)); auto pat=decode(ts,p,p); for(int rev=0;rev<2;rev++){ for(int rot=0;rot<4;rot++){ auto tmp(pat); for(int i=0;i(pat,p,p)[0][0]; for(int i=0;i using namespace std; #define call_from_test #include "../../linearalgebra/matrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Matrix; using arr = M::arr; int d; while(cin>>d,d){ arr vs(d+3); for(int i=0;i>vs[i]; int ans=0; M m(d+3,d+2); for(int i=0;i0.5&&abs(res[1]-vs[j])0.5) ans=j; } } cout< using namespace std; #define call_from_test #include "../../math/fraction.cpp" #undef call_from_test using ll = long long; using frac = fraction; int H,h,m,s; void print(frac f){ int t=f.num/(f.den*60); cout<<(t%(60*H))/60<<" "; cout<<(t%60)<<" "; cout<<(f.num)%(f.den*60)<<" "<=a.den) a.num-=a.den; ll tmp=__gcd(a.num,a.den); return frac(a.num/tmp,a.den/tmp); } signed main(){ cin.tie(0); ios::sync_with_stdio(0); while(cin>>H>>h>>m>>s,H){ const frac base(h*3600+m*60+s,1); const frac vh(1,3600*H),vm(1,3600),vs(1,60); frac t(max(h*3600+m*60+s-100,0),1); while(1){ frac x=norm2(t*vh); frac y=norm2(t*vm); frac z=norm2(t*vs); if(yc){ t1=c-a; t2=b-c; if(a!=b&&b!=c&&c!=a&&t1==t2) ans=min(ans,tmp); } } } if(ans!=frac(10000000,1)){ print(ans); break; } t=t+frac(1,1); } } return 0; } ================================================ FILE: test/aoj/1508.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1508 #include using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/ushi.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; vector vs(n); for(int i=0;i>vs[i]; auto f=[](int a,int b){return min(a,b);}; auto flip=[](int a){return a;}; const int INF = 1e9; using Data = Ushi; using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(f,flip,INF); auto rt=G.build(vector(vs.begin(),vs.end())); for(int i=0;i>x>>y>>z; if(x==0){ int l=y,r=z+1; rt=G.toggle(rt,l,r); rt=G.toggle(rt,l+1,r); } if(x==1){ int l=y,r=z+1; cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; const int OFS = 1e6; vector as(n); for(int i=0;i>as[i],as[i]+=OFS; WaveletMatrix wm(as); int q; cin>>q; for(int i=0;i>l>>r>>d; r++; d+=OFS; int ans=OFS*2; if(wm.rank(d,l) using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/dual.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,a,d; cin>>n>>a>>d; using ll = long long; struct E{ ll a,b,c; E(){} E(ll a,ll b,ll c):a(a),b(b),c(c){} bool operator!=(const E &o) const{ return make_tuple(a,b,c)!=make_tuple(o.a,o.b,o.c); } }; const ll MAX = 1e9; auto h=[](E a,E b){ E c(a.a+a.b*(a.c+b.a),a.b*b.b,0); c.c=c.a/c.b+b.c; c.a%=c.b; if(c.b>MAX){ c.a=max(0LL,MAX-(c.b-c.a)); c.b=MAX; } return c; }; E ei(0,1,0); using Data = Dual; using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(h,ei); auto r=G.build(vector(n,ei)); for(int i=0;i>m; for(int i=0;i>x>>y>>z; y--; if(x==0) r=G.toggle(r,y,z); if(x==1) r=G.update(r,y,z,E(0,1,1)); if(x==2) r=G.update(r,y,z,E(0,2,0)); } int k; cin>>k; k--; cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/farthest.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using Node = NodeBase; constexpr size_t LIM = 1e6; using LCT = Farthest; LCT lct; int n; cin>>n; for(int i=0;i>s>>t; s--;t--; lct.evert(lct[t]); lct.link(lct[s],lct[t]); } for(int i=0;ild)+1<<"\n"; } cout< using namespace std; #define call_from_test #include "../../tree/rerooting.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; auto fold=[&](int a,int b){return max(a,b);}; auto lift=[&](int a,int b){return a+b;}; ReRooting G(n,fold,lift,0); for(int i=1;i>u>>v; u--;v--; G.add_edge(u,v,1); } auto ans=G.build(); for(int a:ans) cout<<(n-1)*2-a<<"\n"; cout< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #undef call_from_test struct Vertex{ void* handle; int idx; Vertex(int idx=-1):handle(nullptr),idx(idx){} }; struct Cluster{ int ans,lf,rg,len; Cluster(int l=0):ans(l),lf(l),rg(l),len(l){} Cluster(int ans,int lf,int rg,int len): ans(ans),lf(lf),rg(rg),len(len){} void toggle(){swap(lf,rg);} static Cluster compress(Cluster x,Vertex*,Cluster y){ return Cluster( max(x.rg,y.lf), max(x.lf,x.len+y.lf), max(y.rg,y.len+x.rg), x.len+y.len); } static Cluster rake(Cluster x,Cluster y){ return Cluster(0,max(x.lf,x.len+y.rg),max(x.rg,y.rg),x.len); } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; const size_t N = 1e5; TopTree T; int n; cin>>n; vector vs(n); for(int i=0;i>u>>v; u--;v--; T.link(vs[u],Cluster(1),vs[v]); } for(int i=0;i using namespace std; #define call_from_test #include "../../vector/compress.cpp" #include "../../maxflow/dinic.cpp" #undef call_from_test int main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector es(n); for(int i=0;i>es[i]; const int L=5; vector vs; for(string &s:es){ for(char &c:s){ if(isdigit(c)) c=c-'0'; else c=c-'a'+10; } for(int i=0;i=10) c='a'+(c-10); else c='0'+c; } return s; }; int m=vd.size(); Dinic G(m+2); int S=m,T=m+1; vector used(m,0); using P = pair; map mp; for(string &s:es){ for(int i=0;i as; for(auto s:es) as.emplace_back(s); for(auto s:vs) as.emplace_back(s); sort(as.begin(),as.end()); cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../vector/compress.cpp" #include "../../datastructure/radixheap.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif const int BS = 8, BS2 = BS * 2; const int msk = (1<>n,n){ int m,k,r; cin>>m>>k>>r; vector x(n),y(n),z(n); for(int i=0;i>x[i]>>y[i]>>z[i]; vector u1(m),v1(m),u2(m),v2(m),w(m); for(int i=0;i>u1[i]>>v1[i]>>u2[i]>>v2[i]>>w[i]; vector vx(x),vy(y); for(int p=0;p=1) vx.emplace_back(u1[p]-1); if(u2[p]+1<=r) vx.emplace_back(u2[p]+1); if(v1[p]-1>=1) vy.emplace_back(v1[p]-1); if(v2[p]+1<=r) vy.emplace_back(v2[p]+1); } vx=compress(vx); vy=compress(vy); auto mx=dict(vx); auto my=dict(vy); // kokokara y yuusen auto idx=[&](int cy,int cx,int f){return (f<void{ vector wy,wx; for(int p=0;p > vs; { for(int i=0;i q; { int v=idx(zy[y[a]],zx[x[a]],z[a]); dist[v]=0; q.emplace(dist[v],v); } while(!q.empty()){ auto p=q.pop(); int v=p.second; if(dist[v]>BS2,i=(v>>BS)&msk,j=v&msk; int ai=my[wy[i]],aj=mx[wx[j]]; if(f==k){ vs.emplace_back((ai<dist[v]+c){ dist[u]=dist[v]+c; q.emplace(dist[u],u); } }; if(hole[idx(ai,aj,f+1)]){ push(i,j,f+1); continue; } if(i+1=0) push(i-1,j,f); if(j+1=0) push(i,j-1,f); } } { for(int i=0;i<(sy< q; for(auto p:vs){ int v=p.first,d=p.second; add[v]=d; q.emplace(add[v],v); } while(!q.empty()){ auto p=q.pop(); int v=p.second; if(add[v]>BS,j=v&msk; auto push= [&](int ni,int nj){ int u=(ni<add[v]+c){ add[u]=add[v]+c; q.emplace(add[u],u); } }; if(i+1=0) push(i-1,j); if(j+1=0) push(i,j-1); } } }; memset(dp,0,sizeof(dp)); for(int p=0;p using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../tree/ahu.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); auto construct=[&](int h,int w){ auto st=read(h); st.emplace(st.begin(),string(w,'.')); st.emplace(st.end(),string(w,'.')); for(auto &s:st) s='.'+s+'.'; h=st.size();w=st[0].size(); int dy[]={0,0,1,-1,1,1,-1,-1}; int dx[]={1,-1,0,0,1,-1,1,-1}; auto in=[&](int y,int x){return 0<=y and y; queue

que; auto push=[&](int ny,int nx){ if(~blg[ny][nx]) return; blg[ny][nx]=n; que.emplace(ny,nx); }; push(y,x); while(!que.empty()){ auto[cy,cx]=que.front();que.pop(); for(int k=0;k> S(n); for(int i=0;i>h>>w,h||w){ auto T1=construct(h,w); cin>>h>>w; auto T2=construct(h,w); cout<<(T1==T2?"yes":"no")<<'\n'; } return 0; } ================================================ FILE: test/aoj/1615.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1615 #include using namespace std; #define call_from_test #include "../../maxflow/dinic.cpp" #include "../../maxflow/leastflow.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; while(cin>>n>>m,n){ vector xs(m),ys(m); for(int i=0;i>xs[i]>>ys[i],xs[i]--,ys[i]--; for(int d=0;d<=n;d++){ for(int l=n-d;l>=0;l--){ int r=l+d; int S=n+m,T=n+m+1; LeastFlow G(n+m+2); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../polynomial/hash.cpp" #undef call_from_test using M1 = Mint; using M2 = Mint; using M3 = Mint; PolynomialHash ph(100); using V = decltype(ph)::V; vector > vs; vector > > vm; V expr(string &s,int &p,int d); V term(string &s,int &p,int d); V factor(string &s,int &p,int d); V number(string &s,int &p); V expr(string &s,int &p,int d){ V res=term(s,p,d); vs[d].emplace_back(res); while(p<(int)s.size()){ if(s[p]=='+'){ p++; V b=term(s,p,d); vs[d].emplace_back(b); res+=b; continue; } break; } vs[d].emplace_back(0); vm[d].emplace_back(); return res; } V term(string &s,int &p,int d){ V res=factor(s,p,d); vm[d].emplace_back(); vm[d].back().emplace_back(res); while(p<(int)s.size()){ if(s[p]=='*'){ p++; V b=factor(s,p,d); vm[d].back().emplace_back(b); res*=b; continue; } break; } return res; } V factor(string &s,int &p,int d){ if(s[p]=='('){ p++; V res=expr(s,p,d+1); assert(s[p]==')'); p++; return res; } return number(s,p); } V number(string &s,int &p){ int k=s[p++]-'0'; return V(k); } signed main(){ using ll = long long; int n; while(cin>>n,n){ string s; cin>>s; vs.assign(1010,vector()); vm.assign(1010,vector >()); V nv((ll)n); int p=0; expr(s,p,0); ll ans=0; for(int i=0;i<1010;i++){ auto &v=vs[i]; if(v.empty()) continue; auto comp=[](V a,V b){ auto [a1,a2,a3]=a; auto [b1,b2,b3]=b; return make_tuple(a1.v,a2.v,a3.v) dp(comp); V uku(0); dp[uku]++; for(int j=0;j<(int)v.size();j++){ if(v[j]==V(0)){ dp.clear(); uku=V(0); dp[uku]++; continue; } { V malta(1); for(int k=0;k<(int)vm[i][j].size();k++){ malta*=vm[i][j][k]; ans+=dp[uku+malta-nv]; } } { V malta(1); map dp2(comp); dp2[malta*nv]++; for(int k=1;k<(int)vm[i][j].size();k++){ malta*=vm[i][j][k]; ans+=dp2[malta]; dp2[malta*nv]++; } } { V malta(1); uku+=v[j]; for(int k=0;k+1<(int)vm[i][j].size();k++){ malta*=vm[i][j][k]; dp[uku-v[j]/malta]++; } } dp[uku]++; } } cout< using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../tools/chminmax.cpp" #include "../../math/enumerate_primes.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; auto ps=enumerate_primes(4e7); ll n; while(cin>>n,n){ vector qs,vs; { ll t=n; for(auto p:ps){ if(tvoid{ if(x+y+z>=ans) return; if(t==m){ assert(x*y*z==n); chmin(ans,x+y+z); return; } int s=vs[t]; vector po(s+1,1); for(int i=0;i using namespace std; #define call_from_test #include "../../linearalgebra/matrix.cpp" #include "../../math/tetrahedra.cpp" #undef call_from_test signed main(){ int n; while(cin>>n,n){ vector as(n); for(int i=0;i>as[i]; double ans=0; for(int i=0;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../tools/all_permutations.cpp" #undef call_from_test signed solve(){ cin.tie(0); ios::sync_with_stdio(0); const int n=9; vector as(n),bs(n); for(int i=0;i>as[i]; for(int i=0;i>bs[i]; int num=0,cnt=0; auto f= [&](vector vs){ int x=0,y=0; for(int i=0;ibs[i]) y+=as[vs[i]]+bs[i]; } if(x>T; while(T--) solve(); return 0; } ================================================ FILE: test/aoj/2212.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2212 #include using namespace std; #define call_from_test #include "../../string/trie.cpp" #include "../../string/ahocorasick.cpp" #undef call_from_test int dp[111][55][55]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w; while(cin>>h>>w,h){ vector ss(h); for(int i=0;i>ss[i]; int p; cin>>p; vector ps(p); for(int i=0;i>ps[i]; auto conv= [&](char c){ if(c=='U') return 0; if(c=='R') return 1; if(c=='D') return 2; if(c=='L') return 3; return -1; }; AhoCorasick<4, false> aho(conv); for(int i=0;i; queue que; for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../graph/stronglyconnectedcomponent.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; int n,m; cin>>n>>m; SCC scc(n); for(int i=0;i>s>>d; s--;d--; scc.add_edge(s,d); } int k=scc.build(); vector dp(k,1); vector indeg(k,0); M ans(1); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../bflow/capacityscaling.cpp" #undef call_from_test signed main(){ using P = pair; using ll = long long; const ll INF = 1<<30; int n,m; cin>>n>>m; vector< vector

> H(n); MinCostFlow G(n); for(int i=0;i>x>>y>>s; H[x].emplace_back(y,s); G.add_edge(y,x,1,INF,-s); } vector dp(n,0); for(int i=0;i using namespace std; #define call_from_test #include "../../graph/dynamicconnectivity.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; DynamicConnectivity dc(n,q); vector ts(q),us(q),vs(q); for(int i=0;i>ts[i]>>us[i]>>vs[i]; if(ts[i]==1) dc.insert(i,us[i],vs[i]); if(ts[i]==2) dc.erase( i,us[i],vs[i]); } dc.build(); auto f= [&](int x){ if(x>=q||ts[x]!=3) return; cout<<(dc.puf.same(us[x],vs[x])?"YES":"NO")< using namespace std; #define call_from_test #include "../../string/trie.cpp" #include "../../string/ahocorasick.cpp" #undef call_from_test signed dp[2][2][501][21][601]; bool used[2][2][501][21][601]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,k; while(cin>>n>>m>>k,n){ memset(dp,0,sizeof(dp)); memset(used,0,sizeof(used)); vector from(n),to(n); for(int i=0;i>from[i]>>to[i]; vector season(k); for(int i=0;i>season[i]; AhoCorasick<26, false> aho('a'); for(int i=0;i v; for(int i=0;i idx; for(int i=0;i<(int)v.size();i++) idx[v[i]]=i; vector > G(v.size()); for(int i=0;i; queue q; for(int i=0;i<(int)v.size();i++){ dp[0][0][i][0][0]=1; q.emplace(0,0,i,0,0); } while(!q.empty()){ int c,d,x,p,pos; tie(c,d,x,p,pos)=q.front();q.pop(); if(d==m) break; int f=d&1; if(p==(int)v[x].size()){ for(int y:G[x]){ int npos=aho.move(pos,v[y][0]); if(aho.cnt[npos]>1) continue; int nc=aho.cnt[npos]; if(c&&nc) continue; dp[c||nc][!f][y][1][npos]+=dp[c][f][x][p][pos]; dp[c||nc][!f][y][1][npos]%=MOD; if(!used[c||nc][!f][y][1][npos]) q.emplace((c||nc),d+1,y,1,npos); used[c||nc][!f][y][1][npos]=1; } }else{ int npos=aho.move(pos,v[x][p]); int np=p+1; if(aho.cnt[npos]>1) goto END; int nc=aho.cnt[npos]; if(c&&nc) goto END; dp[c||nc][!f][x][np][npos]+=dp[c][f][x][p][pos]; dp[c||nc][!f][x][np][npos]%=MOD; if(!used[c||nc][!f][x][np][npos]) q.emplace((c||nc),d+1,x,np,npos); used[c||nc][!f][x][np][npos]=1; } END: dp[c][f][x][p][pos]=0; used[c][f][x][p][pos]=0; } int ans=0; for(int i=0;i<(int)v.size();i++){ for(int j=0;j using namespace std; #define call_from_test #include "../../vector/compress.cpp" #include "../../algorithm/mo.cpp" #include "../../tree/eulertourforedge.cpp" #include "../../tree/lowestcommonancestor.cpp" #include "../../tree/mo_on_tree.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector xs(n+1); for(int i=1;i<=n;i++) cin>>xs[i]; auto cs=compress(xs); auto dc=dict(cs); vector ys(n+1); for(int i=0;i<=n;i++) ys[i]=dc[xs[i]]; vector zs(n); BIT bit(n); auto expand=[&](int e){bit.add(zs[e],+1);}; auto shrink=[&](int e){bit.add(zs[e],-1);}; MoOnTree mo(n+1,400,expand,shrink); LowestCommonAncestor lca(n+1); vector as(n),bs(n); as[0]=0;bs[0]=1; mo.add_edge(as[0],bs[0]); lca.add_edge(as[0],bs[0]); for(int i=1;i>as[i]>>bs[i]; mo.add_edge(as[i],bs[i]); lca.add_edge(as[i],bs[i]); } vector vs(q),ws(q),ls(q); for(int i=0;i>vs[i]>>ws[i]>>ls[i]; mo.add_query(vs[i],ws[i]); } mo.build(); lca.build(); for(int i=0;i ans(q); for(int i=0;i using namespace std; #define call_from_test #include "../../math/totient_table.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int MAX = 1e6; auto ts=totient_table(MAX); vector sm(ts.begin(),ts.end()); for(int i=0;i>t; for(int i=0;i>n; cout< using namespace std; #define call_from_test #include "../../mincostflow/primaldual.cpp" #include "../../tools/chminmax.cpp" #include "../../vector/identity.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,v,xleft,xright; cin>>n>>v>>xleft>>xright; int S=n+n,T=n+n+1,L=n+n+2,R=n+n+3; PrimalDual G(n+n+4); G.add_edge(S,L,1,0); G.add_edge(L,T,1,0); G.add_edge(S,R,1,0); G.add_edge(R,T,1,0); vector xs(n),ts(n),ps(n); for(int i=0;i>xs[i]>>ts[i]>>ps[i]; if(abs(xs[i]-xleft)<=ts[i]*v) G.add_edge(L,i,1,0); if(abs(xs[i]-xright)<=ts[i]*v) G.add_edge(R,i,1,0); } auto init=[&](auto &h)->void{ fill(h.begin(),h.end(),0); auto ord=identity(n); sort(ord.begin(),ord.end(), [&](int i,int j){return ts[i] using namespace std; #define call_from_test #include "../../string/palindromictree.cpp" #include "../../string/rollinghash.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; string s,t; cin>>s>>t; PalindromicTree p1(s),p2(t); const int MOD = 1e9+7; const int BASE1 = 1777771; const int BASE2 = 1e6+3; RollingHash rs1(s),rt1(t); RollingHash rs2(s),rt2(t); const int MAX = 5e5+100; map, int> m1[MAX]; for(int i=2;i<(int)p1.size();i++){ PalindromicTree::node& u=p1.vs[i]; if(u.app<0) continue; auto p=make_pair(rs1.find(u.app,u.app+u.len), rs2.find(u.app,u.app+u.len)); m1[u.len][p]=u.cnt; } ll ans=0; for(int i=2;i<(int)p2.size();i++){ PalindromicTree::node& u=p2.vs[i]; auto p=make_pair(rt1.find(u.app,u.app+u.len), rt2.find(u.app,u.app+u.len)); if(u.app<0||!m1[u.len].count(p)) continue; ans+=(ll)m1[u.len][p]*u.cnt; } cout< using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../vector/multi.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using D = long double; int h,n,p,m,k; cin>>h>>n>>p>>m>>k; p--; vector bs(h,-1); for(int i=0;i>x>>y; bs[h-x]=y-1; } auto dp=make_v(h+1,k+1,n+1); fill_v(dp,0); dp[0][0][p]=1; for(int i=0;ik) continue; for(int l=0;l=0) dp[i+1][j+1][l-1]+=dp[i][j][l]/(n-1.0),x+=1.0; dp[i+1][j+1][l]+=dp[i][j][l]*(n-1.0-x)/(n-1.0); } } } D ans=*max_element(dp[h][k].begin(),dp[h][k].end()); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../tools/drop.cpp" #include "../../io/precision.cpp" #include "../../geometry/projectilemotion.cpp" #undef call_from_test using D = double; struct Point{ D x,y; Point(){} Point(D x,D y):x(x),y(y){} }; istream &operator>>(istream &is,Point &p){ is>>p.x>>p.y; return is; } signed main(){ int n; D v; cin>>n>>v; Point t; cin>>t; vector ps(n),qs(n); for(int i=0;i>ps[i]>>qs[i]; for(int i=0;i=t.y) drop("Yes"); drop("No"); } const D EPS = 1e-10; vector cand; auto push= [&](Point s){ for(auto pq:projectile_motion(v,g,s.x,s.y)){ D d=pq.first; cand.emplace_back(d); cand.emplace_back(d+EPS); cand.emplace_back(d-EPS); } }; for(int i=0;i=t.x) continue; push(ps[i]); push(qs[i]); push(Point(ps[i].x,qs[i].y)); push(Point(qs[i].x,ps[i].y)); } push(t); auto getY= [&](D p,D q,D x){ D ti=x/p; return q*ti-g/2*ti*ti; }; auto in= [&](int k,D p,D q)->int{ if(ps[k].x>=t.x) return 0; if(ps[k].y using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/arborescence_edmond.cpp" #undef call_from_test const int MAX = 111; double v[MAX][MAX]; double c[MAX][MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; for(int i=0;i>v[i][j]; for(int i=0;i G(m+1); for(int i=0;i using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/arborescence_edmond.cpp" #undef call_from_test const int MAX = 111; double v[MAX][MAX]; double c[MAX][MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; for(int i=0;i>v[i][j]; for(int i=0;i G(m+1); for(int i=0;i using namespace std; #define call_from_test #include "../../maxflow/dinic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,e,q; cin>>n>>e>>q; Dinic G(n); vector< map > I(n); for(int i=0;i>f>>t; f--;t--; I[f][t]=G.add_edge(f,t,1); I[t][f]=G.add_edge(t,f,1); } vector ms(q),as(q),bs(q); for(int i=0;i>ms[i]>>as[i]>>bs[i]; as[i]--;bs[i]--; if(I[as[i]].count(bs[i])) continue; I[as[i]][bs[i]]=G.add_edge(as[i],bs[i],0); I[bs[i]][as[i]]=G.add_edge(bs[i],as[i],0); } int res=G.flow(0,n-1); for(int i=0;i using namespace std; #define call_from_test #include "../../graph/multipleeuleriantrail.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int MAX = 52; auto idx=[&](char c)->int{ if(islower(c)) return c-'a'; assert(isupper(c)); return c-'A'+26; }; string s; while(cin>>s,s!="#"){ int n=s.size(); if(n<=2){ cout<<"No Results"< > G(MAX); for(int i=0;i+1 ind(MAX,0),outd(MAX,0); for(int v=0;v(ind[i]-outd[i],0); int m=accumulate(ind.begin(),ind.end(),0)+1; int add=max(res-1,0); m+=add; if(m > H(MAX); for(int v=0;v using namespace std; #define call_from_test #include "../../string/split.cpp" #include "../../maxflow/dinic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int DEG = 55; const int INF = 1<<28; int n,m; while(cin>>n>>m,n){ Dinic flow(n); int ed[DEG][55][55]; memset(ed,0,sizeof(ed)); for(int i=0;i>a>>b>>s; a--;b--; flow.add_edge(a,b,0); for(string t:split(s,'+')){ if(!count(t.begin(),t.end(),'x')){ ed[0][a][b]+=stoi(t); ed[0][b][a]+=stoi(t); }else if(t.back()=='x'){ t.pop_back(); if(t.empty()) t="1"; ed[1][a][b]+=stoi(t); ed[1][b][a]+=stoi(t); }else{ auto v=split(t,'^'); v[0].pop_back(); if(v[0].empty()) v[0]="1"; ed[stoi(v[1])][a][b]+=stoi(v[0]); ed[stoi(v[1])][b][a]+=stoi(v[0]); } } } vector ans(DEG); for(int i=DEG-1;i>=0;i--){ for(auto& v:flow.G){ for(auto& e:v){ if(e.cap) e.cap=INF; e.cap+=ed[i][e.dst][flow.G[e.dst][e.rev].dst]; } } ans[i]=flow.flow(0,n-1); } bool f=1; for(int i=DEG-1;i>=0;i--){ if(!ans[i]){ if(i) continue; if(f) cout<0) cout<<"x"; if(i>1) cout<<"^"< using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../vector/compress.cpp" #include "../../vector/fusion.cpp" #include "../../vector/near.cpp" #include "../../segtree/basic/dual.cpp" #define SegmentTree SegmentTree2 #include "../../segtree/basic/lazy.cpp" #undef SegmentTree #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int q; cin>>q; vector ts(q),as(q),bs(q),ys(q); for(int i=0;i>ts[i]>>as[i]>>bs[i]>>ys[i]; vector vs=near(fusion(as,bs),-1,0,1); vs.emplace_back(0); vs.emplace_back(1e9+10); vs=compress(vs); auto dc=dict(vs); int m=dc.size(); using P = pair; auto h=[&](P a,P b){ if(a.first) return a; return P(b.first,max(a.second,b.second)); }; P ei(0,0); SegmentTree

seg(h,ei); seg.init(m); for(int i=0;i zs(m); for(int i=0;i seg2(ff,gg,gg,INT_MAX,-1); seg2.build(zs); for(int i=0;i using namespace std; #define call_from_test #include "../../graph/bipartitedecomposition.cpp" #include "../../algorithm/partialsum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; BipartiteDecomposition G(n); for(int i=0;i>u>>v; u--;v--; G.add_edge(u,v); } auto res=G.build(); if(res.empty()){ cout<<-1< vs; for(auto[x,y]:res){ offset+=min(x,y); vs.emplace_back(abs(x-y)); } auto dp=partial_sum<100000>(vs); long long ans=0; for(int i=0;i<=n;i++){ if(!dp[i]) continue; long long part=offset+i; ans=max(ans,part*(n-part)-m); } cout< using namespace std; #define call_from_test #include "../../linearalgebra/squarematrix.cpp" #include "../../mod/mint.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int MAX = 80; const int MOD = 1e9+9; using M = Mint; using SM = SquareMatrix; using ll = long long; ll w,h,n; ll cnt=0; while(cin>>w>>h>>n,w){ vector x(n),y(n); for(int i=0;i>x[i]>>y[i]; { using P = pair; vector

vp; for(int i=0;i=0) b[i][i-1]=M(1); if(i+1 using namespace std; #define call_from_test #include "../../graph/nicetree.cpp" #include "../../mod/mint.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; while(cin>>n>>m,n){ NiceTree G(n); using P = pair; set

es; for(int i=0;i>a>>b; a--;b--; G.add_edge(a,b); es.emplace(a,b); es.emplace(b,a); } if(n&1){ cout<<0<; vector> dps(T.size()); auto base= [&](int v){ const auto &bag=T[v].bag; auto &dp=dps[v]; dp.assign(1<>j)&1) bit|=buff[chd_bag[j]]; dp[bit]=pr[i]; } }; auto forget= [&](int v,int rmv){ base(v); const auto &bag=T[v].bag; const auto &chd=T[v].child; const auto &chd_bag=T[chd[0]].bag; const auto &pr=dps[chd[0]]; auto &dp=dps[v]; for(int i=0;i<(int)pr.size();i++){ int bit=0,used=0; for(int j=0;j<(int)chd_bag.size();j++){ if((~i>>j)&1) continue; if(rmv==chd_bag[j]) used=1; if(rmv!=chd_bag[j]) bit|=buff[chd_bag[j]]; } if(!used){ for(int j=0;j<(int)bag.size();j++){ if((bit>>j)&1) continue; if(es.count(P(bag[j],rmv))) dp[bit|(1< using namespace std; #define call_from_test #include "../../algorithm/knuthyao.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector ws(n); for(int i=0;i>ws[i]; vector sm(n+1); for(int i=0;i(n,cost)< using namespace std; #define call_from_test #include "../../datastructure/skewheap.cpp" #include "../../algorithm/optimalbinarytree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector ws(n); for(int i=0;i>ws[i]; cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../linearalgebra/squarematrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int MAX = 160; const int INF = 1e8; struct M{ int v; M(){*this=add_identity();} M(int v):v(v){} M operator+(const M &a)const{return M(max(v,a.v));} M operator*(const M &a)const{return M(v+a.v);} static M add_identity(){return M(-INF);} static M mul_identity(){return M(0);} }; using SM = SquareMatrix; int n,m,k; cin>>n>>m>>k; vector vs(1),ws(1); for(int i=0;i>a>>b>>c; chmax(vs[0][a][b].v,c); } for(int t=0;t<20;t++){ SM tv=vs[t]*vs[t]; SM tw=vs[t]*ws[t]; vs.emplace_back(tv); ws.emplace_back(tw); } auto len=[&](SM &sm)->int{ int res=0; for(int i=0;i=0;t--){ SM tmp=res*ws[t]; SM nxt=res*vs[t]; if(len(tmp)100) return 0; int dp[MAX][MAX]; int pr[MAX][MAX]; for(int i=0;idp[ans][pos]) pos=v; vector vx; for(int i=ans;i>=0;i--){ vx.emplace_back(pos); pos=pr[i][pos]; } reverse(vx.begin(),vx.end()); for(int i=0;i<=ans;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../string/rollinghash.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; string s; cin>>s; const int MOD = 1e9+7; const int B1 = 1e8+7; const int B2 = 1777771; RollingHash rh1(s); RollingHash rh2(s); int l=0,r=1; set> sp; for(int i=0;i>t; if(t=="L++") l++; if(t=="L--") l--; if(t=="R++") r++; if(t=="R--") r--; sp.emplace(rh1.find(l,r),rh2.find(l,r)); } cout< using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/or.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; ll m; cin>>n>>m; vector as(n),ps(n); for(int i=0;i>as[i]; for(int i=0;i>ps[i]; vector dp(1<>i)&1) continue; ll k=as[i]/gcd(t,as[i]); t=(t<=m/k?t*k:m+1); if(t>m) break; } dp[bit]=m/t; } fwht(dp,bitwise_or::moebius); double ans=0; for(int bit=0;bit<(1<>i)&1) po*=ps[i]/100.0; else po*=1.0-(ps[i]/100.0); ans+=po*abs(dp[bit]); } cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; struct T{ int sm,va,vi,vl,vr; T(int sm,int va,int vi,int vl,int vr): sm(sm),va(va),vi(vi),vl(vl),vr(vr){} T(){} }; const int INF = 1e9; int ei=-INF; auto f=[&](T a,T b){ T c; c.sm=a.sm+b.sm; c.va=a.va+b.va; c.vi=max({a.vi,b.vi,a.vr+b.vl}); c.vl=max({a.vl,a.va+b.vl}); c.vr=max({b.vr,a.vr+b.va}); return c; }; auto g=[&](T a,int b){ if(b>=0) return T(a.sm,b*a.sm,b*a.sm,b*a.sm,b*a.sm); return T(a.sm,b*a.sm,b,b,b); }; auto h=[&](int,int b){return b;}; auto s= [&](T a){ swap(a.vl,a.vr); return a; }; using Node = NodeBase; constexpr size_t LIM = 2e5+100; using LCT = Path; LCT lct(f,g,h,s,ei); vector ws(n); for(int i=0;i>ws[i]; for(int i=0;i>a>>b; a--;b--; lct.evert(lct[b]); lct.link(lct[a],lct[b]); } for(int i=0;i>t>>a>>b>>c; a--;b--; if(t==1){ lct.evert(lct[a]); lct.update(lct[b],c); } if(t==2){ lct.evert(lct[a]); auto res=lct.query(lct[b]); cout< using namespace std; #define call_from_test #include "../../tree/heavylightdecomposition.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; HLD hld(n); vector ws(n); for(int i=0;i>ws[i]; for(int i=0;i+1>a>>b; a--;b--; hld.add_edge(a,b); } hld.build(); using T = tuple; using E = pair; T ti(-1,-1,-1,-1,-1); E ei(-1,-(1e4+10)); auto f=[&](T a,T b){ if(a==ti) return b; if(b==ti) return a; auto[asz,ava,avi,avl,avr]=a; auto[bsz,bva,bvi,bvl,bvr]=b; int csz=asz+bsz; int cva=ava+bva; int cvi=max({avi,bvi,avr+bvl}); int cvl=max(avl,ava+bvl); int cvr=max(bvr,avr+bva); return T(csz,cva,cvi,cvl,cvr); }; auto g=[&](T a,E p){ if(p==ei) return a; auto[asz,ava,avi,avl,avr]=a; auto[v,b]=p; if(~v) asz=1; if(b>=0) return T(asz,b*asz,b*asz,b*asz,b*asz); return T(asz,b*asz,b,b,b); }; auto h=[&](E,E b){return b;}; SegmentTree seg(f,g,h,ti,ei); vector vt(n); for(int i=0;i>t>>a>>b>>c; a--;b--; if(t==1){ hld.for_each(a,b,[&](int l,int r){seg.update(l,r,E(-1,c));}); } if(t==2){ int c=hld.lca(a,b); T x=ti,y=ti; hld.for_each(c,a,[&](int l,int r){x=f(seg.query(l,r),x);}); hld.for_each_edge(c,b,[&](int l,int r){y=f(seg.query(l,r),y);}); auto&[xsz,xva,xvi,xvl,xvr]=x; swap(xvl,xvr); auto[vsz,vva,vvi,vvl,vvr]=f(x,y); cout< using namespace std; #define call_from_test #include "../../algorithm/knuthyao.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector xs(n),ys(n); for(int i=0;i>xs[i]>>ys[i]; auto calc= [&](int i,int k,int j){ return (xs[k+1]-xs[i])+(ys[k]-ys[j]); }; cout<(n,calc)< using namespace std; #define call_from_test #include "../../matching/bipartite.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; while(cin>>n,n){ vector> xss; vector> yss; for(int i=0;i xs(3),ys(3); for(int j=0;j<3;j++) cin>>xs[j]>>ys[j]; xss.emplace_back(xs); yss.emplace_back(ys); } const int T = 16; int dx[T][4]={{ 0,-1, 1, 0}, { 0, 1, 1, 2}, { 0, 0, 1,-1}, { 0,-1,-1,-2}, { 0, 1, 2, 3}, { 0,-2,-1, 1}, {-1, 0, 1, 2}, {-3,-2,-1, 0}, { 0, 0,-1,-1}, { 1, 1, 0, 0}, { 0, 0, 1, 1}, {-1,-1, 0, 0}, {-1, 0, 0, 1}, {-2,-1,-1, 0}, { 1, 0, 0,-1}, { 2, 1, 1, 0}, }; int dy[T][4]={{ 0, 0, 0,-1}, { 0, 1, 0, 0}, { 0,-1,-1,-1}, { 0, 0, 1, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0,-1,-1,-2}, { 1, 0, 0,-1}, { 0,-1,-1,-2}, { 1, 0, 0,-1}, { 0, 0,-1,-1}, { 1, 1, 0, 0}, { 0, 0,-1,-1}, { 1, 1, 0, 0}, }; using P = pair; int m=n; map mp; vector> G(n); for(int i=0;i > H(n); for(int i=0;i tmp; for(int j=0;j<3;j++) tmp.emplace(xs[j],ys[j]); int sy=((xs[0]+ys[0])%2==0?1:-1); for(int j=0;j res; for(int k=0;k<4;k++) res.emplace(xs[0]+dx[j][k],ys[0]+sy*dy[j][k]); int cnt=0; P uku; for(auto p:res){ if(tmp.count(p)){ cnt++; continue; } uku=p; } if(cnt!=3) continue; if(!mp.count(uku)) mp[uku]=m++; G[i].emplace(mp[uku]); } } Bipartite bm(m); for(int i=0;i ans; for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../convolution/convolution2D.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<>n; vector< vector > as(n,vector(n)); auto bs(as); int cnt=0; for(int i=0;i>as[i][j]; bs[n-(i+1)][n-(j+1)]=as[i][j]; cnt+=as[i][j]; } } NTT<1> ntt1; NTT<2> ntt2; using M1 = NTT<1>::M; using M2 = NTT<2>::M; auto tran1=[&](auto &as,bool f){ntt1.ntt(as,f);}; auto tran2=[&](auto &as,bool f){ntt2.ntt(as,f);}; Convolution2D conv1(tran1); Convolution2D conv2(tran2); vector< vector > as1(n,vector(n)); auto bs1(as1); vector< vector > as2(n,vector(n)); auto bs2(as2); for(int i=0;i num; const int S = 10000; auto calc= [&](ll a,ll b){ const ll r01 = M2(ntt1.md).inv().v; b = (b - a) * r01 % ntt2.md; if (b < 0) b += ntt2.md; a = (a + b * ntt1.md); return a; }; for(int i=0;i<(int)cs1.size();i++){ for(int j=0;j<(int)cs1[i].size();j++){ ll dd=(ll)(i-(n-1))*(i-(n-1))+(ll)(j-(n-1))*(j-(n-1)); ll cc=calc(cs1[i][j].v,cs2[i][j].v); if(dd==0) cc-=cnt; if(cc==0) continue; num[dd]+=cc; sum+=sqrt(dd)*cc; if((int)num.size()>S) num.erase(--num.end()); } } cout< using namespace std; #define call_from_test #include "../../vector/zip.cpp" #include "../../vector/fusion.cpp" #include "../../vector/compress.cpp" #include "../../algorithm/parallelbinarysearch.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,m,q; cin>>n>>m>>q; vector as(m),bs(m),vs(m); for(int i=0;i>as[i]>>bs[i]>>vs[i],as[i]--; { auto vt=zip(vs,as,bs); sort(vt.begin(),vt.end()); for(int i=0;i xs(q),ys(q); vector js(q); for(int i=0;i>xs[i]>>ys[i]>>js[i],xs[i]--; auto ps=compress(fusion(as,bs,xs,ys,vector({0,1000000007}))); auto dc=dict(ps); using P = pair; auto f=[&](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[&](P a,int b){return P(a.first+(ll)b*a.second,a.second);}; auto h=[&](int a,int b){return a+b;}; SegmentTree seg(f,g,h,P(0,0),0); vector

vp(ps.size()-1); for(int i=0;i+1<(int)ps.size();i++) vp[i]=P(0,ps[i+1]-ps[i]); for(int &a:as) a=dc[a]; for(int &b:bs) b=dc[b]; for(int &x:xs) x=dc[x]; for(int &y:ys) y=dc[y]; auto init=[&](){ seg.build(vp); }; auto apply=[&](int i){ seg.update(as[i],bs[i],1); }; auto check=[&](int i){ return seg.query(xs[i],ys[i]).first>=js[i]; }; auto ans=parallel_binary_search(q,m,init,apply,check); for(int i=0;i using namespace std; #define call_from_test #include "../../algorithm/monotoneminima.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int s,n,m; cin>>s>>n>>m; vector xs(s); for(int i=0;i>xs[i]; vector ts(n),ps(n); for(int i=0;i>ts[i]>>ps[i],ps[i]--; vector vs(n); for(int i=0;i sm(n+1,0); for(int i=0;i dp(n+1,INF); dp[0]=0; for(int k=0;k(n+1,n+1,dist); vector nx(n+1); for(int i=0;i<=n;i++) nx[i]=dist(i,res[i]); swap(dp,nx); } cout< using namespace std; #define call_from_test #include "../../linearalgebra/binarymatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; mat v(n,BS(0)); for(int i=0;i>k; v[i][j]=k; } } BS w; for(int i=0;i>k; w[i]=k; } int t; cin>>t; v=mat_pow(v,t); int a=mrank(v,n); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../mincostflow/primaldual.cpp" #include "../../mincostflow/negativeedge.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; const ll INF = 1e9; int n; cin>>n; NegativeEdge G(n+1); for(int i=0;i>k; map dst; for(int j=0;j>t>>c; t--; G.use_edge(i,t,1,c); if(!dst.count(t)) dst[t]=c; chmin(dst[t],c); } for(auto p:dst) G.add_edge(i,p.first,INF,p.second); G.add_edge(i,n,INF,0); } assert(G.build(0,n,INF)); cout< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #include "../../toptree/distancesum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n; cin>>n; using ll = long long; const size_t N = 2e5; using Cluster = DistanceSum; TopTree G; vector vs(n); for(int i=0;i>p>>d; p--; G.link(vs[p],d,vs[i]); } for(int i=0;i using namespace std; #define call_from_test #include "../../string/suffixarray.cpp" #include "../../segtree/basic/ushi.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; int m; cin>>s>>m; SuffixArray sa(s); using P = pair; auto f=[](P a,P b){ return P(max(a.first,b.first), min(a.second,b.second)); }; int n=s.size()+1; SegmentTree

seg(f,P(-1,n+1)); vector

vp; for(int i=0;i>x>>y; int lx=sa.lower_bound(x); int rx=sa.upper_bound(x); int ly=sa.lower_bound(y); int ry=sa.upper_bound(y); int ans; if(rx-lx<=0||ry-ly<=0) ans=0; else{ int a=seg.query(ly,ry).first; int b=seg.query(lx,rx).second; if(b+(int)x.size()>a+(int)y.size()) ans=0; else ans=a-b+y.size(); } cout< using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../tools/cc_hash.cpp" #include "../../datastructure/pb_ds_cc_hash_table.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,m; cin>>n>>m; m++; vector as(m),bs(m); for(int i=0;i>as[i]; for(int i=1;i>bs[i]; vector hs; MFP([&](auto dfs,int l,int r)->void{ int x=lower_bound(as.begin(),as.end(),r)-as.begin(); if(as[x-1]<=l&&r<=as[x]) return; hs.emplace_back(((ll)l<<31)|r); int m=(l+r)>>1; dfs(l,m); dfs(m,r); })(0,(1< > idx; for(int i=0;i<(int)hs.size();i++) idx[hs[i]]=i; vector< vector > dp(n+1,vector(hs.size(),-1)); int ans=(1<int{ int x=lower_bound(as.begin(),as.end(),r)-as.begin(); if(as[x-1]<=l&&r<=as[x]){ int v=bs[x],tmp=0; tmp+=(k==v); tmp+=(r-l)>>(n-v+1); return tmp; } if(~dp[k][idx[((ll)l<<31)|r]]) return dp[k][idx[((ll)l<<31)|r]]; int &res=(dp[k][idx[((ll)l<<31)|r]]=0); int m=(l+r)>>1; res=max(res,dfs(l,m,d+1,d)+dfs(m,r,d+1,k)); res=max(res,dfs(l,m,d+1,k)+dfs(m,r,d+1,d)); return res; })(0,1< using namespace std; #define call_from_test #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/arborescence_edmond.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; vector> G(n),R(n); for(int i=0;i>a>>b; G[a].emplace_back(b); R[b].emplace_back(a); } vector vs; for(int i=0;i rev; for(int i=0;i> H; for(int r:vs){ vector dp(n,INF); using P = pair; deque

deq; dp[r]=0; deq.emplace_back(r,0); while(!deq.empty()){ int v,d; tie(v,d)=deq.front();deq.pop_front(); if(dp[v] di(sz); for(int i=0;i ans; for(int i=0;i arb(sz); for(int j=0;j using namespace std; #define call_from_test #include "../../math/extgcd.cpp" #include "../../mod/inverse.cpp" #include "../../math/linearcongruence.cpp" #undef call_from_test int r[111][111]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,d; cin>>n>>m>>d; vector a(m); for(int i=0;i>a[i]; for(int i=0;i>r[i][j]; using ll = long long; ll ans=n; for(int i=0;i A,B,M; for(int j=0;j using namespace std; #define call_from_test #include "../../tree/heavylightdecomposition.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,q; cin>>n>>q; HLD hld(n); for(int i=1;i>a>>b; hld.add_edge(a,b); } hld.build(); using P = pair; auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[](P a,ll b){return P(a.first+b*a.second,a.second);}; auto h=[](ll a,ll b){return a+b;}; SegmentTree seg(f,g,h,P(0,0),0); seg.build(vector

(n,P(0,1))); for(int i=0;i>t; if(t==0){ int u,v; cin>>u>>v; ll ans=0; hld.for_each_edge(u,v,[&](int l,int r){ans+=seg.query(l,r).first;}); cout<>v>>x; seg.update(hld.vid[v]+1,hld.vid[v]+hld.sub[v],x); } } cout< using namespace std; #define call_from_test #include "../../segtree/count/static.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int d; cin>>d; vector xs(d); for(int i=0;i>xs[i]; using P = pair; vector

vp; for(int i=0;i seg(d,vp); int q; cin>>q; for(int i=0;i>l>>r>>e; l--; int a=min(xs[l],xs[r-1]); int b=max(xs[l],xs[r-1]); cout<<(r-l)-seg.query(l,r,a-e,b+e+1)<<"\n"; } cout< using namespace std; #define call_from_test #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int d; cin>>d; vector xs(d); for(int i=0;i>xs[i]; const int ofs = 2e8; for(int &x:xs) x+=ofs; WaveletMatrix wm(xs); int q; cin>>q; for(int i=0;i>l>>r>>e; l--; int a=min(xs[l],xs[r-1]); int b=max(xs[l],xs[r-1]); cout<<(r-l)-wm.rangefreq(l,r,a-e,b+e+1)<<"\n"; } cout< using namespace std; #define call_from_test #include "../../mincostflow/primaldual.cpp" #undef call_from_test const int MAX = 52; struct ARR{ array val; ARR(){fill(val.begin(),val.end(),0);} ARR(int x){fill(val.begin(),val.end(),x);} int& operator[](int k){return val[k];}; int operator[](int k)const{return val[k];}; ARR operator+(const ARR &oth) const{ ARR res; for(int i=0;i (const ARR &oth) const{ return val< oth.val; } bool operator==(const ARR &oth) const{ return val==oth.val; } }; namespace std { template<> class numeric_limits { public: static ARR max() {return ARR(numeric_limits::max());}; }; } int main(){ int n; cin>>n; vector vs(n); for(int i=0;i>vs[i]; auto enc=[&](char c){ if(isupper(c)) return c-'A'; return 26+c-'a'; }; auto dec=[&](int d){ if(d<26) return 'A'+d; return 'a'+d-26; }; int S=n*2,T=n*2+1; PrimalDual G(n*2+2); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../datastructure/rotcev.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; string s; cin>>s; vector< vector > G(n); for(int i=1;i>x>>y; x--;y--; G[x].emplace_back(y); G[y].emplace_back(x); } using ll = long long; ll ans=0; vector< Rotcev > dp1(n),dp2(n); MFP([&](auto dfs,int v,int p)->void{ int idx=v; for(int u:G[v]){ if(u==p) continue; dfs(u,v); if(dp1[idx].size()+dp2[idx].size()< dp1[u].size()+dp2[u].size()) idx=u; } auto &dx=dp1[v]; auto &dy=dp2[v]; if(idx!=v){ for(int u:G[v]){ if(u==p) continue; if(u==idx) continue; auto &py=dp2[u]; int sy=py.size(); if(s[v]=='('){ for(int i=0;i+1 tmp(dx); dx.assign(sx,0); for(int j=0;j<(int)tmp.size();j++) dx[j]+=tmp[j]; } for(int j=0;j tmp(dy); dy.assign(sy,0); for(int j=0;j<(int)tmp.size();j++) dy[j]+=tmp[j]; } for(int j=0;j using namespace std; #define call_from_test #include "../../string/suffixarray.cpp" #include "../../string/longestcommonprefix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; LongestCommonPrefix lcp(s); int q; cin>>q; for(int i=0;i>l>>r>>t; l--; int x=lcp.lcp(l,l+t); if(l+t+x+1>=r){ cout<<"Yes\n"; continue; } int y=lcp.lcp(l+x+1,l+t+x+1); if(l+t+x+1+y>=r){ cout<<"Yes\n"; continue; } if(l+x+1+y using namespace std; #define call_from_test #include "../../math/carmichael.cpp" #undef call_from_test // x^n mod m template T mpow(T x,T n,T m){ T r=1; x%=m; while(n){ if(n&1) r=r*x%m; x=x*x%m; n>>=1; } return r; } signed main(){ using ll = long long; ll n; cin>>n; if(n==2){ cout<<1< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../vector/zip.cpp" #include "../../convexhulltrick/linecontainer.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,x; cin>>n>>x; vector ts(n),ps(n),fs(n); for(int i=0;i>ts[i]>>ps[i]>>fs[i]; auto vt=zip(fs,ps,ts); sort(vt.begin(),vt.end()); for(int i=0;i> vh(x+1); ll ans=0; for(int i=0;its[i];j--){ if(vh[j-ts[i]].empty()) continue; ll val=vh[j-ts[i]].query(fs[i])+ps[i]-fs[i]*fs[i]; vh[j].add(2*fs[i],val-fs[i]*fs[i]); chmax(ans,val); } vh[ts[i]].add(2*fs[i],ps[i]-fs[i]*fs[i]); chmax(ans,ps[i]); } cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../vector/zip.cpp" #include "../../convexhulltrick/convexhulltrick.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,x; cin>>n>>x; vector ts(n),ps(n),fs(n); for(int i=0;i>ts[i]>>ps[i]>>fs[i]; auto vt=zip(fs,ps,ts); sort(vt.begin(),vt.end()); for(int i=0;i> vh(x+1); ll ans=0; for(int i=0;its[i];j--){ if(vh[j-ts[i]].empty()) continue; ll val=vh[j-ts[i]].queryMonotoneInc(fs[i])+ps[i]-fs[i]*fs[i]; vh[j].add(2*fs[i],val-fs[i]*fs[i]); chmax(ans,val); } vh[ts[i]].add(2*fs[i],ps[i]-fs[i]*fs[i]); chmax(ans,ps[i]); } cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../io/precision.cpp" #include "../../mincostflow/primaldual.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,p,s,t; cin>>n>>m>>p>>s>>t; s--;t--; PrimalDual G(n); for(int i=0;i>v>>u>>d>>c; v--;u--; G.add_edge(v,u,c,d); } using D = double; D ans=1e18; D sum=0,cnt=0; while(G.build(s,t,1)){ sum+=G.get_cost(); cnt+=1; chmin(ans,(sum+p)/cnt); } cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../tools/fixpoint.cpp" #include "../../tree/centroid.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector gs(n); for(int i=0;i>gs[i]; using P = pair; vector< vector

> G(n); Centroid C(n); for(int i=1;i>a>>b>>d; a--;b--; G[a].emplace_back(b,d); G[b].emplace_back(a,d); C.add_edge(a,b); } int ans=1; queue que; que.emplace(0); while(!que.empty()){ int rt=C.build(que.front())[0]; que.pop(); for(int uku=0;uku<2;uku++){ int len=0; MFP([&](auto dfs,int v,int p,int d)->void{ chmax(len,d); for(auto e:G[v]){ int u=e.first; if(u==p||!C.alive(u)) continue; dfs(u,v,d+1); } })(rt,-1,1); const int INF = 1e9; vector dat(len+1,INF); dat[0]=-INF; for(auto e:G[rt]){ int ch=e.first,cost=e.second; if(!C.alive(ch)) continue; // calc path MFP([&](auto dfs,int v,int p,int d,int sum,int val)->void{ if(val>=0) chmax(ans,d+1); int k=--upper_bound(dat.begin(),dat.end(),val)-dat.begin(); if(k) chmax(ans,k+1+d); for(auto e:G[v]){ int u=e.first,c=e.second; if(u==p||!C.alive(u)) continue; dfs(u,v,d+1,sum-c+gs[u],min(val,sum-c)); } })(ch,rt,1,gs[rt]-cost+gs[ch],gs[rt]-cost); // update dat MFP([&](auto dfs,int v,int p,int d,int sum,int val)->void{ if(val>=0){ chmin(dat[d],-sum); chmax(ans,d+1); } for(auto e:G[v]){ int u=e.first,c=e.second; if(u==p||!C.alive(u)) continue; dfs(u,v,d+1,sum+(gs[u]-c),(val>0?0:val)+(gs[u]-c)); } chmin(dat[d],dat[d+1]); })(ch,rt,1,gs[ch]-cost,gs[ch]-cost); } reverse(G[rt].begin(),G[rt].end()); } C.disable(rt); for(int u:C.G[rt]) if(C.alive(u)) que.emplace(u); } cout< using namespace std; #define call_from_test #include "../../datastructure/BIT2D.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w,t,q; cin>>h>>w>>t>>q; BIT2D beet(h+100,w+100); BIT2D ushi(h+100,w+100); using P = pair; using PP = pair; queue qq; for(int i=0;i>a>>c>>x1>>y1; while(!qq.empty()&&qq.front().first<=a){ P p=qq.front().second;qq.pop(); int x=p.first,y=p.second; assert(beet.sum(x-1,y-1,x,y)==1); beet.add(x,y,-1); assert(ushi.sum(x-1,y-1,x,y)==0); ushi.add(x,y,1); } if(c==0){ assert(beet.sum(x1-1,y1-1,x1,y1)==0); beet.add(x1,y1,1); qq.push(PP(a+t,P(x1,y1))); } if(c==1){ if(ushi.sum(x1-1,y1-1,x1,y1)==0) continue; ushi.add(x1,y1,-1); } if(c==2){ int x2,y2; cin>>x2>>y2; x1--;y1--; cout< using namespace std; #define call_from_test #include "../../segtree/count/dynamic_offline.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w,t,q; cin>>h>>w>>t>>q; RangeCount beet(h),ushi(h); vector ts(q),cs(q); vector y1(q),x1(q),y2(q),x2(q); for(int i=0;i>ts[i]>>cs[i]>>y1[i]>>x1[i]; y1[i]--;x1[i]--; if(cs[i]==0||cs[i]==1){ beet.preupdate(y1[i],x1[i]); ushi.preupdate(y1[i],x1[i]); } if(cs[i]==2) cin>>y2[i]>>x2[i]; } beet.build(); ushi.build(); using P = pair; queue

que; for(int i=0;i using namespace std; #define call_from_test #include "../../tree/eulertourforvertex.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; EulerTourForVertex et(n); for(int i=1;i>p; p--; et.add_edge(p,i); } et.build(); vector cs(n); for(int i=0;i>cs[i]; struct T{ int sum,one; T(int sum,int one):sum(sum),one(one){} }; using E = int; auto f=[](T a,T b){return T(a.sum+b.sum,a.one+b.one);}; auto g=[](T a,E b){return T(a.sum,b?a.sum-a.one:a.one);}; auto h=[](E a,E b){return a^b;}; T ti(0,0); E ei(0); SegmentTree seg(f,g,h,ti,ei); vector vs(n,ti); for(int i=0;i>v; v--; et.exec(v,[&](int l,int r){seg.update(l,r,1);}); auto res=seg.query(0,n); cout<<(res.sum-res.one using namespace std; #define call_from_test #include "../../bflow/capacityscaling.cpp" #include "../../graph/bellmanford.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; const ll INF = 1<<30; int n,m,s,t; cin>>n>>m>>s>>t; s--;t--; MaxGainFlow G(n); BellmanFord H(n); for(int i=0;i>u>>v>>d>>c; u--;v--; G.add_edge(u,v,0,c,-d); H.add_edge(u,v,d); } int neg_loop; int len=H.shortest_path(s,t,neg_loop); assert(!neg_loop); G.add_edge(t,s,0,INF,len+1); assert(G.build()); cout< using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/array.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; using Data = Array; using Node = Data::Node; const int LIM = 1e6; Basic as; Node* rt=nullptr; vector vs(n+1); for(int i=0;i>a; a--; vs[a]=as.create(a+1); rt=as.merge(rt,vs[a]); } for(int i=0;i>p; p--; int k=as.order_of_key(vs[p]); auto s=as.split(rt,k); auto t=as.split(s.second,1); rt=as.merge(as.merge(t.second,t.first),s.first); } for(int i=0;i using namespace std; #define call_from_test #include "../../graph/cycle.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; UndirectedCycle G(n); for(int i=0;i>u>>v; u--;v--; G.add_edge(u,v); } auto vs=G.build(); unordered_set namori(vs.begin(),vs.end()); int q; cin>>q; for(int i=0;i>a>>b; a--;b--; cout<<1+(namori.count(a) and namori.count(b))<<'\n'; } return 0; } ================================================ FILE: test/aoj/2934.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2934 #include using namespace std; #define call_from_test #include "../../string/manacher.cpp" #include "../../tools/drop.cpp" #undef call_from_test signed main(){ int n; cin>>n; string t; cin>>t; auto ms=manacher(t); for(int l=2;l<=n;l++){ int flg=1; for(int i=l-1;i using namespace std; #define call_from_test #include "../../graph/independentset.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; while(cin>>n>>m,n){ vector< vector > as(n,vector(m)); for(int i=0;i>as[i][j]; IndependentSet G(m); for(int a=0;aas[j][a])^(as[i][b]>as[j][b])) ng=1; if(ng) break; } if(ng) break; } if(ng) G.add_edge(a,b); } } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../polynomial/lagrangeinterpolation.cpp" #undef call_from_test using M = Mint; const int MAX = 6060; M dp[2020][MAX]={}; M ad[2020][MAX]={}; signed main(){ int n,m; while(cin>>n>>m,n||m){ vector as(m),bs(m),cs(m); vector< vector > G(n+1); for(int i=0;i>as[i]>>bs[i]>>cs[i]; G[as[i]].emplace_back(i); } as.emplace_back(0); bs.emplace_back(1); cs.emplace_back(0); G[0].emplace_back(m); dp[0][0]=M(1); for(int v=0;v<=n;v++){ for(int j=0;j>q; for(int i=0;i>d>>e; vector ys(dp[d]+n+n,dp[d]+n+n+n+1); if(e using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #undef call_from_test NTT<2> ntt; using M = Mint; vector res; void dfs(vector &as,vector &bs,int l,int r){ if(r-l==1) return; int m=(l+r)>>1; vector cs(m-l); vector ds(r-m); for(int i=l;i>s; int n=s.size(); vector us(n),gs(n),qs(n); int num=0; for(int i=0;i=1) ans+=res[i*2]*M(3).pow(num-1); } if(s[i]=='?'){ if(num>=2) ans+=res[i*2]*M(3).pow(num-2); } } } // U (M / ?) ? { res.assign(2*n,0); dfs(us,qs,0,n); for(int i=0;i=1) ans+=res[i*2]*M(3).pow(num-1); } if(s[i]=='?'){ if(num>=2) ans+=res[i*2]*M(3).pow(num-2); } } } // ? (M / ?) ? { res.assign(2*n,0); dfs(qs,qs,0,n); for(int i=0;i=2) ans+=res[i*2]*M(3).pow(num-2); } if(s[i]=='?'){ if(num>=3) ans+=res[i*2]*M(3).pow(num-3); } } } cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../tools/chminmax.cpp" #include "../../math/factorize.cpp" #include "../../vector/compress.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; auto as=read(n); vector ps; for(auto a:as) for(auto[p,_]:factorize(a)) ps.emplace_back(p); long long ans=0; for(int p:compress(ps)){ long long res=0; for(int a:as) if(a%p==0) res+=a; chmax(ans,res); } cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../segtree/basic/ushi.cpp" #include "../../vector/compress.cpp" #include "../../vector/fusion.cpp" #include "../../vector/near.cpp" #include "../../vector/sorted.cpp" #include "../../vector/zip.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; ll lim; cin>>n>>lim; vector ls(n),rs(n); for(int i=0;i>ls[i]>>rs[i]; auto dc=dict(compress(fusion(near(ls,0,1),near(rs,-1,0)))); int m=dc.size(); auto f=[&](int a,int b){return min(a,b);}; SegmentTree seg(f,n+3); seg.build(vector(m,n+2)); seg.set_val(dc[0],0); int res=n; for(auto[r,l]:sorted(zip(rs,ls))){ int val=seg.query(dc[l],dc[r])+1; chmin(val,seg.query(dc[r],dc[r]+1)); seg.set_val(dc[r],val); if(r==lim) chmin(res,val); } cout< sm(m,0); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../math/extgcd.cpp" #include "../../mod/inverse.cpp" #include "../../math/linearcongruence.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector ps(n),qs(n); for(int i=0;i>ps[i],ps[i]--; for(int i=0;i>qs[i],qs[i]--; using ll = long long; vector A,B,M; vector used(n,0); for(int i=0;i vs,ws; while(!used[pos]){ vs.emplace_back(pos); ws.emplace_back(ps[pos]); used[pos]=1; pos=qs[pos]; } { auto as=vs,bs=ws; sort(as.begin(),as.end()); sort(bs.begin(),bs.end()); if(as!=bs) drop(-1); } int m=vs.size(); for(int j=0;j using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../mod/mint.cpp" #include "../../polynomial/hash.cpp" #undef call_from_test const int MOD1 = 1e9+7; const int MOD2 = 1e9+9; const int MOD3 = 1e9+21; using M1 = Mint; using M2 = Mint; using M3 = Mint; using PH = PolynomialHash; PH ph(1); const int MAX = 1e5+100; int used[MAX]={}; vector vs(MAX,0); using P = pair; vector

G[MAX],R[MAX]; template void check(T x,T y){if(x!=y) drop("No");}; void dfs(int v){ for(auto e:G[v]){ int u=e.first,x=e.second; if(used[u]) continue; used[u]=1; vs[u]=vs[v]*PH::V(x); dfs(u); } for(auto e:R[v]){ int u=e.first,x=e.second; if(used[u]) continue; used[u]=1; vs[u]=vs[v]/PH::V(x); dfs(u); } for(auto e:G[v]){ int u=e.first,x=e.second; check(vs[u],vs[v]*PH::V(x)); } for(auto e:R[v]){ int u=e.first,x=e.second; check(vs[u],vs[v]/PH::V(x)); } } signed main(){ int n,m; cin>>n>>m; for(int i=0;i>a>>b>>x; a--;b--; G[a].emplace_back(b,x); R[b].emplace_back(a,x); } for(int i=0;i using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../tools/chminmax.cpp" #include "../../convexhulltrick/convexhulltrick.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; int zx,zv; cin>>zx>>zv; vector xs(n),vs(n); for(int i=0;i>xs[i]>>vs[i]; for(int i=0;i ans(n,INF); for(int i=0;i; vector

vp; int sp=0; for(int i=0;i=0) continue; if(vs[i]<=0) continue; vp.emplace_back(vs[i],xs[i]); chmax(sp,vs[i]); } if(vp.empty()) continue; sort(vp.begin(),vp.end()); MaxConvexHullTrick cht; for(auto p:vp) cht.add(p.first,p.second); for(int i=0;i=(D)vs[i]*M+(D)xs[i]) R=M; else L=M; } chmin(ans[i],R); } } for(int i=0;i=INF) cout<<-1<<"\n"; else cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../convolution/convolution2D.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,k,l; cin>>n>>m>>k>>l; vector bs(n); for(int i=0;i>bs[i]; string s; cin>>s; NTT<0> ntt; using M = NTT<0>::M; auto tran=[&](auto &as,bool f){ntt.ntt(as,f);}; Convolution2D conv(tran); using Matrix=Convolution2D::Matrix; Matrix A(n,vector(n,0)); for(int i=0;i(m-n+1,0)); int cy=0,cx=0; for(int i=0;i=k) ans++; cout< using namespace std; #define call_from_test #include "../../maxflow/dinic.cpp" #include "../../maxflow/twocommodity.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,s,t,u,v; cin>>n>>m>>s>>t>>u>>v; s--;t--;u--;v--; TwoCommodity G(n); for(int i=0;i>x>>y; x--;y--; G.add_edge(x,y,1); } cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../tools/drop.cpp" #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/and.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; int sz=1< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../matching/tutte.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; vector< vector > L(m); for(int i=0;i>k; L[i].resize(k); for(int j=0;j>L[i][j],L[i][j]--; } vector< vector > G(n); for(int i=0;i dead(m,0); for(int i=0;i > H(m); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../convolution/garner.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; Garner arb; auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector line(n+1,0),quad(n+1,0); for(int i=1;i<=n;i++){ line[i]=M(i).pow(0); quad[i]=M(i).pow(1); } M v1=FPS.exp(line,n+1)[n]; M v2=FPS.exp(quad,n+1)[n]; M ans=v2-v1*v1; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/fastfouriertransform.cpp" #include "../../convolution/arbitrarymod.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; ArbitraryMod arb; auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector line(n+1,0),quad(n+1,0); for(int i=1;i<=n;i++){ line[i]=M(i).pow(0); quad[i]=M(i).pow(1); } M v1=FPS.exp(line,n+1)[n]; M v2=FPS.exp(quad,n+1)[n]; M ans=v2-v1*v1; cout< using namespace std; #define call_from_test #include "../../datastructure/unionfind.cpp" #include "../../tree/sack.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,k; cin>>n>>k; vector us(n),vs(n),cs(n),ds(n); for(int i=1;i>us[i]>>vs[i]; for(int i=0;i>cs[i]>>ds[i]; int num=0; vector cnt(k,0); UnionFind uf(k); auto calc=[&](int c){return min(cnt[c],uf.size(c));}; auto expand=[&](int v){ int c=uf.find(cs[v]); int d=uf.find(ds[v]); int flg=uf.same(c,d); if(flg){ num-=calc(c); uf.unite(c,d); cnt[c]++; num+=calc(c); }else{ num-=calc(c)+calc(d); uf.unite(c,d); if(uf.find(c)!=c) swap(c,d); cnt[c]+=cnt[d]+1; num+=calc(c); } }; auto shrink=[&](int v){ num=0; cnt[cs[v]]=cnt[ds[v]]=0; uf.ps[cs[v]]=cs[v]; uf.ps[ds[v]]=ds[v]; uf.rs[cs[v]]=uf.rs[ds[v]]=1; }; vector ans(n); auto query=[&](int v){ans[v]=num;}; Sack S(n,expand,shrink,query); for(int i=1;i using namespace std; #define call_from_test #include "../../segtree/persistent/ushi.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector as(n),bs(n); for(int i=0;i>as[i]; for(int i=0;i>bs[i]; auto f=[](int a,int b){return min(a,b);}; int ti=INT_MAX; SegmentTree seg(f,ti); auto ra=seg.build(as); auto rb=seg.build(bs); int q; cin>>q; for(int i=0;i>x>>y>>z; y--; if(x==1) ra=seg.set_val(ra,y,z); if(x==2) rb=seg.set_val(rb,y,z); if(x==3) cout< using namespace std; #define call_from_test #include "../../string/suffixarray.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; ll k; string s; cin>>n>>k>>s; auto calc=[](ll x){return x*(x+1)/2;}; ll zs=0; vector cnt(n+1,1); for(int i=0;i=n||s[i+1]!='0') zs+=calc(cnt[i]); if(i+1 sum(n+1,0); for(int i=0;i=sum[n+1-len]&&lenn) continue; if(k>=0) pos=sa.sa[i]; k-=cnt[sa.sa[i]]; } cout< using namespace std; #define call_from_test #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; struct T{ ll w,x,y,z; T(ll w,ll x,ll y,ll z):w(w),x(x),y(y),z(z){} }; auto f= [](T a,T b){ ll cw=min(a.w,b.w); ll cx=(a.w==b.w?a.x+b.x:(a.wb.y?a.z:b.z)); return T(cw,cx,cy,cz); }; auto g= [](T a,ll b){ return T(a.w+b,a.x,a.y+b,a.z); }; auto h=[](ll a,ll b){return a+b;}; int H,W,Q; cin>>H>>W>>Q; vector A,B; for(int i=0;i>v; A.emplace_back(v,1,v,1); } for(int i=0;i>v; B.emplace_back(v,1,v,1); } const ll INF = 1e17; T ti(INF,0,-INF,0); SegmentTree segY(f,g,h,ti,0); SegmentTree segX(f,g,h,ti,0); segY.build(A); segX.build(B); auto calc= [](int t,T a,T b,ll p,ll q){ ll res=t==3? min({a.w*b.w,a.w*b.y,a.y*b.w,a.y*b.y}): max({a.w*b.w,a.w*b.y,a.y*b.w,a.y*b.y}); ll cnt=0; ll n=p-(!a.w?a.x:!a.y?a.z:0ll); ll m=q-(!b.w?b.x:!b.y?b.z:0ll); if(res==0) cnt=p*q-n*m; else{ if(a.w==a.y) a.z=0; if(b.w==b.y) b.z=0; if(res==a.w*b.w) cnt+=a.x*b.x; if(res==a.w*b.y) cnt+=a.x*b.z; if(res==a.y*b.w) cnt+=a.z*b.x; if(res==a.y*b.y) cnt+=a.z*b.z; } cout<>t; if(t==1){ int a,b,v; cin>>a>>b>>v; segY.update(--a,b,v); } if(t==2){ int c,d,v; cin>>c>>d>>v; segX.update(--c,d,v); } if(t==3||t==4){ int a,b,c,d; cin>>a>>b>>c>>d; T y=segY.query(--a,b); T x=segX.query(--c,d); calc(t,y,x,b-a,d-c); } } cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../toptree/toptree.cpp" #undef call_from_test using ll = long long; struct Vertex{ void* handle; ll val; Vertex(ll val=0):handle(nullptr),val(val){} }; struct Cluster{ ll sm,md,chd,ma; Cluster():sm(0),md(0),chd(0),ma(0){} void toggle(){} static Cluster compress(Cluster x,Vertex *v,Cluster y){ Cluster z; z.sm=x.sm+(v->val)+y.sm; z.md=max({x.md,x.chd,y.md}); z.ma=x.sm+(v->val)+y.sm; return z; } static Cluster rake(Cluster x,Cluster y){ x.sm+=y.sm; x.chd=max({x.chd,y.chd,y.ma}); return x; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n; cin>>n; vector ws(n); for(int i=0;i>ws[i]; const size_t N = 1e5 + 10; TopTree G; vector vs(n); for(int i=0;i>u>>v; u--;v--; G.link(vs[u],Cluster(),vs[v]); } Vertex* da=G.create(0); Vertex* db=G.create(0); int q; cin>>q; for(int i=0;i>a>>b; a--;b--; G.link(da,Cluster(),vs[a]); G.link(db,Cluster(),vs[b]); cout< using namespace std; #define call_from_test #include "../../maxflow/dinic.cpp" #undef call_from_test const int K = 28; int cap[K][K]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector s(n); for(int i=0;i>s[i]; for(int i=0;i<26;i++){ memset(cap,0,sizeof(cap)); int x=26,y=27,z=0,e=0; Dinic G(K); for(int j=0;j using namespace std; #define call_from_test #include "../../tools/all_permutations.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; string s; cin>>n>>s; int c[10][10]={}; for(int i=0;i+1 us; auto f= [&](auto vs){ int x[10],y[10]; for(int i=0;i<9;i++){ x[vs[i]+1]=i%3; y[vs[i]+1]=i/3; } int res=0; for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) res+=c[i][j]*(abs(x[i]-x[j])+abs(y[i]-y[j])); if(res using namespace std; #define call_from_test #include "../../maxflow/dinic.cpp" #undef call_from_test signed main(){ int n,m; cin>>n>>m; string s; cin>>s; vector as(n); for(int i=0;i>as[i]; int S=n,T=n+1; Dinic G(n+2); for(int i=0;i>x>>y>>z; x--;y--; if(x>y) swap(x,y); G.add_edge(x,y,z); } for(int i=0;i using namespace std; #define call_from_test #include "../../mod/pow.cpp" #include "../../mod/order.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int MOD; cin>>MOD; int T; cin>>T; while(T--){ int n; cin>>n; vector gs(n); for(int i=0;i>gs[i]; int a; cin>>a; if(a==1){ cout<<1<(n,1)){ cout<<0<(gs[0],MOD); for(int x:gs) res=lcm(res,order(x,MOD)); cout<<(res%order(a,MOD)==0?1:0)< using namespace std; #define call_from_test #include "../../string/suffixarray.cpp" #include "../../string/longestcommonprefix.cpp" #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; string s; cin>>s; LongestCommonPrefix lcp(s); auto vs=lcp.sa.sa; auto rev=lcp.sa.rev; using WM = WaveletMatrix; WM wm(vs); auto calc= [&](int a,int b)->int{ auto check= [&](int x)->int{ int p=b-x; int pos=rev[p]; int ll=-1,rr=-1; { int l=-1,r=pos; while(l+1>1; if(vs[m]+x<=n&&lcp.lcp(vs[m],p)>=x) r=m; else l=m; } ll=r; } { int l=pos,r=n+1; while(l+1>1; if(vs[m]+x<=n&&lcp.lcp(vs[m],p)>=x) l=m; else r=m; } rr=r; } // [ll, rr) int q=wm.pred(ll,rr,p-x); if(q==WM::npos||q-x<0) return 0; int k=wm.pred(ll,rr,q-x); if(k==WM::npos) return 0; return a>1; if(check(m)) l=m; else r=m; } return l; }; for(int i=0;i>a>>b; a--; cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../convexhulltrick/linecontainer.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,m,q; cin>>n>>m>>q; vector ds(n); for(int i=0;i>ds[i]; for(int i=0;i sm(n*3+1,0); for(int i=0;i cs(m); vector bs(m),ts(m); for(int i=0;i>cs[i]>>bs[i]>>ts[i],bs[i]--; vector< vector > G(n*3); vector xs(q),ys(q); for(int i=0;i>xs[i]>>ys[i]; xs[i]--,ys[i]--; xs[i]+=n,ys[i]+=n; G[xs[i]].emplace_back(i); } const ll INF = 1e18; vector R(n*3,INF),L(n*3,INF); int exR=0,exL=0; for(int i=0;i ans(q,INF); // use R if(exR){ MinLineContainer cht; for(int x=0;xy) y+=n; chmin(ans[i],cht.query(sm[y])); } } } // use L if(exL){ MinLineContainer cht; for(int x=n*3-1;x>=n;x--){ if(L[x]!=INF) cht.add(-L[x],L[x]*sm[x]); for(int i:G[x]){ int y=ys[i]; if(x using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); int n,k,p100; cin>>n>>k>>p100; M p=M(p100)/M(100); vector as({M(n)/p}); vector bs(n+1,-p); bs[0]=n; auto cs=FPS.mul(as,FPS.inv(bs,k)); M ans{1}; for(int i=1;i using namespace std; #define call_from_test #include "../../string/trie.cpp" #include "../../string/ahocorasick.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; string s; cin>>s; int n,q; cin>>n>>q; AhoCorasick<26, false> aho('a'); aho.add(s,0); aho.build(); using A = array; A ti,ei; fill(ti.begin(),ti.end(),0); iota(ei.begin(),ei.end(),0); auto f=[&](A a,A b){ A c; for(int i=0;i<(int)a.size();i++) c[i]=a[i]+b[i]; return c; }; auto g=[&](A a,A b){ A c(ti); for(int i=0;i<(int)a.size();i++) c[b[i]]+=a[i]; return c; }; auto h=[&](A a,A b){ A c; for(int i=0;i<(int)a.size();i++) c[i]=b[a[i]]; return c; }; SegmentTree seg(f,g,h,ti,ei); vector va(n,ti); for(int i=0;i mv(26); for(int x=0;x<26;x++) for(int i=0;i<(int)mv[x].size();i++) mv[x][i]=(i<(int)aho.size()?aho.move(i,char('a'+x)):i); for(int i=0;i>t; if(t==1){ int l,r; string c; cin>>l>>r>>c; l--; A a=ei; for(char x:c) a=h(a,mv[x-'a']); seg.update(l,r,a); } if(t==2){ int l,r; cin>>l>>r; l--; A res=seg.query(l,r); int ans=0; for(int j=0;j<(int)res.size();j++) if(j<(int)aho.size()&&aho.count(j)) ans+=res[j]; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../convolution/convolution2D.cpp" #include "../../linearalgebra/squarematrix.cpp" #undef call_from_test NTT<2> ntt; using M = NTT<2>::M; auto tran=[](auto &as,bool f){ntt.ntt(as,f);}; Convolution2D conv(tran); struct Ring{ vector dat; Ring(){}; Ring(vector dat):dat(dat){}; static Ring add_identity(); static Ring mul_identity(); Ring operator*(const Ring &a)const{ auto res=Ring(dat); for(int i=0;i<(int)dat.size();i++) res.dat[i]*=a.dat[i]; return res; } Ring operator+(const Ring &a)const{ auto res=Ring(dat); for(int i=0;i<(int)dat.size();i++) res.dat[i]+=a.dat[i]; return res; } }; Ring add_id, mul_id; Ring Ring::add_identity(){return add_id;}; Ring Ring::mul_identity(){return mul_id;}; signed main(){ int h,w,k; cin>>h>>w>>k; h=1< > tt(h,vector(w)); vector< vector > gg(h,vector(w)); for(int i=0;i>tt[i][j]; for(int i=0;i>gg[i][j]; using Matrix = vector< vector >; Matrix T(h,vector(w)); Matrix G(h,vector(w)); Matrix W(h,vector(w)); Matrix H(h,vector(w)); for(int i=0;i=0?tt[i][j]:0; G[i][j]=gg[i][j]>=0?gg[i][j]:0; W[i][j]=tt[i][j]>=0?1:0; H[i][j]=T[i][j]*G[i][j]; } } auto flatten= [&](Matrix A){ conv.transform(A,false); vector dat(h*w); for(int i=0;i(w,M(0))); add_id=flatten(id); id[0][0]=1; mul_id=flatten(id); } using SM = SquareMatrix; SM P; P[0][0]=flatten(W); P[1][0]=flatten(T);P[1][1]=flatten(W); P[2][0]=flatten(H);P[2][1]=flatten(G);P[2][2]=flatten(W); P[3][0]=flatten(H);P[3][1]=flatten(G);P[3][2]=flatten(W); P[3][3]=Ring::mul_identity(); auto val=P.pow(k)[3][0]; Matrix res(h,vector(w)); for(int i=0;i using namespace std; #define call_from_test #include "../../string/zalgorithm.cpp" #include "../../string/run.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector as(n); for(int i=0;i>as[i]; auto run=Run::enumerate(as); using ll = long long; vector dp(n+1,0),sm(n+1,0); for(ll i=1;i<=n;i++){ dp[i]=dp[i-1]+(i-1)*1; sm[i]=sm[i-1]+(i-1)*i; } auto calc=[&](ll t,ll len)->ll{ return (len+1)*dp[len/t]-t*sm[len/t]; }; ll ans=(ll)n*(n+1)/2; set used; for(int t=1;t<=n;t++){ for(auto p:run[t]){ if(used.count(p)) continue; used.emplace(p); ans+=calc(t,p.second-p.first); } } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #include "../../formalpowerseries/pow.cpp" #include "../../tree/centroid.cpp" #include "../../tools/fixpoint.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); NTT<2> ntt; using M = decltype(ntt)::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); using Poly = decltype(FPS)::Poly; int n,m; cin>>n>>m; Poly as(n); for(int i=0;i>as[i].v; Centroid G(n+1); G.add_edge(n,0); for(int i=1;i>u>>v; G.add_edge(u,v); } vector par(n+1,-1); { queue que; que.emplace(n); while(!que.empty()){ int v=que.front();que.pop(); for(int u:G.G[v]){ if(u==par[v]) continue; par[u]=v; que.emplace(u); } } } vector dead(n+1,0); auto disable=[&](int k){ dead[k]=1; G.disable(k); }; disable(n); const int deg = 1<<18; Poly ps(n,M(1)); ps=FPS.pow(ps,m,deg); queue que; que.emplace(G.build(0)[0]); Poly ans(n); while(!que.empty()){ int r=que.front();que.pop(); Poly qs; MFP([&](auto dfs,int v,int p,int h)->void{ while(!(h<(int)qs.size())) qs.emplace_back(0); qs[h]+=as[v]; for(int u:G.G[v]){ if(u==p) continue; if(dead[u]) continue; dfs(u,v,h+1); } })(r,par[r],0); reverse(qs.begin(),qs.end()); vector bs; int p=r; while(~p&&!dead[p]){ bs.emplace_back(p); p=par[p]; } int len=qs.size()-1; qs.resize(len+bs.size(),M(0)); auto rs=FPS.mul(FPS.pre(ps,qs.size()),qs); for(int i=0;i<(int)bs.size();i++) ans[bs[i]]+=rs[len+i]; disable(r); for(int u:G.G[r]) if(!dead[u]) que.emplace(G.build(u)[0]); } for(int i=0;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../algorithm/offlineonline.cpp" #include "../../datastructure/sparsetable.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,l; cin>>n>>l; auto as=read(n); auto f=[](int a,int b){return max(a,b);}; SparseTable st(f); st.build(as); using ll = long long; const ll INF = 1e18; auto dist=[&](int i,int j)->ll{ return j-i(n,dist)< using namespace std; #define call_from_test #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/twosatisfiability.cpp" #undef call_from_test signed main(){ int n,m; cin>>n>>m; TwoSat G(n); for(int i=0;i>a>>b; a--;b--; G.add_if(a,b); } G.build(); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../string/suffixarray.cpp" #include "../../string/longestcommonprefix.cpp" #include "../../segtree/basic/dual.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s,t; cin>>s>>t; string b=s+'%'+t; LongestCommonPrefix lcp(b); int n=s.size(),m=t.size(); set ss; for(int i=0;i<=n+1+m;i++){ if(!isalpha(b[lcp.sa[i]])) continue; if(n nx(n+1,-1); for(int i=0;i<=n+1+m;i++){ if(!isalpha(b[lcp.sa[i]])) continue; int k=lcp.sa[i]; if(k>=n) continue; auto it=ss.upper_bound(i); if(it!=ss.end()) chmax(nx[k],lcp.query(i,*it)); if(it!=ss.begin()) it--; if(it!=ss.end()) chmax(nx[k],lcp.query(i,*it)); } int len; cin>>len; auto h=[&](int a,int b){return a||b;}; int ei=0; SegmentTree seg(h,ei); seg.init(n+m+1000); seg.set_val(0,1); for(int i=0;i using namespace std; #define call_from_test #include "../../bbst/pb_ds_tree.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,k; cin>>n>>k; vector as(n); for(int i=0;i>as[i],as[i]-=k; using ll = long long; using P = pair; gtree

G; ll sum=0,ans=0; G.insert(P(sum,-1)); for(int i=0;i using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/subtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using Node = NodeBase; constexpr size_t LIM = 1e5+100; using LCT = Subtree; LCT lct; int n,q; cin>>n>>q; for(int i=0;i<=n;i++) lct.create(1); for(int i=1;i>a>>b; lct.evert(lct[b]); lct.link(lct[a],lct[b]); } lct.evert(lct[1]); lct.link(lct[0],lct[1]); vector par(n+1); for(int i=1;i<=n;i++) par[i]=lct.idx(lct.parent(lct[i])); for(int i=0;i>t>>v; if(t==1){ if(lct.root(lct[v])==lct[v]){ lct.link(lct[par[v]],lct[v]); }else{ lct.cut(lct[v]); } } if(t==2){ auto r=lct.root(lct[v]); lct.evert(lct[v]); auto u=lct.parent(r); lct.evert(r); lct.cut(u); cout< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #include "../../tools/drop.cpp" #undef call_from_test int dp[100][200][200]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w; cin>>h>>w; vector ss(h); for(int i=0;i>ss[i]; Die d; d.top()='1'; d.bottom()='6'; d.north()='5'; d.south()='2'; d.east()='3'; d.west()='4'; auto ds=makeDice(d); map, int> idx; for(int i=0;i<(int)ds.size();i++) idx[ds[i].fs]=i; memset(dp,0,sizeof(dp)); using T = tuple; queue que; dp[idx[d.fs]][0][0]=1; que.emplace(idx[d.fs],0,0); while(!que.empty()){ int k,i,j; tie(k,i,j)=que.front();que.pop(); if(i==h-1 and j==w-1) drop("YES"); d=ds[k]; if(i+1=0){ int ni=i-1,nj=j; Die nd(d); nd.roll('N'); if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.fs]][ni][nj]){ dp[idx[nd.fs]][ni][nj]=1; que.emplace(idx[nd.fs],ni,nj); } } if(j+1=0){ int ni=i,nj=j-1; Die nd(d); nd.roll('W'); if(nd.bottom()==ss[ni][nj] and !dp[idx[nd.fs]][ni][nj]){ dp[idx[nd.fs]][ni][nj]=1; que.emplace(idx[nd.fs],ni,nj); } } } drop("NO"); return 0; } ================================================ FILE: test/aoj/3142.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3142 #include using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../tools/fixpoint.cpp" #include "../../tree/centroid.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; Centroid G(n); for(int i=1;i>u>>v; u--;v--; G.add_edge(u,v); } vector as(n),bs(n); for(int i=0;i>as[i]; for(int i=0;i>bs[i]; using P = pair; vector> H(n); MFP([&](auto dfs,int v,int p)->ll{ ll res=as[v]-bs[v]; for(int u:G[v]){ if(u==p) continue; ll tmp=dfs(u,v); H[u].emplace_back(v,-tmp); H[v].emplace_back(u,+tmp); res+=tmp; } return res; })(0,-1); vector dp(n,0); queue que; que.emplace(G.build(0)[0]); vector tmp(n); while(!que.empty()){ int r=que.front();que.pop(); for(int t=0;t<2;t++){ ll res=0; for(auto ch:H[r]){ int c=ch.first; if(!G.alive(c)) continue; // calc cost MFP([&](auto dfs,int v,int p,ll d)->void{ chmin(dp[v],-d+res); for(auto[u,w]:H[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v,d+w); } })(c,r,ch.second); // update cost MFP([&](auto dfs,int v,int p,ll d)->void{ chmin(res,d); for(auto[u,w]:H[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v,d+w); } })(c,r,ch.second); } chmin(dp[r],res); reverse(H[r].begin(),H[r].end()); } G.disable(r); for(int c:G.G[r]) if(G.alive(c)) que.emplace(G.build(c)[0]); } ll ans=0; for(ll x:dp) ans+=x; cout<<-ans< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #include "../../toptree/farthest.cpp" #undef call_from_test const int MAX = 2e5+100; Vertex* vs[MAX]; int as[MAX],bs[MAX],ds[MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; const size_t N = MAX; using Cluster = Farthest; TopTree G; int n; cin>>n; for(int i=0;i>as[i]>>bs[i]>>ds[i]; as[i]--;bs[i]--; G.link(vs[as[i]],Cluster(ds[i],as[i],bs[i]),vs[bs[i]]); } auto cut=[&](int k)->void{ G.cut(vs[as[k]],vs[bs[k]]); }; auto link=[&](int k)->void{ G.link(vs[as[k]],Cluster(ds[k],as[k],bs[k]),vs[bs[k]]); }; int q; cin>>q; int cur=0; for(int i=0;i>t; if(t==1){ int x; cin>>x; x--; cur=x; } if(t==2){ int y; cin>>y; cut(y); } if(t==3){ int z; cin>>z; link(z); } auto fs=get_all_farthests(G,vs[cur]); if(fs.empty()){ cout<<1<<" "< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../tools/drop.cpp" #include "../../tree/rerooting.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; struct T{ ll a,b,c; T(ll a,ll b,ll c):a(a),b(b),c(c){} }; const ll INF = 1e9; auto fold=[&](T x,T y){ vector vs({x.a,x.b,x.c,y.a,y.b,y.c}); sort(vs.rbegin(),vs.rend()); return T(vs[0],vs[1],vs[2]); }; auto lift=[&](T x,ll y){ chmax(x.a,0); x.a+=y; x.b=-INF; x.c=-INF; return x; }; int n; cin>>n; if(n==1) drop(1); ReRooting G(n,fold,lift,T(-INF,-INF,-INF)); for(int i=1;i>u>>v; u--;v--; G.add_edge(u,v,1); } auto res=G.build(); string ans(n+1,'1'); for(int i=0;i=0;i--) if(ans[i+1]=='0') ans[i]='0'; ans[1]='1'; ans[2]='1'; cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../tools/chminmax.cpp" #include "../../matching/bipartite.cpp" #undef call_from_test const int MAX = 303; int G[MAX][MAX]={}; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,lim; cin>>n>>m>>lim; auto cs=read(n); const int INF = 1e9; for(int i=0;i>a>>b; a--;b--; G[a][b]=G[b][a]=1; } for(int k=0;k using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../toptree/toptree.cpp" #undef call_from_test using M = Mint; struct Vertex{ M v; void* handle; Vertex():v(0),handle(nullptr){} Vertex(M v):v(v),handle(nullptr){} }; struct Cluster{ M len; M sum_v; M sum_l,sum_r; M rake_v,rake_d; Cluster(M len=M(0)):len(len),sum_v(0),sum_l(0),sum_r(0),rake_v(0),rake_d(0){} void toggle(){ swap(sum_l,sum_r); } static Cluster compress(Cluster x,Vertex *v,Cluster y){ Cluster nxt(x.len+y.len); nxt.sum_v=x.sum_v+x.rake_v+(v->v)+y.sum_v; nxt.sum_l=x.sum_l+x.rake_d+y.sum_l+(x.sum_v+(v->v)+x.rake_v)*y.len; nxt.sum_r=x.sum_r+x.rake_d+y.sum_r+(y.sum_v+(v->v)+x.rake_v)*x.len; return nxt; } static Cluster rake(Cluster x,Cluster y){ x.rake_v+=y.sum_v+y.rake_v; x.rake_d+=y.sum_l+y.rake_d; return x; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl ='\n'; int n; cin>>n; vector vs(n); for(int i=0;i>vs[i].v; vector as(n),bs(n); vector ws(n); for(int i=1;i>as[i]>>bs[i]>>ws[i].v; as[i]--;bs[i]--; } const size_t N = 2e5+1; TopTree G; vector ptr(n); for(int i=0;i>q; for(int i=0;i>t; if(t==1){ int c,a; cin>>c>>a; c--; G.link(rt,Cluster(0),ptr[c]); Cluster x=G.get_subtree(rt,ptr[c]); G.cut(rt,ptr[c]); ans+=M(a)*(x.sum_l+x.rake_d); vs[c]+=M(a); G.set_vertex(ptr[c],Vertex(vs[c])); } if(t==2){ int e,a; cin>>e>>a; Cluster x=G.get_subtree(ptr[bs[e]],ptr[as[e]]); Cluster y=G.get_subtree(ptr[as[e]],ptr[bs[e]]); ans+=M(a)*(x.sum_v+x.rake_v+vs[as[e]])*(y.sum_v+y.rake_v+vs[bs[e]]); ws[e]+=M(a); G.set_edge(ptr[as[e]],ptr[bs[e]],Cluster(ws[e])); } cout< using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/dijkstra.cpp" #include "../../maxflow/fordfulkerson.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif const int MAX = 303; int G[MAX][MAX]={}; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; SCC G(n); int S=n,T=n+1; Dijkstra D(n+2); FordFulkerson F(n+2); for(int i=0;i>u>>v; u--;v--; G.add_edge(u,v); D.add_edge(u,v,1); F.add_edge(u,v,1); } int k=G.build(); vector indeg(n,0); vector outdeg(n,0); for(int i=0;i using namespace std; #define call_from_test #include "../../matching/bipartite.cpp" #undef call_from_test const int MAX = 5050; int ex[MAX][MAX]={}; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; Bipartite G(n+n); for(int i=0;i>a>>b; a--;b--; ex[a][b]=1; G.add_edge(0+a,n+b); } int res=G.build(); int q; cin>>q; for(int i=0;i>x>>y; x--;y--; if(ex[x][y]) res-=G.cut_edge(0+x,n+y); else G.add_edge(0+x,n+y); ex[x][y]^=1; res+=G.build(); cout<<(res==n?"Yes":"No")<<'\n'; } return 0; } ================================================ FILE: test/aoj/3208.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3208 // verification-helper: ERROR 1e-10 #include using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../tools/chminmax.cpp" #include "../../graph/topologicalsort.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; while(cin>>n>>m,n){ TopologicalSort G(n); for(int i=0;i>a>>b; a--;b--; G.add_edge(a,b); } auto ps=G.build(); if(ps.empty()){ cout<<0< dp(n,0); for(int i=n-1;i>=0;i--){ int v=ps[i]; for(int u:G.G[v]) chmax(dp[v],dp[u]+1); } cout<<-1.0/accumulate(dp.begin(),dp.end(),0.0)< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../tools/chminmax.cpp" #include "../../tools/defaultdict.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,m; cin>>n>>m; m++; // [0, m] -> [0, m) auto as=read(n); auto bs=read(n); while(n<34){ as.emplace_back(0); bs.emplace_back(0); n++; } assert(n==34); using ll = long long; const int h = n/2; const int sz = 1<; vector

vp,vq; for(int t=0;t<2;t++){ for(int bit=0;bit>i)&1){ x^=as[t*h+i]; y+=bs[t*h+i]; } } vp.emplace_back(x,y); } swap(vp,vq); } const ll INF = 1e18; const int LOG = 30; ll ans=0; for(int t=LOG-1;t>=0;t--){ if((~m>>t)&1) continue; DefaultDict dp(-INF); auto get_bit=[&](int b){return (b>>t)< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../vector/compress.cpp" #include "../../graph/rangetorange.cpp" #include "../../graph/dijkstra.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector xs(n),ys(n); for(int i=0;i>xs[i]>>ys[i]; // [0n, 1n) : original // [1n, 2n) : x-axis // [2n, 3n) : y-axis const int m = 3 * n; RangeToRange R(m); Dijkstra D(m*3+4*n); auto f0=[&](int u,int v){D.add_edge(u,v,0);}; auto f1=[&](int u,int v){D.add_edge(u,v,1);}; R.init(f0); // swap(xs,ys); for(int k=1;k<=2;k++){ auto cx=compress(xs); auto dx=dict(cx); vector tx(n); for(int i=0;i ls,rs; for(int i=0;i using namespace std; #define call_from_test #include "../../segtree/basic/ushi.cpp" #include "../../segtree/2d/ushi.cpp" #include "../../tools/chminmax.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; map, int> mp; for(int i=0;i>y>>x>>a; mp[{y,x}]=a; } const int INF = 1e9+7; using P = pair; auto f1=[&](int a,int b){return min(a,b);}; auto f2=[&](int a,int b){return a+b;}; auto f=[&](P a,P b){return P(f1(a.first,b.first),f2(a.second,b.second));}; SegmentTree2D> seg(f,P(INF,0)); for(auto[pos,a]:mp){ auto[y,x]=pos; seg.preupdate(y,x); } seg.build(); for(auto[pos,a]:mp){ auto[y,x]=pos; seg.update(y,x,P(a,1)); } int q; cin>>q; for(int i=0;i>u>>d>>l>>r; d++;r++; P res=seg.query(u,d,l,r); ll num=(d-u)*(r-l); if(res.second using namespace std; #define call_from_test #include "../../string/longestcommonsubstring.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int q; cin>>q; while(q--){ string s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../string/knuthmorrispratt.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string t,p; cin>>t>>p; vector res=pattern_match(p,t); for(int x:res) cout< using namespace std; #define call_from_test #include "../../string/rollinghash.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string t,p; cin>>t>>p; using ll = long long; const ll MOD = 1e9+7; const ll B = 1777771; using RH = RollingHash; RH rt(t),rp(p); for(int i=0;i<(int)t.size()-(int)p.size()+1;i++) if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout< using namespace std; #define call_from_test #include "../../string/rollinghash.cpp" #include "../../string/rectanglehash.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w; cin>>h>>w; vector ss(h); for(int i=0;i>ss[i]; int r,c; cin>>r>>c; vector ts(r); for(int i=0;i>ts[i]; const int MOD = 1e9+7; const int B1 = 1777771; const int B2 = 1e8+7; auto srh=rectangle_hash(ss,r,c); auto trh=rectangle_hash(ts,r,c); for(int i=0;i using namespace std; #define call_from_test #include "../../io/precision.cpp" #undef call_from_test signed main(){ using D = double; int n,w; cin>>n>>w; vector vs(n),ws(n); for(int i=0;i>vs[i]>>ws[i]; using P = pair; vector

vp; for(int i=0;i using namespace std; #define call_from_test #include "../../math/isprime.cpp" #undef call_from_test signed main(){ int n; cin>>n; int ans=0; for(int i=0;i>x; ans+=isprime(x); } cout< using namespace std; #define call_from_test #include "../../datastructure/binaryindexedtree.cpp" #include "../../vector/compress.cpp" #include "../../vector/inversion.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector as(n); for(int i=0;i>as[i]; cout< using namespace std; #define call_from_test #include "../../datastructure/skewheap.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using Heap=SkewHeap; auto g=[](int a,int b){return a+b;}; auto c=[](int a,int b){return a>s,s!="end"){ int x; if(s=="insert"){ cin>>x; base=heap.meld(base,heap.push(x)); } if(s=="extract"){ x=heap.top(base); base=heap.pop(base); cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../string/editdistance.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s1,s2; cin>>s1>>s2; cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../algorithm/largestrectangle.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int h,w; cin>>h>>w; vector< vector > cs(h,vector(w)); for(int i=0;i>cs[i][j]; int res=0; vector dp(w,0); for(int i=0;i using namespace std; #define call_from_test #include "../../algorithm/largestrectangle.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using ll = long long; vector vs(n); for(int i=0;i>vs[i]; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #undef call_from_test signed main(){ int n; Mint k; scanf("%d %d",&n,&k.v); printf("%d\n",k.pow(n).v); return 0; } ================================================ FILE: test/aoj/DPL_5_B.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_B #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",Enumeration>::P(k,n).v); return 0; } ================================================ FILE: test/aoj/DPL_5_C.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_C #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../combinatorics/surjection.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",surjection>(n,k).v); return 0; } ================================================ FILE: test/aoj/DPL_5_D.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_D #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",Enumeration>::H(n,k).v); return 0; } ================================================ FILE: test/aoj/DPL_5_E.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_E #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",Mint::comb(k,n).v); return 0; } ================================================ FILE: test/aoj/DPL_5_F.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_F #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",Enumeration>::C(n-1,k-1).v); return 0; } ================================================ FILE: test/aoj/DPL_5_G.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_G #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../combinatorics/bell.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",bell>(n,k).v); return 0; } ================================================ FILE: test/aoj/DPL_5_H.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_H #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",(n<=k)); return 0; } ================================================ FILE: test/aoj/DPL_5_I.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_I #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../combinatorics/surjection.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); using M = Mint; M res=surjection(n,k); for(int i=1;i<=k;i++) res/=M(i); printf("%d\n",res.v); return 0; } ================================================ FILE: test/aoj/DPL_5_J.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_J #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../combinatorics/partitiontable.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",PartitionTable>(n,k)(n,k).v); return 0; } ================================================ FILE: test/aoj/DPL_5_K.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_K #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); printf("%d\n",(n<=k)); return 0; } ================================================ FILE: test/aoj/DPL_5_L.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_L #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/partitiontable.cpp" #undef call_from_test signed main(){ int n,k; scanf("%d %d",&n,&k); PartitionTable> P(n,k); printf("%d\n",k<=n?P(n-k,k).v:0); return 0; } ================================================ FILE: test/aoj/DSL_1_A.quickfind.test.cpp ================================================ // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A #include using namespace std; #define call_from_test #include "../../datastructure/quickfind.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; QuickFind qf(n); for(int i=0;i>c>>x>>y; if(c==0) qf.unite(x,y); if(c==1) cout< using namespace std; #define call_from_test #include "../../datastructure/unionfind.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; UnionFind uf(n); for(int i=0;i>c>>x>>y; if(c) cout< using namespace std; #define call_from_test #include "../../datastructure/weightedunionfind.cpp" #undef call_from_test int main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; WeightedUnionFind wuf(n); for(int i=0;i>t>>x>>y; if(t){ if(wuf.same(x,y)) cout<>z; wuf.unite(x,y,z); } } cout< using namespace std; #define call_from_test #include "../../datastructure/binarytrie.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; BinaryTrie bt; for(int i=0;i>c>>x>>y; if(c==0){ bt.add(x,y); } if(c==1){ int res=bt.order_of_key(y+1)-bt.order_of_key(x); cout< using namespace std; #define call_from_test #include "../../datastructure/kdtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; KDTree kd; for(int i=0;i>x>>y; kd.add_point(i,x,y); } int root=kd.build(); int q; cin>>q; int sx,tx,sy,ty; vector ans; for(int i=0;i>sx>>tx>>sy>>ty; ans.clear(); kd.find(root,sx,tx,sy,ty,0,ans); sort(ans.begin(),ans.end()); for(auto p:ans) cout< using namespace std; #define call_from_test #include "../../segtree/basic/dual.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto h=[](int a,int b){(void)a;return b;}; int ei=INT_MAX; SegmentTree seg(h,ei); seg.init(n); for(int i=0;i>tp; if(tp==0){ int s,t,x; cin>>s>>t>>x; seg.update(s,t+1,x); } if(tp==1){ int s; cin>>s; cout< using namespace std; #define call_from_test #include "../../segtree/basic/dual.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto h=[](int a,int b){return a+b;}; int ei=0; SegmentTree seg(h,ei); seg.init(n); for(int i=0;i>tp; if(tp==0){ int s,t,x; cin>>s>>t>>x; s--; seg.update(s,t,x); } if(tp==1){ int s; cin>>s; s--; cout< using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/lazy.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; auto f=[](int a,int b){return min(a,b);}; auto g=[](int ,int b){return b;}; auto flip=[](int a){return a;}; using Data = decltype(Lazy(f,g,g,flip,INT_MAX,-1)); using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(f,g,g,flip,INT_MAX,-1); auto rt=G.build(vector(n,Node(INT_MAX,-1))); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; rt=G.update(rt,s,t+1,x); } if(c==1){ int s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto f=[](int a,int b){return min(a,b);}; auto g=[](int,int b){return b;}; SegmentTree seg(f,g,g,INT_MAX,-1); seg.build(vector(n,INT_MAX)); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; seg.update(s,t+1,x); } if(c==1){ int s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/lazy.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; using ll = long long; using P = pair; auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[](P a,ll b){return P(a.first+b*a.second,a.second);}; auto h=[](ll a,ll b){return a+b;}; auto flip=[](P a){return a;}; using Data = decltype(Lazy(f,g,h,flip,P(0,0),0)); using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(f,g,h,flip,P(0,0),0); auto rt=G.build(vector(n,Node(P(0,1),0))); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; s--; rt=G.update(rt,s,t,x); } if(c==1){ int s,t; cin>>s>>t; s--; cout< using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/lazy.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; auto f=[](int a,int b){return min(a,b);}; auto g=[](int a,int b){return a+b;}; auto flip=[](int a){return a;}; using Data = decltype(Lazy(f,g,g,flip,INT_MAX,0)); using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(f,g,g,flip,INT_MAX,0); auto rt=G.build(vector(n,Node(0,0))); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; rt=G.update(rt,s,t+1,x); } if(c==1){ int s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto f=[](int a,int b){return min(a,b);}; auto g=[](int a,int b){return a+b;}; SegmentTree seg(f,g,g,INT_MAX,0); seg.build(vector(n,0)); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; seg.update(s,t+1,x); } if(c==1){ int s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/lazy.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; using P = pair; auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[](P a,int b){return P(a.second*b,a.second);}; auto h=[](int,int b){return b;}; auto flip=[](P a){return a;}; int ei=-1010; using Data = decltype(Lazy(f,g,h,flip,P(0,0),ei)); using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(f,g,h,flip,P(0,0),ei); auto rt=G.build(vector(n,Node(P(0,1),ei))); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; rt=G.update(rt,s,t+1,x); } if(c==1){ int s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; using P = pair; auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[](P a,int b){return P(a.second*b,a.second);}; auto h=[](int,int b){return b;}; SegmentTree seg(f,g,h,P(0,0),-1010); seg.build(vector

(n,P(0,1))); for(int i=0;i>c; if(c==0){ int s,t,x; cin>>s>>t>>x; seg.update(s,t+1,x); } if(c==1){ int s,t; cin>>s>>t; cout< using namespace std; #define call_from_test #include "../../datastructure/cartesiantree.cpp" #include "../../tree/lca.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,l; cin>>n>>l; vector vs(n); for(int i=0;i>vs[i]; auto ps=cartesian_tree(vs); LCA lca(n); int rt; for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/disjointsparsetable.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,l; cin>>n>>l; vector as(n); for(int i=0;i>as[i]; auto f=[](int a,int b){return min(a,b);}; DisjointSparseTable st(f); st.build(as); for(int i=0;i+l<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../datastructure/slidingwindowaggregation.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,l; cin>>n>>l; vector as(n); for(int i=0;i>as[i]; auto f=[](int a,int b){return min(a,b);}; SWAG swag(f,INT_MAX); for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/sparsetable.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,l; cin>>n>>l; vector as(n); for(int i=0;i>as[i]; auto f=[](int a,int b){return min(a,b);}; SparseTable st(f); st.build(as); for(int i=0;i+l<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../datastructure/rangeslide.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,l; cin>>n>>l; vector as(n); for(int i=0;i>as[i]; auto cmp=[](int a,int b){return a rs(as,cmp); for(int i=0;i+l<=n;i++) rs.add_range(i,i+l); auto res=rs.build(); for(int i=0;i+l<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../datastructure/radixheap.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,r; cin>>n>>m>>r; using P = pair; vector< vector

> G(n); for(int i=0;i>s>>t>>d; G[s].emplace_back(t,d); } const int INF = numeric_limits::max(); RadixHeap pq; vector dist(n,INF); dist[r]=0; pq.emplace(dist[r],r); while(!pq.empty()){ P p=pq.pop(); int v=p.second; if(dist[v]dist[v]+c){ dist[u]=dist[v]+c; pq.emplace(dist[u],u); } } } for(int i=0;i using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../graph/bellmanford.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,r; cin>>n>>m>>r; BellmanFord G(n); for(int i=0;i>a>>b>>c; G.add_edge(a,b,c); } int neg_loop; auto res=G.build(r,neg_loop); if(neg_loop) drop("NEGATIVE CYCLE"); for(int x:res){ if(x==numeric_limits::max()) cout<<"INF\n"; else cout< using namespace std; #define call_from_test #include "../../datastructure/unionfind.cpp" #include "../../graph/kruskal.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int V,E; cin>>V>>E; Kruskal G(V); for(int i=0;i>a>>b>>c; G.add_edge(a,b,c); } cout< using namespace std; #define call_from_test #include "../../graph/arborescence_tarjan.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,r; cin>>n>>m>>r; Arborescence G(n); for(int i=0;i>s>>t>>w; G.add_edge(s,t,w); } cout< using namespace std; #define call_from_test #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/arborescence_edmond.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,r; cin>>n>>m>>r; Arborescence G(n); for(int i=0;i>s>>t>>w; G.add_edge(s,t,w); } cout< using namespace std; #define call_from_test #include "../../graph/lowlink.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; LowLink G(n); for(int i=0;i>u>>v; G.add_edge(u,v); } G.build(); auto ap=G.ap; sort(ap.begin(),ap.end()); for(int v:ap) cout< using namespace std; #define call_from_test #include "../../graph/lowlink.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; LowLink G(n); for(int i=0;i>u>>v; G.add_edge(u,v); } G.build(); auto bs=G.bs; for(auto &e:bs) if(e.first>e.second) swap(e.first, e.second); sort(bs.begin(),bs.end()); for(auto e:bs) cout< using namespace std; #define call_from_test #include "../../graph/topologicalsort.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,e; cin>>n>>e; TopologicalSort ts(n); for(int i=0;i>s>>t; ts.add_edge(s,t); } auto ps=ts.build(); for(int i:ps) cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/farthest.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using Node = NodeBase; constexpr size_t LIM = 2e6 + 200; using LCT = Farthest; LCT lct; vector vs(1e5+100); vector es(1e5+100); int n; cin>>n; for(int i=0;i>s>>t>>w; es[i]=lct.create(w); lct.evert(vs[s]); lct.evert(vs[t]); lct.link(es[i],vs[s]); lct.link(es[i],vs[t]); } int ans=0; for(int i=0;ild); } cout< using namespace std; #define call_from_test #include "../../tree/diameterforedge.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; DiameterForEdge G(n); for(int i=1;i>s>>t>>w; G.add_edge(s,t,w); } cout< using namespace std; #define call_from_test #include "../../tree/lca.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; LCA lca(n); for(int i=0;i>k; for(int j=0;j>c; lca.add_edge(i,c); } } lca.build(); int q; cin>>q; while(q--){ int u,v; cin>>u>>v; cout< using namespace std; #define call_from_test #include "../../tree/lowestcommonancestor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; LowestCommonAncestor lca(n); for(int i=0;i>k; for(int j=0;j>c; lca.add_edge(i,c); } } lca.build(); int q; cin>>q; while(q--){ int u,v; cin>>u>>v; cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using Node = NodeBase; constexpr size_t LIM = 1e5+100; using LCT = Path; auto f=[](int a,int b){return a+b;}; LCT lct(f,f,f,0); for(int i=0;i>k; for(int j=0;j>c; lct.link(lct[i],lct[c]); } } int q; cin>>q; for(int i=0;i>t; if(t==0){ int a,b; cin>>a>>b; lct.expose(lct[a]); lct[a]->val+=b; lct.pushup(lct[a]); } if(t==1){ int a; cin>>a; cout< using namespace std; #define call_from_test #include "../../tree/eulertourforedge.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; EulerTourForEdge et(n); for(int i=0;i>k; for(int j=0;j>c; et.add_edge(i,c); } } et.build(); BIT bit(2*n); int q; cin>>q; for(int i=0;i>t; if(t==0){ int v,w; cin>>v>>w; auto g=[&](int k,int d){bit.add(k,d);}; et.update(v,w,g); } if(t==1){ int u; cin>>u; int res=0; et.query(0,u,[&](int l,int r){res+=bit.query(l,r);}); cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; using P = pair; using Node = NodeBase; constexpr size_t LIM = 1e5+100; using LCT = Path; auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);}; auto g=[](P a,int b){return P(a.first+b*a.second,a.second);}; auto h=[](ll a,ll b){return a+b;}; LCT lct(f,g,h,0); for(int i=0;i>k; for(int j=0;j>c; lct.link(lct[i],lct[c]); } } int q; cin>>q; ll sum=0; for(int i=0;i>t; if(t==0){ int a,b; cin>>a>>b; lct.update(lct[a],b); sum+=b; } if(t==1){ int a; cin>>a; cout< using namespace std; #define call_from_test #include "../../maxflow/fordfulkerson.cpp" #undef call_from_test int main(){ cin.tie(0); ios::sync_with_stdio(0); int V,E; cin>>V>>E; FordFulkerson G(V); for(int i=0;i>u>>v>>c; G.add_edge(u,v,c); } cout< using namespace std; #define call_from_test #include "../../mincostflow/primaldual.cpp" #undef call_from_test int main(){ cin.tie(0); ios::sync_with_stdio(0); int v,e,f; cin>>v>>e>>f; PrimalDual G(v); for(int i=0;i>u>>v>>c>>d; G.add_edge(u,v,c,d); } if(!G.build(0,v-1,f)) cout<<-1< using namespace std; #define call_from_test #include "../../matching/bipartite.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int X,Y,E; cin>>X>>Y>>E; Bipartite bm(X+Y); for(int i=0;i>x>>y; bm.add_edge(x,X+y); } cout< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); Die d; for(int i=0;i<6;i++) cin>>d.fs[i]; string s; cin>>s; for(int i=0;i<(int)s.size();i++) d.roll(s[i]); cout< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); Die d; for(int i=0;i<6;i++) cin>>d.fs[i]; int n; cin>>n; while(n--){ int a,b; cin>>a>>b; if(d.west()==a) d.roll('E'); if(d.east()==a) d.roll('W'); while(d.top()!=a) d.roll('N'); while(d.south()!=b) d.roll('R'); cout< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); Die ds[2]; for(int j=0;j<2;j++) for(int i=0;i<6;i++) cin>>ds[j].fs[i]; bool f=false; auto vd=makeDice(ds[1]); for(auto e:vd) f|=ds[0]==e; cout<<(f?"Yes":"No")< using namespace std; #define call_from_test #include "../../tools/dice.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector> ds(n); for(int j=0;j>ds[j].fs[i]; bool ff=true; for(int i=0;i using namespace std; #define call_from_test #include "../../math/factorize.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; auto mp=factorize(n); cout< using namespace std; #define call_from_test #include "../../mod/pow.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; const int MOD = 1e9+7; cout< using namespace std; #define call_from_test #include "../../math/totient.cpp" #undef call_from_test signed main(){ using ll = long long; ll n; cin>>n; cout< using namespace std; #define call_from_test #include "../../math/extgcd.cpp" #undef call_from_test signed main(){ int a,b; cin>>a>>b; auto[x,y]=extgcd(a,b); cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ bigint a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ bigint a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ bigint a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ bigint a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ bigint a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ bigint a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #include "../../../tools/chminmax.cpp" #include "../../../graph/dijkstra.cpp" #undef call_from_test signed main(){ int n,m; cin>>n>>m; Polygon ps(n),qs(m); for(int i=0;i>ps[i]; for(int i=0;i>qs[i]; using D = double; const D INF = 1e18; Dijkstra G(n),H(m); for(int i=0;i using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #include "../../../tools/fixpoint.cpp" #undef call_from_test signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; vector ss(n-1); for(int i=0;i+1void{ if(v==s) return; int z=G[v][0]; for(int u:G[v]){ double a1=calc(qs[p]-qs[v],qs[z]-qs[v]); if(z==p) a1=8; double a2=calc(qs[p]-qs[v],qs[u]-qs[v]); if(u==p) a2=8; if(a1>a2) z=u; } res.emplace_back(qs[v]); dfs(z,v); })(t,s); ans+=max(0.0,area(res)); } cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test // segmentArrangement signed main(){ int n,m; cin>>n>>m; vector ss(n); Polygon ps(m); for(int i=0;i>ss[i]; for(int i=0;i>ps[i]; map mp; for(int i=0;i>s>>g; ps.emplace_back(s); ps.emplace_back(g); auto H=segmentArrangement(ss,ps); vector< vector< pair > > G(H.size()); for(int i=0;i<(int)H.size();i++) for(int j:H[i]) G[i].emplace_back(j,abs(ps[i]-ps[j])); double ans=0,tmp=0; for(int i=0;i used(G.size(),0); queue q; for(int i=0;i<(int)G.size();i++) if(ps[i]==g) {used[i]=1;q.emplace(i);} while(!q.empty()){ int v=q.front();q.pop(); if(ps[v]==s){ cout<<(int)-1< using namespace std; #define call_from_test #include "../../../tools/chminmax.cpp" #include "../../../io/precision.cpp" #include "../../../geometry/geometry.cpp" #undef call_from_test signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; ps=andrewScan(ps); n=ps.size(); int m; cin>>m; Polygon cs(m); cin>>cs; double ans=0; for(int i=0;i using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #include "../../../tools/chminmax.cpp" #undef call_from_test signed main(){ int n; cin>>n; Polygon ps(n); for(int i=0;i>ps[i]; for(int i=0;idouble{ Point p=getCrossPointLL(b,Line(ps[k],ps[k]+v)); if(abs(p-ps[i+w]) using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test // Projection signed main(){ Point p1,p2; cin>>p1>>p2; int q; cin>>q; while(q--){ Point p; cin>>p; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //Reflect signed main(){ Point p1,p2; cin>>p1>>p2; int q; cin>>q; while(q--){ Point p; cin>>p; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //CCW signed main(){ Point p0,p1; cin>>p0>>p1; int q; cin>>q; while(q--){ Point p2; cin>>p2; int t=ccw(p0,p1,p2); if(t==CCW_COUNTER_CLOCKWISE) cout<<"COUNTER_CLOCKWISE"< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //Parallel / Orthogonal signed main(){ int q; cin>>q; while(q--){ Point p0,p1,p2,p3; cin>>p0>>p1>>p2>>p3; if(isParallel(Line(p0,p1),Line(p2,p3))) cout<<2< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //intersectSS signed main(){ int q; cin>>q; while(q--){ Point p0,p1,p2,p3; cin>>p0>>p1>>p2>>p3; cout<<(intersectSS(Segment(p0,p1),Segment(p2,p3)))< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //cross point signed main(){ int q; cin>>q; while(q--){ Point p0,p1,p2,p3; cin>>p0>>p1>>p2>>p3; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #include "../../../io/precision.cpp" #undef call_from_test //distanceSS signed main(){ int q; cin>>q; for(int i=0;i>p0>>p1>>p2>>p3; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //Area of Polygon signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //isConvex signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //contains signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; int q; cin>>q; while(q--){ Point r; cin>>r; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //convex hull signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; Polygon qs=convex_hull(ps); cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //diameter of Polygon signed main(){ int n; cin>>n; Polygon ps(n); cin>>ps; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //convexCut signed main(){ int n; cin>>n; Polygon gs(n); cin>>gs; Polygon ps=andrewScan(gs); int q; cin>>q; while(q--){ Line l; cin>>l.p1>>l.p2; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test // closest_pair signed main(){ int n; cin>>n; Polygon p(n); for(int i=0;i>p[i]; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test // manhattan_intersection signed main(){ int n; cin>>n; vector ss(n); for(int i=0;i>ss[i]; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //intersectCC signed main(){ Circle c1,c2; cin>>c1>>c2; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //getCrossPointCL signed main(){ Circle c; int q; cin>>c>>q; while(q--){ Line l; cin>>l; auto pp=getCrossPointCL(c,l); if(pp.size()==1u) pp.emplace_back(pp[0]); if(pp[1] using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //intersectCC signed main(){ Circle c1,c2; cin>>c1>>c2; auto pp=getCrossPointCC(c1,c2); if(pp.size()==1u) pp.emplace_back(pp[0]); if(pp[1] using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //tangent to a Circle signed main(){ Point p; Circle c; cin>>p>>c; auto pp=tangent(c,p); for(auto p:pp) cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #undef call_from_test //Common Tangent signed main(){ Circle c1,c2; cin>>c1>>c2; auto ls=tangent(c1,c2); Polygon ps; for(auto l:ls) ps.emplace_back(getCrossPointCL(c1,l)[0]); sort(ps.begin(),ps.end()); for(auto p:ps) cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #include "../../../io/precision.cpp" #undef call_from_test // intersection of a circle and a polygon signed main(){ int n; double r; cin>>n>>r; Circle c(Point(0,0),r); Polygon ps(n); for(int i=0;i>ps[i]; cout< using namespace std; #define call_from_test #include "../../../geometry/geometry.cpp" #include "../../../io/precision.cpp" #undef call_from_test // area of 2 circles' intersection signed main(){ Circle c1,c2; cin>>c1>>c2; cout< using namespace std; #define call_from_test #include "../../bflow/capacityscaling.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; MinCostFlow G(n+n); for(int i=0;i> E(n); for(int i=0;i>a; E[i].emplace_back(G.add_edge(i,n+j,0,1,a)); } } assert(G.build()); cout< using namespace std; #define call_from_test #include "../../tools/cc_hash.cpp" #include "../../datastructure/pb_ds_cc_hash_table.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; gmap> mp; int q; cin>>q; for(int i=0;i>t; if(t==0){ ll k,v; cin>>k>>v; mp[k]=v; } if(t==1){ ll k; cin>>k; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../combinatorics/bernoulli.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; Bernoulli bs(conv); bs.build(n); for(int i=0;i<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../matching/hopcroft_karp.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int L,R,M; cin>>L>>R>>M; HopcroftKarp G(L,R); for(int i=0;i>a>>b; G.add_edge(a,b); } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/and.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; int sz=1< as(sz),bs(sz); for(int i=0;i>as[i].v; for(int i=0;i>bs[i].v; fwht(as,bitwise_and::zeta); fwht(bs,bitwise_and::zeta); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/xor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; int sz=1< as(sz),bs(sz); for(int i=0;i>as[i].v; for(int i=0;i>bs[i].v; fwht(as,bitwise_xor::zeta); fwht(bs,bitwise_xor::zeta); for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/cartesiantree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n; cin>>n; vector as(n); for(int i=0;i>as[i]; auto ps=cartesian_tree(as); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; NTT<2> ntt; using M = decltype(ntt)::M; vector as(n),bs(m); for(int i=0;i>as[i].v; for(int i=0;i>bs[i].v; auto cs=ntt.multiply(as,bs); for(int i=0;i<(int)cs.size();i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../convolution/garner.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; vector as(n),bs(m); for(int i=0;i>as[i]; for(int i=0;i>bs[i]; const int MOD = 1e9+7; Garner arb; auto cs=arb.multiply(as,bs,MOD); for(int i=0;i<(int)cs.size();i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #define double long double #include "../../convolution/fastfouriertransform.cpp" #undef double #include "../../convolution/arbitrarymod.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; using M = Mint; ArbitraryMod arb; vector as(n),bs(m); for(int i=0;i>as[i].v; for(int i=0;i>bs[i].v; auto cs=arb.multiply(as,bs); for(int i=0;i<(int)cs.size();i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../graph/cycle.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; DirectedCycle G(n); vector> I(n); for(int i=0;i>u>>v; G.add_edge(u,v); I[u][v]=i; } auto vs=G.build(); if(vs.empty()){ cout<<-1< using namespace std; #define call_from_test #include "../../mod/log.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int t; cin>>t; while(t--){ int x,y,m; cin>>x>>y>>m; int l=mod_log(x,y,m); if(l==m) l=-1; cout< using namespace std; #define call_from_test #include "../../graph/dominatortree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,s; cin>>n>>m>>s; DominatorTree G(n); for(int i=0;i>a>>b; G.add_edge(a,b); } G.build(s); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/affine.cpp" #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/lazy.cpp" #include "../../bbst/rbst/impl/basic.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using M = Mint; using T = pair; using E = pair; auto [f,g,h,ti,ei]=Affine::params(); auto flip=[](T a){return a;}; using Data = decltype(Lazy(f,g,h,flip,ti,ei)); using Node = Data::Node; constexpr size_t LIM = 1e6; Basic G(f,g,h,flip,ti,ei); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; vector vt; for(int i=0;i>t; if(t==0){ int k,x; cin>>k>>x; rt=G.insert(rt,k,Node(T(x,1),ei)); } if(t==1){ int k; cin>>k; rt=G.erase(rt,k); } if(t==2){ int l,r; cin>>l>>r; rt=G.toggle(rt,l,r); } if(t==3){ int l,r,b,c; cin>>l>>r>>b>>c; rt=G.update(rt,l,r,E(b,c)); } if(t==4){ int l,r; cin>>l>>r; cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; using ll = long long; using Node = NodeBase; auto f=[&](ll a,ll b){return a+b;}; constexpr size_t LIM = 2e5+100; using LCT = Path; LCT lct(f,f,f,0); for(int i=0;i>u>>v; lct.evert(lct[v]); lct.link(lct[u],lct[v]); } for(int i=0;i>t; if(t==0){ int u,v,w,x; cin>>u>>v>>w>>x; lct.evert(lct[u]); lct.cut(lct[v]); lct.evert(lct[x]); lct.link(lct[w],lct[x]); } if(t==1){ int p,x; cin>>p>>x; lct.evert(lct[p]); lct.update(lct[p],x); } if(t==2){ int u,v; cin>>u>>v; lct.evert(lct[u]); cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/subtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; using Node = NodeBase; constexpr size_t LIM = 2e5+100; using LCT = Subtree; LCT lct; for(int i=0;i>u>>v; lct.evert(lct[v]); lct.link(lct[u],lct[v]); } for(int i=0;i>t; if(t==0){ int u,v,w,x; cin>>u>>v>>w>>x; lct.evert(lct[u]); lct.cut(lct[v]); lct.evert(lct[x]); lct.link(lct[w],lct[x]); } if(t==1){ int p,x; cin>>p>>x; as[p]+=x; lct.set_val(lct[p],as[p]); } if(t==2){ int v,p; cin>>v>>p; lct.evert(lct[p]); lct.cut(lct[v]); cout< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #undef call_from_test using ll = long long; struct Vertex{ void* handle; ll val; Vertex(ll val=0):handle(nullptr),val(val){} }; struct Cluster{ ll res; Cluster(ll res=0):res(res){} void toggle(){} static Cluster compress(Cluster x,Vertex* v,Cluster y){ return Cluster(x.res+v->val+y.res); } static Cluster rake(Cluster x,Cluster y){ return Cluster(x.res+y.res); } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; const size_t N = 2e5; TopTree G; int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; vector vs(n); for(int i=0;i>u>>v; G.link(vs[u],Cluster(0),vs[v]); } for(int i=0;i>t; if(t==0){ int u,v,w,x; cin>>u>>v>>w>>x; G.cut(vs[u],vs[v]); G.link(vs[w],Cluster(0),vs[x]); } if(t==1){ int p,x; cin>>p>>x; as[p]+=x; G.set_vertex(vs[p],Vertex(as[p])); } if(t==2){ int v,p; cin>>v>>p; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/linearfunction.cpp" #include "../../math/dual.cpp" #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; vector as(n),bs(n); for(int i=0;i>as[i]>>bs[i]; using M = Mint; using LF = LinearFunction; using DL = Dual; using P = pair; using Node = NodeBase; auto f=[&](P a,P b){return P(a.first*b.first,a.second*b.second);}; auto g=[&](P a,int){return a;}; auto h=[&](int a,int){return a;}; auto flip=[&](P a){return P(a.second.v,a.first);}; constexpr size_t LIM = 2e5+100; using LCT = Path; LCT lct(f,g,h,flip,0); for(int i=0;i>u>>v; lct.evert(lct[v]); lct.link(lct[u],lct[v]); } for(int i=0;i>t; if(t==0){ int u,v,w,x; cin>>u>>v>>w>>x; lct.evert(lct[u]); lct.cut(lct[v]); lct.evert(lct[x]); lct.link(lct[w],lct[x]); } if(t==1){ int p,c,d; cin>>p>>c>>d; lct.set_val(lct[p],P(LF(c,d),LF(c,d))); } if(t==2){ int u,v,x; cin>>u>>v>>x; lct.evert(lct[u]); cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/linearfunction.cpp" #include "../../math/twoway.cpp" #include "../../toptree/toptree.cpp" #undef call_from_test using M = Mint; using L = LinearFunction; using P = TwoWay; struct Vertex{ void* handle; L val; Vertex(L val=L()):handle(nullptr),val(val){} }; struct Cluster{ P res; Cluster():res(L(1,0)){} Cluster(L val):res(val){} Cluster(P res):res(res){} void toggle(){swap(res.x,res.y);} static Cluster compress(Cluster x,Vertex* v,Cluster y){ return Cluster(x.res*P(v->val)*y.res); } static Cluster rake(Cluster x,Cluster){ return x; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; const size_t N = 2e5 + 10; TopTree G; int n,q; cin>>n>>q; vector as(n),bs(n); for(int i=0;i>as[i]>>bs[i]; vector vs(n); for(int i=0;i>u>>v; G.link(vs[u],Cluster(L(1,0)),vs[v]); } Vertex* du=G.create(L(1,0)); Vertex* dv=G.create(L(1,0)); for(int i=0;i>t; if(t==0){ int u,v,w,x; cin>>u>>v>>w>>x; G.cut(vs[u],vs[v]); G.link(vs[w],Cluster(L(1,0)),vs[x]); } if(t==1){ int p,c,d; cin>>p>>c>>d; G.set_vertex(vs[p],Vertex(L(c,d))); } if(t==2){ int u,v,x; cin>>u>>v>>x; G.link(du,Cluster(L(1,0)),vs[u]); G.link(dv,Cluster(L(1,0)),vs[v]); auto res=G.get_path(du,dv).res.x; cout< using namespace std; #define call_from_test #include "../../math/enumerate_primes.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,a,b; cin>>n>>a>>b; auto ps=enumerate_primes(n); vector qs; for(int i=b;i<(int)ps.size();i+=a) qs.emplace_back(ps[i]); cout< using namespace std; #define call_from_test #include "../../graph/triangle.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,m; cin>>n>>m; vector xs(n); for(int i=0;i>xs[i]; Triangle G(n); for(int i=0;i>u>>v; G.add_edge(u,v); } const ll mod = 998244353; ll ans=0; auto f=[&](int x,int y,int z){ ans+=xs[x]*xs[y]%mod*xs[z]%mod; ans%=mod; }; G.build(f); cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector as(n); for(int i=0;i>as[i].v; auto bs=FPS.exp(as,n); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../polynomial/berlekampmassey.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; vector as(n); for(int i=0;i>as[i].v; auto cs=berlekamp_massey(as); cs.pop_back(); reverse(cs.begin(),cs.end()); cout< using namespace std; #define call_from_test #include "../../tree/centroid.cpp" #include "../../tools/fixpoint.cpp" #include "../../convolution/fastfouriertransform.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; Centroid G(n); for(int i=1;i>a>>b; G.add_edge(a,b); } queue que; que.emplace(G.build(0)[0]); using ll = long long; vector ans(n,0); while(!que.empty()){ int r=que.front();que.pop(); vector cnt; cnt.emplace_back(1); for(int c:G[r]){ if(!G.alive(c)) continue; vector num; MFP([&](auto dfs,int v,int p,int d)->void{ while((int)cnt.size()<=d) cnt.emplace_back(0); while((int)num.size()<=d) num.emplace_back(0); cnt[d]++; num[d]++; for(int u:G[v]){ if(u==p or !G.alive(u)) continue; dfs(u,v,d+1); } })(c,r,1); auto ns=FFT::multiply(num,num); for(int i=0;i<(int)min(ans.size(),ns.size());i++) ans[i]-=ns[i]; } auto cs=FFT::multiply(cnt,cnt); for(int i=0;i<(int)min(ans.size(),cs.size());i++) ans[i]+=cs[i]; G.disable(r); for(int c:G[r]) if(G.alive(c)) que.emplace(G.build(c)[0]); } for(int i=1;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector as(n); for(int i=0;i>as[i].v; auto bs=FPS.inv(as,n); for(int i=0;i using namespace std; #define call_from_test #include "../../tools/int128.cpp" #undef call_from_test #ifdef __clang__ #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin>>T; using ll = __int128_t; for(int t=0;t>A>>K; ll L=0,R=A+1; while(L+1>1; ll res=1; for(int i=0;iA) break; } if(res<=A) L=M; else R=M; } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../math/bostanmori.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); NTT<2> ntt; using M = decltype(ntt)::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; int d; cin>>d; long long k; cin>>k; vector as(d),cs(d); for(int i=0;i>as[i].v; for(int i=0;i>cs[i].v; reverse(cs.begin(),cs.end()); for(auto &c:cs) c=-c; cs.emplace_back(1); BostanMori seq(conv); cout< using namespace std; #define call_from_test #include "../../linkcuttree/base.cpp" #include "../../linkcuttree/path.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; using Node = NodeBase; constexpr size_t LIM = 1e6; using LCT = Path; auto f=[](int a,int b){return a+b;}; LCT lct(f,f,f,0); for(int i=0;i>p; lct.link(lct[p],lct[i]); } for(int i=0;i>u>>v; cout< using namespace std; #define call_from_test #include "../../tree/lowestcommonancestor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; LowestCommonAncestor G(n); for(int i=1;i>p; G.add_edge(p,i); } G.build(); for(int i=0;i>u>>v; cout< using namespace std; #define call_from_test #include "../../convexhulltrick/segmentcontainer.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,q; cin>>n>>q; vector as(n),bs(n); for(int i=0;i>as[i]>>bs[i]; vector ts(q),xs(q),ys(q); vector ps; for(int i=0;i>ts[i]; if(ts[i]==0) cin>>xs[i]>>ys[i]; if(ts[i]==1) cin>>xs[i]; ps.emplace_back(xs[i]); } int lb=-1e9,ub=+1e9; ps.emplace_back(lb); ps.emplace_back(ub); MinSegmentContainer seg(ps); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/log.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector as(n); for(int i=0;i>as[i].v; auto bs=FPS.log(as,n); for(int i=0;i using namespace std; #define call_from_test #include "../../graph/manhattanmst.cpp" #include "../../datastructure/unionfind.cpp" #include "../../graph/kruskal.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; int n; cin>>n; vector xs(n),ys(n); for(int i=0;i>xs[i]>>ys[i]; Kruskal mst(n); for(auto[u,v]:manhattanmst(xs,ys)) mst.add_edge(u,v,abs(xs[u]-xs[v])+abs(ys[u]-ys[v])); cout< using namespace std; #define call_from_test #include "../../tools/fastio.cpp" #undef call_from_test signed main(){ const char newl = '\n'; int t; cin>>t; for(int i=0;i>a>>b; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../linearalgebra/matrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; using Mat = Matrix; int n; cin>>n; Mat A(n,n); for(int i=0;i>A[i][j].v; cout< using namespace std; #define call_from_test #include "../../graph/independentset.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; IndependentSet G(n); for(int i=0;i>u>>v; G.add_edge(u,v); } int X=G.build(); cout< using namespace std; #define call_from_test #include "../../bflow/capacityscaling.cpp" #undef call_from_test #ifdef __clang__ #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; using ll = long long; MinCostFlow G(n); for(int i=0;i>b; if(b>0) G.add_supply(i,+b); if(b<0) G.add_demand(i,-b); } vector es; for(int i=0;i>s>>t>>l>>u>>c; auto e=G.add_edge(s,t,l,u,c); es.emplace_back(e); } if(!G.build()){ cout<<"infeasible\n"; return 0; } auto print=[&](auto res){ if(res==0){ cout<<0<<'\n'; return; } if(res<0) cout<<'-',res*=-1; string ans; while(res){ ans+=char('0'+res%10); res/=10; } reverse(ans.begin(),ans.end()); cout<()); auto p=G.get_potential(); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/montmort.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; Montmort mm(n,m); for(int i=1;i<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/div.cpp" #include "../../formalpowerseries/mod.cpp" #include "../../polynomial/multieval.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; MultiEval me(conv); vector cs(n),ps(m); for(int i=0;i>cs[i].v; for(int i=0;i>ps[i].v; auto ans=me.build(cs,ps); for(int i=0;i using namespace std; #define call_from_test #include "../../string/suffixarray.cpp" #include "../../string/longestcommonprefix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; LongestCommonPrefix lcp(s); int n=s.size(); long long ans=0; for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../combinatorics/partition.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; Partition ps(conv); ps.build(n); for(int i=0;i<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../bbst/rbst/rbst.cpp" #include "../../bbst/rbst/data/array.cpp" #include "../../bbst/rbst/impl/persistent.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using Data = Array; using Node = Data::Node; const int LIM = 2e7; Persistent pa; Node* rt=pa.create(0); int q; cin>>q; vector ss(q,nullptr); for(int i=0;i>a; if(a==0){ int t,x; cin>>t>>x; Node* p=~t?ss[t]:rt; ss[i]=pa.insert(p,p->cnt,Node(x)); } if(a==1){ int t; cin>>t; cout< using namespace std; #define call_from_test #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; BIT bit(n); for(int i=0;i>t; if(t==0){ int p,x; cin>>p>>x; bit.add(p,x); } if(t==1){ int l,r; cin>>l>>r; cout< using namespace std; #define call_from_test #include "../../vector/compress.cpp" #include "../../segtree/count/dynamic_offline.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector xs(n+q),ys(n+q),ws(n+q); for(int i=0;i>xs[i]>>ys[i]>>ws[i]; vector ts(q); vector ls(q),ds(q),rs(q),us(q); for(int i=0;i>ts[i]; if(ts[i]==0) cin>>xs[n+i]>>ys[n+i]>>ws[n+i]; if(ts[i]==1) cin>>ls[i]>>ds[i]>>rs[i]>>us[i]; } auto vs=compress(xs); auto idx= [&](int x){return lower_bound(vs.begin(),vs.end(),x)-vs.begin();}; using ll = long long; RangeCount seg(vs.size()); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/linearfunction.cpp" #include "../../segtree/basic/ushi.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n),bs(n); for(int i=0;i>as[i]>>bs[i]; using M = Mint; using T = LinearFunction; auto f=[&](T x,T y){return x*y;}; T ti=T::mul_identity(); SegmentTree seg(f,ti); vector vt; for(int i=0;i>t; if(t==0){ int p,c,d; cin>>p>>c>>d; seg.set_val(p,T(M(c),M(d))); } if(t==1){ int l,r,x; cin>>l>>r>>x; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/div.cpp" #include "../../formalpowerseries/mod.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../polynomial/multieval.cpp" #include "../../polynomial/interpolate.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; Interpolate ip(conv); vector xs(n),ys(n); for(int i=0;i>xs[i].v; for(int i=0;i>ys[i].v; auto ans=ip.build(xs,ys); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/shift.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,c; cin>>n>>c; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector as(n); for(int i=0;i>as[i].v; auto bs=FPS.shift(as,M(c)); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #include "../../formalpowerseries/pow.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); vector as(n); for(int i=0;i>as[i].v; auto bs=FPS.pow(as,m,n); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/linearfunction.cpp" #include "../../datastructure/slidingwindowaggregation.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; using T = LinearFunction; auto f=[](T a,T b){return a*b;}; SWAG swag(f,T::mul_identity()); int q; cin>>q; for(int i=0;i>t; if(t==0){ int a,b; cin>>a>>b; swag.push(T(M(a),M(b))); } if(t==1){ swag.pop(); } if(t==2){ int x; cin>>x; swag.fold([&](T a,T b){cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/affine.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using M = Mint; using T = pair; using E = pair; auto [f,g,h,ti,ei]=Affine::params(); SegmentTree seg(f,g,h,ti,ei); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; vector vt; for(int i=0;i>t; if(t==0){ int l,r,b,c; cin>>l>>r>>b>>c; seg.update(l,r,T(M(b),M(c))); } if(t==1){ int l,r; cin>>l>>r; cout< using namespace std; #define call_from_test #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; WaveletMatrix wm(as); for(int i=0;i>l>>r>>k; cout< using namespace std; #define call_from_test #include "../../vector/compress.cpp" #include "../../segtree/count/dynamic_offline.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector xs(n),ys(n),ws(n); for(int i=0;i>xs[i]>>ys[i]>>ws[i]; auto vs=compress(xs); auto idx= [&](int x){return lower_bound(vs.begin(),vs.end(),x)-vs.begin();}; using ll = long long; RangeCount seg(vs.size()); for(int i=0;i>l>>d>>r>>u; cout< using namespace std; #define call_from_test #include "../../string/zalgorithm.cpp" #include "../../string/run.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string ss; cin>>ss; auto run=Run::enumerate(ss); set vis; vector ans; for(int t=1;t<=(int)ss.size();t++){ for(auto lr:run[t]){ if(vis.count(lr)) continue; vis.emplace(lr); ans.emplace_back(t,lr.first,lr.second); } } cout< using namespace std; #define call_from_test #include "../../graph/stronglyconnectedcomponent.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; SCC G(n); for(int i=0;i>a>>b; G.add_edge(a,b); } int k=G.build(); cout< using namespace std; #define call_from_test #include "../../convexhulltrick/segmentcontainer.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,q; cin>>n>>q; vector ls(n),rs(n),as(n),bs(n); for(int i=0;i>ls[i]>>rs[i]>>as[i]>>bs[i]; vector ts(q),v0(q),v1(q),v2(q),v3(q); for(int i=0;i>ts[i]; if(ts[i]==0) cin>>v0[i]>>v1[i]>>v2[i]>>v3[i]; if(ts[i]==1) cin>>v0[i]; } vector ps; for(int i=0;i seg(ps); for(int i=0;i2e18) cout<<"INFINITY"<<'\n'; else cout< using namespace std; #define call_from_test #include "../../datastructure/binarytrie.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; BinaryTrie bt; int q; cin>>q; for(int i=0;i>t>>x; if(t==0){ if(bt.find(x)) continue; bt.add(x,1); } if(t==1){ if(!bt.find(x)) continue; bt.sub(bt.find(x),1); } if(t==2){ cout<<(x^bt.val(bt.xmin(x)))< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,t; cin>>n>>t; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); decltype(FPS)::init(t+1); vector cnt(t+1,0); for(int i=0;i>s; cnt[s]++; } vector as(t+1); for(int s=1;s<=t;s++){ for(int k=1;s*k<=t;k++){ if(k&1) as[s*k]+=M(cnt[s])*decltype(FPS)::Invs(k); else as[s*k]-=M(cnt[s])*decltype(FPS)::Invs(k); } } auto bs=FPS.exp(as,t+1); for(int i=1;i<=t;i++){ if(i>1) cout<<" "; cout< using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../graph/dijkstra.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,m,s,t; cin>>n>>m>>s>>t; using ll = long long; Dijkstra G(n); for(int i=0;i>a>>b>>c; G.add_edge(a,b,c); } G.build(s); auto ps=G.restore(t); if(ps.empty()) drop(-1); int y=ps.size()-1; cout< using namespace std; #define call_from_test #include "../../geometry/argsort.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using ll = long long; struct Point{ll x,y;}; vector ps(n); for(int i=0;i>ps[i].x>>ps[i].y; argsort(ps); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/sqrt.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin>>T; for(int t=0;t>y>>p; auto res=mod_sqrt(y,p); if(res.empty()) cout<<-1<<"\n"; else cout< using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../mod/sqrt.cpp" #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/sqrt.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; FormalPowerSeries FPS(conv); deque as(n); for(int i=0;i>as[i]; while(!as.empty()&&as.front()==0) as.pop_front(); if(as.empty()){ for(int i=0;i ps(n,M(0)); for(int i=0;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto as=read(n); WaveletMatrix wm(as); for(int i=0;i>l>>r>>x; cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../vector/compress.cpp" #include "../../algorithm/mo.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto as=read(n); auto dc=dict(compress(as)); vector cs(n); for(int i=0;i ans(q); BIT bit(n); auto expandL=[&](int i){bit.add(cs[i],+1);res+=bit.query(0,cs[i]);}; auto expandR=[&](int i){bit.add(cs[i],+1);res+=bit.query(cs[i]+1,n);}; auto shrinkL=[&](int i){bit.add(cs[i],-1);res-=bit.query(0,cs[i]);}; auto shrinkR=[&](int i){bit.add(cs[i],-1);res-=bit.query(cs[i]+1,n);}; Mo mo(n,400,expandL,expandR,shrinkL,shrinkR); for(int i=0;i>l>>r; mo.add(l,r); } mo.build(); for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/cumulativesum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; CumulativeSum cs(as); for(int i=0;i>l>>r; cout< using namespace std; #define call_from_test #include "../../datastructure/disjointsparsetable.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; auto f=[](int a,int b){return min(a,b);}; DisjointSparseTable rmq(f); rmq.build(as); for(int i=0;i>l>>r; cout< using namespace std; #define call_from_test #include "../../datastructure/sparsetable.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; auto f=[](int a,int b){return min(a,b);}; SparseTable rmq(f); rmq.build(as); for(int i=0;i>l>>r; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../combinatorics/stirling1st.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; Stirling1st ss(conv); ss.build(n); for(int i=0;i<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../combinatorics/stirling2nd.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; NTT<2> ntt; using M = NTT<2>::M; auto conv=[&](auto as,auto bs){return ntt.multiply(as,bs);}; Stirling2nd ss(conv); ss.build(n); for(int i=0;i<=n;i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/or.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; using V = valarray; int sz=1< as(sz,V(n+1)),bs(sz,V(n+1)); for(int i=0;i>as[i][__builtin_popcount(i)].v; for(int i=0;i>bs[i][__builtin_popcount(i)].v; fwht(as,bitwise_or::zeta); fwht(bs,bitwise_or::zeta); vector cs(sz,V(n+1)); for(int i=0;i using namespace std; #define call_from_test #include "../../string/suffixarray.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; SuffixArray sa(s); for(int i=0;i<(int)s.size();i++){ if(i) cout<<" "; cout< using namespace std; #define call_from_test #include "../../math/sum_of_floor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin>>T; for(int t=0;t>n>>m>>a>>b; cout< using namespace std; #define call_from_test #include "../../math/totient.cpp" #include "../../mod/tetration.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin>>T; for(int t=0;t>a>>b>>m; cout< using namespace std; #define call_from_test #include "../../tools/drop.cpp" #include "../../graph/nicetree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; {string s;cin>>s;} {string s;cin>>s;} int n,m; cin>>n>>m; NiceTree G(n); for(int i=0;i>u>>v; u--;v--; G.add_edge(u,v); } G.build(); auto T=G.T; if(T.empty()) drop(-1); assert((int)T.size()<=3*n+m+10); cout<<"s td "< using namespace std; #define call_from_test #include "../../tools/fixpoint.cpp" #include "../../tree/diameterforedge.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; int n; cin>>n; DiameterForEdge G(n); for(int i=1;i>a>>b>>c; G.add_edge(a,b,c); } auto seq=G.restore(); cout< using namespace std; #define call_from_test #include "../../graph/twoedgeconnectedcomponents.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; TwoEdgeConnectedComponents C(n); for(int i=0;i>a>>b; C.add_edge(a,b); } int k=C.build(); cout< using namespace std; #define call_from_test #include "../../graph/stronglyconnectedcomponent.cpp" #include "../../graph/twosatisfiability.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; cin>>s; int n,m; cin>>n>>m; TwoSat ts(n+1); for(int i=0;i>a>>b>>c; if(a<0) a=ts.negate(abs(a)); if(b<0) b=ts.negate(abs(b)); ts.add_or(a,b); } auto res=ts.build(); if(res.empty()){ cout<<"s UNSATISFIABLE"< using namespace std; #define call_from_test #include "../../datastructure/unionfind.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; UnionFind uf(n); for(int i=0;i>t>>u>>v; if(t==0) uf.unite(u,v); if(t==1) cout< using namespace std; #define call_from_test #include "../../tree/heavylightdecomposition.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; HLD G(n); for(int i=1;i>u>>v; G.add_edge(u,v); } G.build(); using ll = long long; BIT bit(n); for(int i=0;i>t; if(t==0){ int p,x; cin>>p>>x; bit.add(G.vid[p],x); } if(t==1){ int u,v; cin>>u>>v; ll res=0; auto f=[&](int l,int r){res+=bit.query(l,r);}; G.for_each(u,v,f); cout< using namespace std; #define call_from_test #include "../../tree/eulertourforvertex.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; EulerTourForVertex G(n); for(int i=1;i>p; G.add_edge(p,i); } G.build(0); BIT bit(n); for(int i=0;i>t; if(t==0){ int u,x; cin>>u>>x; bit.add(G.idx(u),x); } if(t==1){ int u; cin>>u; G.exec(u,[&](int l,int r){cout< using namespace std; #define call_from_test #include "../../io/space.cpp" #include "../../string/zalgorithm.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; auto zs=zalgorithm(s); zs.pop_back(); space(zs); return 0; } ================================================ FILE: test/yukicoder/0022.test.cpp ================================================ // verification-helper: PROBLEM https://yukicoder.me/problems/22 #include using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../polynomial/lagrangeinterpolation.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; const int MAX = 666 * 6 + 10; vector dp(MAX,0); dp[0]=M(1); for(int x:{1,5,10,50,100,500}) for(int j=x;j>T; while(T--){ using ll = long long; ll m; cin>>m; vector ys(6); for(int i=0;i<6;i++) ys[i]=dp[(m%500)+(i*500)]; cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../polynomial/berlekampmassey.cpp" #include "../../convolution/naive.cpp" #include "../../math/bostanmori.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); long long n; int p,c; cin>>n>>p>>c; using M = Mint; using Poly = vector; const int d = 1500; const int MAX = p+c+1; vector cf(MAX,Poly(d,0)); cf[0][0]=M(1); for(int v:{2,3,5,7,11,13}){ vector nx(MAX,Poly(d,0)); for(int t=0;t<=p;t++) for(int i=0;i nx(MAX,Poly(d,0)); for(int t=p;t<=p+c;t++) for(int i=0;i bm(naive()); cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; bigint MOD = 1000000000; ll n,m; cin>>n>>m; n/=1000; n%=m; bigint res(1); for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/bitvector.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,s,x,y,z; cin>>n>>s>>x>>y>>z; int q; cin>>q; BitVector bv(n+1); int a=s; for(int i=1;i<=n;i++){ bv.set(i,a&1); a=(1LL*x*a+y)%z; } for(int i=0;i>s>>t>>u>>v; auto p=bv.get(s,t+1),q=bv.get(u,v+1); for(int i=0;i<(int)p.dat.size();i++) p.dat[i]^=q.dat[i]; bv.set(u,v+1,p); } for(int i=1;i<=n;i++) cout<<(bv.get(i)?"O":"E"); cout< using namespace std; #define call_from_test #include "../../tools/iskado.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int w,h; cin>>w>>h; vector> st(h,vector(w)); for(int i=0;i>st[i][j]; using T = tuple; map dp; queue qu; if(st[0][0]!=st[0][1]){ dp[T(0,0,0,1)]=1; qu.emplace(0,0,0,1); } if(st[0][0]!=st[1][0]){ dp[T(0,0,1,0)]=1; qu.emplace(0,0,1,0); } int dy[]={0,0,1,-1}; int dx[]={1,-1,0,0}; auto in=[&](int y,int x){return 0<=y&&y using namespace std; #define call_from_test #include "../../string/palindromictree.cpp" #include "../../string/rollinghash.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; string s,t; cin>>s>>t; PalindromicTree p1(s),p2(t); const int MOD = 1e9+7; const int BASE1 = 1777771; const int BASE2 = 1e6+3; RollingHash rs1(s),rt1(t); RollingHash rs2(s),rt2(t); const int MAX = 5e5+100; map, int> m1[MAX]; for(int i=2;i<(int)p1.size();i++){ auto& u=p1.vs[i]; if(u.app<0) continue; auto p=make_pair(rs1.find(u.app,u.app+u.len), rs2.find(u.app,u.app+u.len)); m1[u.len][p]=u.cnt; } ll ans=0; for(int i=2;i<(int)p2.size();i++){ auto& u=p2.vs[i]; auto p=make_pair(rt1.find(u.app,u.app+u.len), rt2.find(u.app,u.app+u.len)); if(u.app<0||!m1[u.len].count(p)) continue; ans+=(ll)m1[u.len][p]*u.cnt; } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/fastfouriertransform.cpp" #include "../../convolution/arbitrarymod.cpp" #include "../../polynomial/berlekampmassey.cpp" #include "../../math/bostanmori.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; using Poly = vector; ArbitraryMod arb; auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);}; long long n; cin>>n; n--; int p,c; cin>>p>>c; const int d = 606 * 13; auto calc=[&](int l,vector vs){ int m=vs.size(); vector dp(m,Poly(d)); for(int i=0;i=0;j--){ dp[i][j]=0; if(i) dp[i][j]+=dp[i-1][j]; if(j>=vs[i]) dp[i][j]+=dp[i][j-vs[i]]; } } } return dp.back(); }; Poly cf({M(1)}); cf=conv(cf,calc(p,vector({2,3,5,7,11,13}))); cf=conv(cf,calc(c,vector({4,6,8,9,10,12}))); cf.resize(d,M(0)); Poly dp(d*3,0),as(d*3,0); dp[0]=M(1); for(int i=0;i<(int)dp.size();i++){ for(int j=0;j seq(conv); cout< using namespace std; #define call_from_test #include "../../math/totient.cpp" #include "../../mod/tetration.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int a,n,m; cin>>a>>n>>m; cout< using namespace std; #define call_from_test #include "../../convexhulltrick/convexhulltrick.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using D = double; D c,d; cin>>c>>d; vector as{{3.0/4.0,1.0/4.0}}; vector bs{{2.0/7.0,5.0/7.0}}; vector cs{{c,d}}; D ans=solve_lp_max(1000,2000,as,bs,cs); cout< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #include "../../linearalgebra/squarematrix.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; ll l; cin>>l; if(l==2){ cout<<3<; M A; A[0][0]=1;A[0][1]=1; A[1][0]=1;A[1][1]=0; if(l&1) cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../string/trie.cpp" #include "../../string/ahocorasick.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); AhoCorasick<26, false> aho('A'); string s; cin>>s; int m; cin>>m; auto cs=read(m); for(auto c:cs) aho.add(c,0); aho.build(); cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../convolution/garner.cpp" #include "../../mod/rint.cpp" #include "../../mod/factorial.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int MOD = 1e9+7; long long n; cin>>n; cout< using namespace std; #define call_from_test #include "../../math/convertbase.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); long long p; cin>>p; auto ans=convert_base(p,7LL); for(auto x:ans) cout< using namespace std; #define call_from_test #include "../../math/totient_table.cpp" #include "../../mod/mint.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; auto ts=totient_table(n/m+1); using M = Mint; M ans{0}; for(int i=2;i<=n/m;i++) ans+=M(ts[i]*2); for(int i=1;i<=n-2;i++) ans*=M(i); cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../vector/compress.cpp" #include "../../datastructure/waveletmatrix.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,k; cin>>n>>k; vector as(n); for(int i=0;i>as[i]; auto vx=compress(as); auto mx=dict(vx); BIT bit1(n),bit2(n); ll ans=1e18,sum=0; for(int i=0;i wm(as); for(int i=0;i+k<=n;i++){ int j=i+k; int x=wm.quantile(i,j,k>>1); ll p=bit1.query(0,mx[x]+1),q=k-p; ll s=bit2.query(0,mx[x]+1); chmin(ans,p*x-s+(sum-s)-q*x); bit1.add(mx[as[i]],-1); bit2.add(mx[as[i]],-as[i]); sum-=as[i]; if(j==n) continue; bit1.add(mx[as[j]],1); bit2.add(mx[as[j]],as[j]); sum+=as[j]; } cout< using namespace std; #define call_from_test #include "../../io/precision.cpp" #include "../../datastructure/rangeslide.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,k; cin>>n>>k; string s; cin>>s; vector a(n); for(int i=0;iint{ vector b(n); for(int i=0;i sm(n*2+1,0); for(int i=0;i rs(sm,cmp); for(int i=0;ism[res[i]]) return 1; return 0; }; D L=0,R=1; for(int k=0;k<20;k++){ D M=(L+R)/2; if(check(M)) L=M; else R=M; } cout< using namespace std; #define call_from_test #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector as(n),ls(n),rs(n); for(int i=0;i>as[i]; for(int i=0;i>ls[i]>>rs[i]; const ll OFS = 2e9; vector bs(n),cs(n); for(int i=0;i wm1(bs),wm2(cs); ll ans=0; for(int i=0;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../algorithm/offlineonline.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; auto as=read(n); auto xs=read(n); auto ys=read(n); auto dist= [&](int i,int j)->ll{ ll s=abs(xs[i]-as[j-1]); ll t=abs(ys[i]); return s*s+t*t; }; cout<(n,dist)< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../algorithm/offlineonline.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; auto as=read(n); auto xs=read(n); auto ys=read(n); auto dist= [&](int i,int j)->ll{ ll s=abs(xs[i]-as[j-1]); ll t=abs(ys[i]); return s+t; }; cout<(n,dist)< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/kitamasa.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; const int n = 4; vector as(n,0),cs(n,1); as[n-1]=1; Kitamasa fib(cs); int q; cin>>q; for(int i=0;i>p; cout< using namespace std; #define call_from_test #include "../../segtree/count/dynamic_offline.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,m; cin>>n>>m; vector as(n),bs(n); for(int i=0;i>as[i]>>bs[i]; RangeCount seg(m); for(int i=0;ibs[i]) swap(as[i],bs[i]); seg.preupdate(as[i],bs[i]); } seg.build(); long long ans=0; for(int i=0;i using namespace std; #define call_from_test #include "../../tree/rerooting.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; auto fold=[](int a,int b){return max(a,0)+max(b,0);}; auto lift=[](int a,int d){return d-a;}; ReRooting G(n,fold,lift,0); for(int i=1;i>a>>b; a--;b--; G.add_edge(a,b,1); } auto res=G.build(); vector ans; for(int i=0;i0) ans.emplace_back(i); cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../algorithm/offlineonline.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; auto as=read(n); auto xs=read(n); auto ys=read(n); auto dist= [&](int i,int j)->ll{ ll s=abs(xs[i]-as[j-1]); ll t=abs(ys[i]); return s*s*s+t*t*t; }; cout<(n,dist)< using namespace std; #define call_from_test #include "../../tools/bigint.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test using ll = long long; const int MAX = 1e5+100; ll dp[MAX]; pair dfs(int l,int r){ if(l+1>=r) return make_pair(bigint(dp[l]),bigint(l+1)); int m=(l+r)>>1; auto v=dfs(l,m); auto t=dfs(m,r); t.first*=v.second; t.first+=v.first; t.second*=v.second; return t; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector ps(n); for(int i=0;i>ps[i]; BIT bit(n); for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector xs(n); for(int i=0;i>xs[i],xs[i]--; WaveletMatrix wm(xs); int ans=n*(n-1); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/sum_of_geometric_sequence.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; long long n; cin>>n; cout< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #include "../../toptree/distancesum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; using ll = long long; const size_t N = 1e5; using Cluster = DistanceSum; TopTree G; vector xs(n,1); vector vs(n); for(int i=0;i>t; if(t==1){ int a,b,c; cin>>a>>b>>c; a--;b--; a+=pre;a%=n; b+=pre;b%=n; G.link(vs[a],c,vs[b]); } if(t==2){ int a,b; cin>>a>>b; a--;b--; a+=pre;a%=n; b+=pre;b%=n; G.cut(vs[a],vs[b]); } if(t==3){ int a; cin>>a; a--; a+=pre;a%=n; xs[a]^=1; G.set_vertex(vs[a],xs[a]); auto cc=centroid(G,vs[a]); ll res=G.get_subtree(cc).ans; cout< using namespace std; #define call_from_test #include "../../datastructure/absolutesum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector ys(n); for(int i=0;i>ys[i]; sort(ys.begin(),ys.end()); if(ys.front()==ys.back()){ cout<<1< as; vector dp(n,0); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/fastfouriertransform.cpp" #include "../../convolution/arbitrarymod.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int k,n; cin>>k>>n; vector xs(n); for(int i=0;i>xs[i]; using M = Mint; ArbitraryMod arb; auto conv=[&](auto as,auto bs){return arb.multiply(as,bs);}; FormalPowerSeries FPS(conv); const int sz=1<<17; vector bs(sz,M(0)); bs[0]=1; for(int x:xs) bs[x]-=M(1); cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../combinatorics/surjection.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; using M = Mint; cout<(n,m)< using namespace std; #define call_from_test #include "../../vector/reversed.cpp" #include "../../mod/mint.cpp" #include "../../polynomial/berlekampmassey.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using M = Mint; int p; cin>>p; const int n = 100; vector as(n); as[0]=M(0); as[1]=M(0); as[2]=M(1); for(int i=3;i bs(n,M(0)); for(int s=0;s dp(MAX,0); for(int i=0;i>q; for(int i=0;i>k; cout< using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../datastructure/waveletmatrix.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector as(n); for(int i=0;i>as[i]; const int OFS = 1e9; for(int &a:as) a+=OFS; WaveletMatrix wm(as); ll ans=0; for(ll k=1;k<=n;k++){ int p=(k-1)/2; vector ls,rs; for(int i=0;i+k<=n;i+=k) ls.emplace_back((wm.rquantile(i,i+k,p)-OFS)*k); for(int i=n;i-k>=0;i-=k) rs.emplace_back((wm.rquantile(i-k,i,p)-OFS)*k); int sz=ls.size(); vector dp(sz+1,0),pd(sz+1,0); for(ll i=0,sum=0;i0;i--){ sum+=rs[sz-i]; chmax(pd[i-1],pd[i]); chmax(pd[i-1],sum); } for(int i=0;i<=sz;i++) chmax(ans,dp[i]+pd[i]); } cout< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/divisor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const int MAX = 3e6+100; using M = Mint; vector ys(MAX,0),xs(MAX,0); int h,w; cin>>h>>w; for(int i=1;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../segtree/basic/ushi.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; auto as=read(n); auto f=[](int a,int b){return min(a,b);}; SegmentTree seg(f,n+1); seg.build(as); for(int i=0;i>t>>l>>r; if(t==1){ l--;r--; swap(as[l],as[r]); seg.set_val(l,as[l]); seg.set_val(r,as[r]); } if(t==2){ l--; int m=seg.query(l,r); auto check=[&](int x){return x>m;}; cout< using namespace std; #define call_from_test #include "../../io/yesno.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int a,b; cin>>a>>b; cout< using namespace std; #define call_from_test #include "../../tree/levelancestor.cpp" #include "../../tree/eulertourforbfs.cpp" #include "../../segtree/basic/lazy.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; EulerTourForBFS G(n); for(int i=1;i>u>>v; G.add_edge(u,v); } G.build(); vector as(n); for(int i=0;i>as[i]; using ll = long long; auto f=[&](ll a,ll b){return a+b;}; auto g=[&](ll a,ll b){return a*b;}; SegmentTree seg(f,g,g,0,1); vector vs(n); for(int i=0;i>q; for(int i=0;i>x; ll sum=0; auto apply= [&](int l,int r){ sum+=seg.query(l,r); seg.update(l,r,0); }; int p=G.par[0][x]; if(~p){ int pp=G.par[0][p]; if(~pp) G.exec(pp,0,apply); G.exec(p,0,apply); G.exec(p,1,apply); } G.exec(x,0,apply); G.exec(x,1,apply); G.exec(x,2,apply); seg.set_val(G.idx(x),sum); cout< using namespace std; #define call_from_test #include "../../tree/lowestcommonancestor.cpp" #include "../../tree/auxiliarytree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; AuxiliaryTree G(n); vector> ws(n); for(int i=1;i>u>>v>>w; G.add_edge(u,v); ws[u][v]=ws[v][u]=w; } G.build(); using ll = long long; vector dep(n,-1); queue que; dep[0]=0; que.emplace(0); while(!que.empty()){ int v=que.front();que.pop(); for(int u:G.G[v]){ if(~dep[u]) continue; dep[u]=dep[v]+ws[v][u]; que.emplace(u); } } int q; cin>>q; for(int i=0;i>k; vector vs(k); for(int j=0;j>vs[j]; G.query(vs); ll ans=0; for(int v:vs) for(int u:G.T[v]) ans+=max(dep[u]-dep[v],0LL); cout< using namespace std; #define call_from_test #include "../../toptree/toptree.cpp" #include "../../toptree/steiner.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; const size_t N = 1e5; using Cluster = SteinerTree; TopTree G; int n; cin>>n; vector vs(n); for(int i=0;i>u>>v>>w; G.link(vs[u],Cluster(w),vs[v]); } int q; cin>>q; for(int i=0;i>t; if(t==1){ int u,v,w,x; cin>>u>>v>>w>>x; G.cut(vs[u],vs[v]); G.link(vs[v],Cluster(x),vs[w]); } if(t==2){ int k; cin>>k; vector xs(k); for(int j=0;j>xs[j]; for(int x:xs) G.set_vertex(vs[x],Vertex(1)); cout< using namespace std; #define call_from_test #include "../../datastructure/weightedunionfind.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; WeightedUnionFind uf(n); vector vs(n,0); auto add=[&](int a,int b){ vs[uf.find(a)]+=b; }; auto query=[&](int a){ int r=uf.find(a); return uf.diff(a,r)+vs[r]; }; auto unite=[&](int a,int b){ a=uf.find(a); b=uf.find(b); if(a==b) return; int x=query(a); int y=query(b); uf.unite(a,b,x-y); }; for(int i=0;i>t>>a>>b; if(t==1){ a--;b--; unite(a,b); } if(t==2){ a--; add(a,b); } if(t==3){ a--; cout< using namespace std; #define call_from_test #include "../../tree/centroid.cpp" #include "../../tools/fixpoint.cpp" #include "../../tools/chminmax.cpp" #include "../../segtree/basic/dual.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; Centroid G(n); for(int i=1;i>a>>b; a--;b--; G.add_edge(a,b); } vector xs(q),ys(q),zs(q); for(int i=0;i>xs[i]>>ys[i]>>zs[i]; vector> H(n); for(int i=0;i dep(n); using ll = long long; vector ans(q,0); auto h=[&](ll a,ll b){return a+b;}; SegmentTree seg(h,0); seg.init(n*2); queue que; que.emplace(G.build(0)[0]); while(!que.empty()){ int r=que.front();que.pop(); dep[r]=0; // add for all { int len=1; vector qs(H[r]); for(int t:G[r]){ if(!G.alive(t)) continue; MFP([&](auto dfs,int v,int p,int d)->void{ dep[v]=d; chmax(len,d+1); for(int i:H[v]) qs.emplace_back(i); for(int u:G[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v,d+1); } })(t,r,1); } seg.init(len); sort(qs.begin(),qs.end()); for(int i:qs){ ans[i]+=seg.get_val(dep[xs[i]]); if(ys[i]>=dep[xs[i]]) seg.update(0,min(len,ys[i]-dep[xs[i]]+1),zs[i]); } } // sub for subtree { for(int t:G[r]){ if(!G.alive(t)) continue; int len=1; vector qs; MFP([&](auto dfs,int v,int p,int d)->void{ dep[v]=d; chmax(len,d+1); for(int i:H[v]) qs.emplace_back(i); for(int u:G[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v,d+1); } })(t,r,1); seg.init(len); sort(qs.begin(),qs.end()); for(int i:qs){ ans[i]-=seg.get_val(dep[xs[i]]); if(ys[i]>=dep[xs[i]]) seg.update(0,min(len,ys[i]-dep[xs[i]]+1),zs[i]); } } } G.disable(r); for(int t:G[r]) if(G.alive(t)) que.emplace(G.build(t)[0]); } for(auto a:ans) cout< using namespace std; #define call_from_test #include "../../tree/centroid.cpp" #include "../../tools/fixpoint.cpp" #include "../../vector/compress.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,k; cin>>n>>k; using P = pair; vector< map > col(n); Centroid G(n); for(int i=1;i>x>>y>>z; x--;y--;z--; G.add_edge(x,y); col[x][y]=z; col[y][x]=z; } queue que; que.emplace(G.build(0)[0]); ll ans=0; vector cnt(k,0),uku(k,0); vector

ps(n),vp(n); while(!que.empty()){ int r=que.front();que.pop(); auto calc= [&](P p,int q)->P{ assert(~p.first); if(p.first==q||p.second==q) return p; if(p.second==-1) return minmax({p.first,q}); return P(-1,-1); }; vp.clear(); for(int t:G[r]){ if(!G.alive(t)) continue; MFP([&](auto dfs,int v,int p,P st)->void{ ps[v]=st; if(st.first<0) return; for(int u:G[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v,calc(st,col[u][v])); } if(st.second!=-1) vp.emplace_back(st); })(t,r,P(col[r][t],-1)); } vp=compress(vp); auto idx=[&](P p){return lower_bound(vp.begin(),vp.end(),p)-vp.begin();}; vector num(vp.size()); int all=0; for(int t:G[r]){ if(!G.alive(t)) continue; // count MFP([&](auto dfs,int v,int p)->void{ P st=ps[v]; if(st.first<0) return; for(int u:G[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v); } if(st.second==-1){ ans+=all-cnt[st.first]; ans+=uku[st.first]; }else{ ans+=1; ans+=cnt[st.first]; ans+=cnt[st.second]; ans+=num[idx(st)]; } })(t,r); // paint MFP([&](auto dfs,int v,int p)->void{ P st=ps[v]; if(st.first<0) return; for(int u:G[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v); } if(st.second==-1){ cnt[st.first]++; all++; }else{ num[idx(st)]++; uku[st.first]++; uku[st.second]++; } })(t,r); } for(int t:G[r]){ if(!G.alive(t)) continue; // clear MFP([&](auto dfs,int v,int p)->void{ P st=ps[v]; if(st.first<0) return; for(int u:G[v]){ if(u==p) continue; if(!G.alive(u)) continue; dfs(u,v); } if(st.second==-1){ cnt[st.first]--; }else{ uku[st.first]--; uku[st.second]--; } })(t,r); } G.disable(r); for(int u:G[r]) if(G.alive(u)) que.emplace(G.build(u)[0]); } cout< using namespace std; #define call_from_test #include "../../datastructure/disjointsparsetable.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n; cin>>n; vector as(n); for(int i=0;i>as[i]; auto f=[&](ll a,ll b){return gcd(a,b);}; DisjointSparseTable dst(f); dst.build(as); ll ans=0; for(int l=0,r=0;l1) r++; ans+=n-r+1; } cout< using namespace std; #define call_from_test #include "../../io/yesno.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); long long l,r,m,k; cin>>l>>r>>m>>k; long long x=l*k,y=r*k; cout< using namespace std; const int MAX = 1e5; const int MOD = 1e9+7; using uint = unsigned int; inline uint add_mod(uint a, uint b) { return (a += b) >= MOD ? a - MOD : a; } uint mul(uint x,uint y){ return 1ULL*x*y%MOD; } uint xs[MAX]={}; uint as[MAX]={}; uint cs[MAX]={}; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int k,n,m; cin>>k>>n>>m; for(int i=0;i>as[i]; for(int i=0;i>cs[i]; for(int i=k;i>l>>r; for(int k=l;k using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../polynomial/recursivesequence.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int k,n,m; cin>>k>>n>>m; using M = Mint; vector as(k),cs(k); for(int i=0;i>as[i].v; for(int i=0;i>cs[i].v; RecursiveSequence rs(n); for(int i=0;i>l>>r; rs.query(l,r); } auto ss=rs.build(as,cs); for(int i=0;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../graph/rangetorange.cpp" #include "../../graph/stronglyconnectedcomponent.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,a,b; cin>>n>>a>>b; auto xs=read(n); RangeToRange G(n); SCC scc(G.size()+n+n); auto f=[&](int u,int v){scc.add_edge(u,v);}; G.init(f); for(int i=0;i cnt; for(int i=0;i using namespace std; #define call_from_test #include "../../mod/pow.cpp" #include "../../mod/order.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int T; cin>>T; while(T--){ long long n; cin>>n; cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../mod/rint.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int p,n; cin>>p>>n; auto as=read(n); string s; cin>>s; using R = Rint; R::set_mod(p); R ans(as[0]); for(int i=1;i using namespace std; #define call_from_test #include "../../tools/chminmax.cpp" #include "../../toptree/toptree.cpp" #undef call_from_test struct Vertex{ void* handle; Vertex():handle(nullptr){} }; using ll = long long; const ll INF = 1e9 + 10; struct Cluster{ ll len; ll lft,rgh,mid,ans; Cluster(ll len=INF):len(len),lft(len),rgh(len),mid(INF),ans(INF){} void toggle(){ swap(lft,rgh); } static Cluster compress(Cluster x,Vertex *,Cluster y){ Cluster nxt(x.len+y.len); nxt.lft=y.lft; nxt.rgh=x.rgh; nxt.ans=min({x.ans,y.ans,x.mid}); return nxt; } static Cluster rake(Cluster x,Cluster y){ x.mid=min({x.mid,y.mid,y.lft}); return x; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; const size_t N = 1e5; TopTree T; int n; cin>>n; vector vs(n); for(int i=0;i>u>>v>>w; u--;v--; T.link(vs[u],Cluster(w),vs[v]); } int q; cin>>q; for(int i=0;i>x>>y; x--;y--; auto res=T.get_path(vs[x],vs[y]); ll ans=res.ans; chmin(ans,T.get_subtree(vs[x],vs[y]).lft); chmin(ans,T.get_subtree(vs[x],vs[y]).mid); chmin(ans,T.get_subtree(vs[y],vs[x]).lft); chmin(ans,T.get_subtree(vs[y],vs[x]).mid); if(ans==INF) cout<<-1< using namespace std; #define call_from_test #include "../../vector/near.cpp" #include "../../vector/compress.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n; cin>>n; vector xs(n),rs(n); for(int i=0;i>xs[i]>>rs[i]; xs=mul(xs,2); rs=mul(rs,2); auto vs=compress(near(near(xs,0,rs,mul(rs,-1)),-1,0,1)); auto dc=dict(vs); vector sm(vs.size(),0); for(int i=0;i using namespace std; #define call_from_test #include "../../datastructure/binaryindexedtree.cpp" #include "../../io/tuple.cpp" #include "../../tools/fixpoint.cpp" #include "../../tree/lowestcommonancestor.cpp" #include "../../tree/auxiliarytree.cpp" #include "../../vector/compress.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; using P = pair; int n,q; cin>>n>>q; vector> G(n+1); AuxiliaryTree H(n+1); for(int i=1;i>a>>b>>c; G[a].emplace_back(b,c); G[b].emplace_back(a,c); H.add_edge(a,b); } // add 0 for root H.add_edge(0,1); H.build(0); const ll INF = 1e15; G[0].emplace_back(1,INF); vector dep(n+1); MFP([&](auto dfs,int v,int p,ll d)->void{ dep[v]=d; for(auto [u,c]:G[v]) if(u!=p) dfs(u,v,d+c); })(0,-1,0); auto [type,vs,ts,ls]=read_tuple(q); // vanish vertices vector rs(q); for(int i=0;i=0;k--){ int p=H.par[k][r]; if(~p and d<=dep[p]) r=p; } rs[i]=H.par[0][r]; } vector pos; for(int i=0;i bit(pos.size()); vector cs(q); for(int i=0;i que; que.emplace(0,q); vector ans(q); vector> add(n+1),sub(n+1),query(n+1); while(!que.empty()){ auto [L,R]=que.front();que.pop(); if(L+1==R) continue; int M=(L+R)>>1; vector ss; for(int i=L;ivoid{ for(int i:query[v]) ans[i]-=bit.query(0,cs[i]+1); for(int u:H.T[v]) if(u!=p) dfs(u,v); expand(v); for(int i:query[v]) ans[i]+=bit.query(0,cs[i]+1); })(0,-1); H.clear(ss); for(int i=L;i using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../toptree/toptree.cpp" #include "../../toptree/distancesum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; const char newl = '\n'; int n,m,q; cin>>n>>m>>q; auto cs=read(m); vector cnt(n,0); for(int &c:cs) cnt[--c]++; constexpr size_t N = 1e5; using Cluster = DistanceSum; TopTree G; vector vs(n); for(int i=0;i>a>>b; a--;b--; G.link(vs[a],1,vs[b]); } int flg=0; for(int i=0;i>t; if(t==1){ int p,d; cin>>p>>d; p--;d--; G.set_vertex(vs[cs[p]],--cnt[cs[p]]); cs[p]=d; G.set_vertex(vs[cs[p]],++cnt[cs[p]]); } if(t==2){ int e; cin>>e; e--; cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../vector/runlength.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; auto as=read(n); auto bs=read(n); vector cs(n); for(int i=0;i using namespace std; #define call_from_test #include "../../io/tuple.cpp" #include "../../tools/chminmax.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; auto [as, bs]=read_tuple(m); vector G(n,vector(n,n)); for(int i=0;i using namespace std; #define call_from_test #include "../../math/fraction.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s,t; cin>>s>>t; int a=(s[0]-'0')*10+(s[1]-'0'); int b=(t[0]-'0')*10+(t[1]-'0'); using F = fraction; F c(a*60+b,1); F d(720,11); F x(0,1); while(x using namespace std; #define call_from_test #include "../../math/quotients.cpp" #include "../../mod/mint.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; ll n; cin>>n; using M = Mint; M ans{0}; for(auto[l,r]:quotients(n)){ if(l==1) continue; ll d=n/l; if(d using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../convolution/bitwise/fwht.cpp" #include "../../convolution/bitwise/or.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; vector as(1<>a; int sum=0; for(int a:as) sum+=a; using M = Mint; vector dp(1< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../vector/fusion.cpp" #include "../../vector/compress.cpp" #include "../../datastructure/slope.cpp" #undef call_from_test #ifdef SANITIZE #define IGNORE #endif signed main(){ cin.tie(0); ios::sync_with_stdio(0); int m,n; cin>>m>>n; auto as=read(m); auto bs=read(n); auto cs=compress(fusion(as,bs)); auto dc=dict(cs); for(int &a:as) a=dc[a]; for(int &b:bs) b=dc[b]; const int sz = cs.size(); vector num(sz,0); for(int a:as) num[a]--; using ll = long long; for(int k=1;k<=m;k++){ for(int b:bs) num[b]++; int pos=0; Slope S; S.add_a_minus_x(pos,1e9); for(int i=0;i using namespace std; #define call_from_test #include "../../algorithm/mo.cpp" #include "../../segtree/basic/lazy.cpp" #include "../../datastructure/binaryindexedtree.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; int n,q; cin>>n>>q; vector as(n); for(int i=0;i>as[i]; auto f=[&](int a,int b){return min(a,b);}; auto g=[&](int a,int b){return a+b;}; int ti(1e9),ei(0); SegmentTree seg(f,g,g,ti,ei); seg.build(vector(n+2,0)); BIT bitL(n+2),bitR(n+2); using ll = long long; ll res=0; auto expandL=[&](int i){ res-=bitL.query(as[i]+1,n+2); res-=bitR.query(0,as[i]); bitL.add(as[i],-1); seg.update(0,as[i],-1); }; auto expandR=[&](int i){ res-=bitL.query(as[i]+1,n+2); res-=bitR.query(0,as[i]); bitR.add(as[i],-1); seg.update(as[i]+1,n+2,-1); }; auto shrinkL=[&](int i){ res+=bitL.query(as[i]+1,n+2); res+=bitR.query(0,as[i]); bitL.add(as[i],+1); seg.update(0,as[i],+1); }; auto shrinkR=[&](int i){ res+=bitL.query(as[i]+1,n+2); res+=bitR.query(0,as[i]); bitR.add(as[i],+1); seg.update(as[i]+1,n+2,+1); }; for(int i=n-1;i>=0;i--){ res+=bitR.query(0,as[i]); bitR.add(as[i],+1); seg.update(as[i]+1,n+2,+1); } Mo mo(n,200,expandL,expandR,shrinkL,shrinkR); vector ls,rs; for(int i=0;i>l>>r; l--; ls.emplace_back(l); rs.emplace_back(r); mo.add(l,r); } mo.build(); vector ans(q,0); for(int i=0;i using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../vector/powers.cpp" #include "../../convolution/numbertheoretictransform.cpp" #include "../../combinatorics/enumeration.cpp" #include "../../formalpowerseries/base.cpp" #include "../../formalpowerseries/inv.cpp" #include "../../formalpowerseries/diff.cpp" #include "../../formalpowerseries/integral.cpp" #include "../../formalpowerseries/log.cpp" #include "../../formalpowerseries/exp.cpp" #include "../../formalpowerseries/pow.cpp" #include "../../formalpowerseries/998244353.cpp" #undef call_from_test //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m,k; cin>>n>>m>>k; using namespace fps_998244353; E::init(n+m); auto ps=FPS.exp({M(0),M(1)},n+1); ps[0]-=M(1); auto qs=FPS.pow(ps,k,n+1); auto po=powers(n,M(m)); M ans{0}; for(int l=k;l<=n;l++) ans+=E::C(m,k)*E::C(n,l)*E::Fact(l)*qs[l]*po[n-l]; cout< using namespace std; #define call_from_test #include "../../io/single.cpp" #include "../../graph/grid.cpp" #include "../../graph/dijkstra.cpp" #undef call_from_test signed main(){ using ll = long long; cin.tie(0); ios::sync_with_stdio(0); int h,w; cin>>h>>w; ll u,d,r,l,k,p; cin>>u>>d>>r>>l>>k>>p; int ys,xs,yt,xt; cin>>ys>>xs>>yt>>xt; ys--;xs--;yt--;xt--; auto C=read(h); map cost; cost[-w]=u; cost[+w]=d; cost[+1]=r; cost[-1]=l; Grid G(h,w,[&](int y,int x){return C[y][x];}); Dijkstra D(h*w); for(auto[a,b]:G.edges()){ if(G[a]=='#' or G[b]=='#') continue; D.add_edge(a,b,cost[b-a]+p*(G[b]=='@')); D.add_edge(b,a,cost[a-b]+p*(G[a]=='@')); } D.build(G.idx(ys,xs)); cout<<(D[G.idx(yt,xt)]<=k?"Yes":"No")< using namespace std; #define call_from_test #include "../../mod/mint.cpp" #include "../../math/moebius.cpp" #include "../../convolution/divisor.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; using M = Mint; vector emp(n+1,0),way(n+1,0); M cnt{0}; M all{0}; auto sign=moebius(n); using ll = long long; for(int i=1;i<=n;i++){ emp[i]=M((ll)sign[i])*M(1).pow(n/i); way[i]=M((ll)sign[i])*M(2).pow(n/i); cnt+=emp[i]; all+=way[i]; } LCMConvolution::zeta(way); LCMConvolution::zeta(emp); vector dp0(n+1,0),dp1(n+1,0),dp2(n+1,0); for(int i=1;i<=n;i++){ dp0[i]=emp[i]*emp[i]; dp1[i]=emp[i]*way[i]; dp2[i]=way[i]*way[i]; } LCMConvolution::moebius(dp0); LCMConvolution::moebius(dp1); LCMConvolution::moebius(dp2); M ans=(all-cnt)*(all-cnt); M cof=M(3)/M(4); for(int i=1;i<=n;i++){ ans+=dp0[i]; ans-=dp1[i]*M(2); ans+=dp2[i]*cof.pow(n/i); ans-=dp0[i]; ans+=dp1[i]*M(2); ans-=dp2[i]; } cout< using namespace std; #define call_from_test #include "../../datastructure/unionfind.cpp" #include "../../toptree/toptree.cpp" #include "../../toptree/farthest.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; const char newl = '\n'; const size_t N = 2e5+10; using Cluster = Farthest; TopTree G; int n; ll x; int q; cin>>n>>x>>q; vector vs(n); for(int i=0;i>k; if(k==1){ int v; ll w; cin>>v>>w; G.link(vs[v],Cluster(w,v,x),vs[x]); uf.unite(v,x); } if(k==2){ int u,v; cin>>u>>v; if(uf.same(u,v)){ ll len=(u==v?0:G.get_path(vs[u],vs[v]).len); cout<>v; auto p=G.get_subtree(vs[v]).md; if(p.dist==0){ cout<<0<>value; x+=value; x%=n; } } return 0; } ================================================ FILE: tools/all_permutations.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template void all_permutations(int n,F f){ vector vs(n); iota(vs.begin(),vs.end(),0); do f(vs); while(next_permutation(vs.begin(),vs.end())); } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tools/avx2.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif // https://beet-aizu.hatenablog.com/entry/2020/09/04/173522 //BEGIN CUT HERE #pragma GCC optimize ("O3") #pragma GCC target ("avx2") // or sse4 #pragma GCC optimize("unroll-loops") //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tools/bigint.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../convolution/fastfouriertransform.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct bigint { using ll = long long; using vll = vector; inline static constexpr ll base_digits = 9; inline static constexpr ll base = 1000000000; vll a; ll sign; bigint():sign(1){} bigint(ll v){*this=v;} bigint(const string &s){read(s);} static bigint add_identity(){return bigint(0);} static bigint mul_identity(){return bigint(1);} void operator=(ll v){ sign=1; if(v<0) sign=-1,v=-v; for(;v>0;v=v/base) a.emplace_back(v%base); } bigint operator+(const bigint &v) const{ if(sign==v.sign){ bigint res=v; for(ll i=0,carry=0;i<(ll)max(a.size(),v.a.size()) or carry;++i){ if(i==(ll)res.a.size()) res.a.emplace_back(0); res.a[i]+=carry+(i<(ll)a.size()?a[i]:0); carry=res.a[i]>=base; if(carry) res.a[i]-=base; } return res; } return *this-(-v); } bigint operator-(const bigint &v) const{ if(sign==v.sign){ if(abs()>=v.abs()){ bigint res=*this; for(ll i=0,carry=0;i<(ll)v.a.size() or carry;++i){ res.a[i]-=carry+(i<(ll)v.a.size()?v.a[i]:0); carry=res.a[i]<0; if(carry) res.a[i]+=base; } res.trim(); return res; } return -(v-*this); } return *this+(-v); } void operator*=(ll v){ if(v<0) sign=-sign,v=-v; for(ll i=0,carry=0;i<(ll)a.size() or carry;++i){ if(i ==(ll)a.size()) a.emplace_back(0); ll cur=a[i] *(ll)v+carry; carry=(ll)(cur/base); a[i]=(ll)(cur%base); // asm("divl %%ecx" : "=a"(carry),"=d"(a[i]) : "A"(cur),"c"(base)); } trim(); } bigint operator*(ll v) const{ bigint res=*this; res*=v; return res; } friend pair divmod(const bigint &a1,const bigint &b1){ ll norm=base/(b1.a.back()+1); bigint a=a1.abs()*norm; bigint b=b1.abs()*norm; bigint q,r; q.a.resize(a.a.size()); for(ll i=a.a.size()-1;i>=0;i--){ r *=base; r+=a.a[i]; ll s1=r.a.size()<=b.a.size() ? 0 : r.a[b.a.size()]; ll s2=r.a.size()<=b.a.size()-1 ? 0 : r.a[b.a.size()-1]; ll d=((ll)base*s1+s2)/b.a.back(); r-=b*d; while(r<0) r+=b,--d; q.a[i]=d; } q.sign=a1.sign*b1.sign; r.sign=a1.sign; q.trim(); r.trim(); return make_pair(q,r/norm); } bigint operator/(const bigint &v) const{ return divmod(*this,v).first; } bigint operator%(const bigint &v) const{ return divmod(*this,v).second; } void operator/=(ll v){ if(v<0) sign=-sign,v=-v; for(ll i=(ll)a.size()-1,rem=0;i>=0;--i){ ll cur=a[i]+rem *(ll)base; a[i]=(ll)(cur/v); rem=(ll)(cur%v); } trim(); } bigint operator/(ll v) const{ bigint res=*this; res/=v; return res; } ll operator%(ll v) const{ if(v<0) v=-v; ll m=0; for(ll i=a.size()-1;i>=0;--i) m=(a[i]+m*(ll)base)%v; return m*sign; } void operator+=(const bigint &v){ *this=*this+v; } void operator-=(const bigint &v){ *this=*this-v; } void operator*=(const bigint &v){ *this=*this*v; } void operator/=(const bigint &v){ *this=*this/v; } bool operator<(const bigint &v) const{ if(sign!=v.sign) return sign=0;i--) if(a[i]!=v.a[i]) return a[i]*sign(const bigint &v) const{ return v<*this; } bool operator<=(const bigint &v) const{ return !(v<*this); } bool operator>=(const bigint &v) const{ return !(*this=0;i--) res=res*base+a[i]; return res*sign; } friend bigint gcd(const bigint &a,const bigint &b){ return b.isZero()?a:gcd(b,a%b); } friend bigint lcm(const bigint &a,const bigint &b){ return a/gcd(a,b)*b; } void read(const string &s){ sign=1; a.clear(); ll pos=0; while(pos<(ll)s.size() and (s[pos]=='-' or s[pos]=='+')){ if(s[pos]=='-') sign=-sign; ++pos; } for(ll i=s.size()-1;i>=pos;i-=base_digits){ ll x=0; for(ll j=max(pos,i-base_digits+1);j<=i;j++) x=x*10+s[j]-'0'; a.emplace_back(x); } trim(); } friend istream &operator>>(istream &stream,bigint &v){ string s; stream>>s; v.read(s); return stream; } friend ostream &operator<<(ostream &stream,const bigint &v){ if(v.sign==-1) stream<<'-'; stream<<(v.a.empty()?0:v.a.back()); for(ll i=(ll)v.a.size()-2;i>=0;--i) stream<=new_digits){ res.emplace_back(signed(cur%p[new_digits])); cur/=p[new_digits]; cur_digits-=new_digits; } } res.emplace_back((signed)cur); while(!res.empty() and !res.back()) res.pop_back(); return res; } static vll karatsubaMultiply(vll &a,vll &b){ { while(a.size()>1; vll a1(a.begin(),a.begin()+k); vll a2(a.begin()+k,a.end()); vll b1(b.begin(),b.begin()+k); vll b2(b.begin()+k,b.end()); vll a1b1=karatsubaMultiply(a1,b1); vll a2b2=karatsubaMultiply(a2,b2); for(ll i=0;ia,base_digits,nbase_digits); vll b=convert_base(v.a,base_digits,nbase_digits); if(a.empty() or b.empty()) return bigint(0); vll c=karatsubaMultiply(a,b); // vll c=FFT::multiply(a,b); bigint res; res.sign=sign*v.sign; for(ll i=0,carry=0;i<(ll)c.size();i++){ ll cur=c[i]+carry; res.a.emplace_back((ll)(cur%nbase)); carry=(ll)(cur/nbase); if(i+1==(int)c.size() and carry>0) c.emplace_back(0); } res.a=convert_base(res.a,nbase_digits,base_digits); res.trim(); return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tools/cc_hash.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct cc_hash{ uint64_t operator()(T x) const{ uint64_t y(x); y += 0x9e3779b97f4a7c15; y = (y ^ (y >> 30)) * 0xbf58476d1ce4e5b9; y = (y ^ (y >> 27)) * 0x94d049bb133111eb; return y ^ (y >> 31); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tools/chminmax.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a using namespace std; #define IGNORE //BEGIN CUT HERE const int DEBUG = 1; template void debug(Ts... ts){ if(!DEBUG) return; cout<<"#:"; auto print=[](auto v){cout<{(void(print(ts)),0)...}; cout< using namespace std; #endif //BEGIN CUT HERE template struct DefaultDict : map{ using super = map; const T val; DefaultDict(T val_):val(val_){} T& operator[](const Key& key){ if(!super::count(key)) super::operator[](key)=val; return super::operator[](key); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tools/dice.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct Die{ array fs; int &top() {return fs[0];} int &south() {return fs[1];} int &east() {return fs[2];} int &west() {return fs[3];} int &north() {return fs[4];} int &bottom(){return fs[5];} void roll(char c){ //the view from above // N //W E // S string b("EWNSRL"); int v[6][4]={{0,3,5,2}, {0,2,5,3}, {0,1,5,4}, {0,4,5,1}, {1,2,4,3}, {1,3,4,2}}; for(int k=0;k<6;k++){ if(b[k]!=c) continue; int t=fs[v[k][0]]; fs[v[k][0]]=fs[v[k][1]]; fs[v[k][1]]=fs[v[k][2]]; fs[v[k][2]]=fs[v[k][3]]; fs[v[k][3]]=t; } } using ll = long long; ll hash(){ ll res=0; for(int i=0;i<6;i++) res=res*256+fs[i]; return res; } bool operator==(const Die &d) const{ for(int i=0;i<6;i++) if(fs[i]!=d.fs[i]) return 0; return 1; } }; template vector> makeDice(Die d){ vector> res; for(int i=0;i<6;i++){ Die t(d); if(i==1) t.roll('N'); if(i==2) t.roll('S'); if(i==3) t.roll('S'),t.roll('S'); if(i==4) t.roll('L'); if(i==5) t.roll('R'); for(int k=0;k<4;k++){ res.emplace_back(t); t.roll('E'); } } return res; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tools/drop.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template void drop(const T &x){cout< using namespace std; #endif //BEGIN CUT HERE struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tools/fixpoint.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct FixPoint : F{ FixPoint(F&& f):F(forward(f)){} template decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward(args)...); } }; template inline decltype(auto) MFP(F&& f){ return FixPoint{forward(f)}; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tools/gridbfs.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE vector< vector > gridbfs(vector &st,int sy,int sx,char wall,int dir){ int h=st.size(),w=st.front().size(); vector > dp(h,vector(w,-1)); using P = pair; queue

qu; dp[sy][sx]=0; qu.emplace(sy,sx); int dy[]={1,-1,0,0,1,1,-1,-1}; int dx[]={0,0,1,-1,1,-1,1,-1}; auto in=[&](int y,int x){return 0<=y and y using namespace std; /* multiprecision: #include using ll = boost::multiprecision::cpp_int; */ #endif //BEGIN CUT HERE __int128_t abs128(__int128_t val){return val<0?-val:val;} ostream &operator<<(ostream &os,__int128_t val){ if(ostream::sentry(os)){ __uint128_t tmp=abs128(val); char buf[64]; char *d=end(buf); do{ --d; *d=char(tmp%10+'0'); tmp/=10; }while(tmp); if(val<0) *--d='-'; int len=end(buf)-d; if(os.rdbuf()->sputn(d,len)!=len){ os.setstate(ios_base::badbit); } } return os; } istream &operator>>(istream &is,__int128_t &val){ string s; is>>s; val=0; for(int i=0;i<(int)s.size();i++) if(isdigit(s[i])) val=val*10+s[i]-'0'; if(s[0]=='-') val*=-1; return is; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tools/iskado.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template bool is_kado(T a,T b,T c){ if(a==b or b==c or c==a) return 0; if(ac) return 1; if(a>b and b using namespace std; #endif //BEGIN CUT HERE template struct trio{ T first; U second; V third; trio(T first,U second,V third): first(first),second(second),third(third){} operator tuple(){ return forward_as_tuple(first,second,third); } using X = tuple; operator X() const{return make_tuple(first,second,third);} bool operator==(const trio&a) const{return (X)(*this)==(X)a;} bool operator!=(const trio&a) const{return (X)(*this)!=(X)a;} bool operator< (const trio&a) const{return (X)(*this)< (X)a;} bool operator<=(const trio&a) const{return (X)(*this)<=(X)a;} bool operator> (const trio&a) const{return (X)(*this)> (X)a;} bool operator>=(const trio&a) const{return (X)(*this)>=(X)a;} }; template trio make_trio(T first,U second,V third){ return trio(first,second,third); } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: toptree/base.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct Vertex{ void* handle; Vertex():handle(nullptr){} }; struct Cluster{ Cluster(){} void toggle(){} static Cluster compress(Cluster x,Vertex *v,Cluster y){} static Cluster rake(Cluster x,Cluster y){} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: toptree/distancesum.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "toptree.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct Vertex{ void* handle; // 0: dead, 1: alive int color; Vertex(int color=0):handle(nullptr),color(color){} }; template struct DistanceSum{ struct pi{ T cnt; Vertex* ptr; pi():cnt(-1),ptr(nullptr){} pi(T cnt,Vertex* ptr):cnt(cnt),ptr(ptr){} bool operator<(const pi &o)const{return cntcolor)+y.cnt; nxt.chd=0; assert(y.chd==0); nxt.ans=x.sum_l+y.sum_r; nxt.sum_l+=x.sum_l; nxt.sum_l+=y.sum_l; nxt.sum_l+=(x.cnt+x.chd+(v->color))*y.len; nxt.sum_r+=x.sum_r; nxt.sum_r+=y.sum_r; nxt.sum_r+=(x.chd+(v->color)+y.cnt)*x.len; nxt.md=pi(nxt.cnt,v); return nxt; } static DistanceSum rake(const DistanceSum& x,const DistanceSum& y){ DistanceSum nxt; nxt.len=x.len; nxt.cnt=x.cnt; nxt.chd=x.chd+y.cnt+y.chd; nxt.ans=x.sum_l+y.sum_l; nxt.sum_l+=x.sum_l; nxt.sum_l+=y.sum_l; nxt.sum_r+=x.sum_r; nxt.sum_r+=y.sum_l; nxt.md=max(x.md,y.md); return nxt; } }; template Vertex* centroid(TopTree, N> &G, Vertex* v){ using TT = typename remove_reference::type; using Node = typename TT::Node; using Type = typename TT::Type; Node* rt=G.expose(v); if(rt->type==Type::Edge) return v; Node* cc=rt; Vertex* ctr=nullptr; T lv=0,rv=0,sum=rt->dat.cnt; while(cc->type==Type::Compress){ G.propagate(cc); Node* ll=cc->ch[0]; if((ll->dat.cnt+lv)*2>sum){ assert(ll->type!=Type::Edge); rv+=cc->dat.md.cnt-ll->dat.cnt; cc=ll; continue; } Node* rr=cc->ch[1]; if((rr->dat.cnt+rv)*2>sum){ assert(rr->type!=Type::Edge); lv+=cc->dat.md.cnt-rr->dat.cnt; cc=rr; continue; } Node* mm=cc->q; if(mm and mm->dat.md.cnt*2>sum){ assert(mm->type!=Type::Edge); rv+=lv;lv=0; rv+=cc->dat.md.cnt-mm->dat.md.cnt; cc=(decltype(cc))mm->dat.md.ptr->handle; continue; } ctr=cc->dat.md.ptr; break; } return ctr; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: toptree/farthest.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "toptree.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct Vertex{ void* handle; Vertex():handle(nullptr){} }; template struct Farthest{ struct pi{ T dist; int idx; pi():dist(0),idx(-1){} pi(T dist,int idx):dist(dist),idx(idx){} bool operator<(const pi &o)const{return dist vector get_all_farthests(TopTree, N> &G,Vertex* v){ using TT = typename remove_reference::type; using Node = typename TT::Node; using Type = typename TT::Type; vector fs; auto dist=G.get_subtree(v).md.dist; if(dist==T(0)) return {}; auto dfs=[&](auto dfs,Node* rt,T d,bool left)->void{ if(!rt) return; G.propagate(rt); auto cur=left?(rt->dat.lf):(rt->dat.rg); if(d+cur.dist!=dist) return; if(rt->type==Type::Edge){ if(~cur.idx) fs.emplace_back(cur.idx); return; } if(rt->type==Type::Rake){ assert(!left); dfs(dfs,rt->ch[0],d,false); dfs(dfs,rt->ch[1],d,false); return; } if(rt->type==Type::Compress){ T mid=rt->ch[left?0:1]->dat.len; dfs(dfs,rt->ch[left?0:1],d,left); dfs(dfs,rt->ch[left?1:0],d+mid,left); dfs(dfs,rt->q,d+mid,false); return; } abort(); }; auto rt=G.expose(v); assert(rt->type==Type::Compress); dfs(dfs,rt->ch[0],T(0),false); dfs(dfs,rt->ch[1],T(0),true); dfs(dfs,rt->q,T(0),false); return fs; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: toptree/steiner.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct Vertex{ void* handle; int color; Vertex(int color=0):handle(nullptr),color(color){} }; template struct SteinerTree{ T con,len,lf,rg,md,chd,ans; SteinerTree(T len=0):con(0),len(len),lf(0),rg(0),md(0),chd(0),ans(0){} void toggle(){return swap(lf,rg);} static SteinerTree compress(SteinerTree x,Vertex* v,SteinerTree y){ if(x.chd){ if(!x.con){ x.con=1; x.lf=x.len; x.rg=0; x.md=x.chd; }else{ x.ans+=x.md+x.rg+x.chd; x.md=x.rg=x.chd=0; } } if(!x.con and !(v->color) and !y.con) return SteinerTree(x.len+y.len); SteinerTree nxt; nxt.con=1; nxt.lf=x.con?x.lf:(v->color?x.len:x.len+y.lf); nxt.rg=y.con?y.rg:(v->color?y.len:y.len+x.rg); nxt.ans=x.ans+y.ans; if(x.con and (v->color or y.con)){ nxt.ans+=x.md+x.rg; x.md=0; } if(y.con and (v->color or x.con)){ nxt.ans+=y.md+y.lf; y.md=0; } nxt.md=x.md+y.md; return nxt; } static SteinerTree rake(SteinerTree x,SteinerTree y){ x.chd+=y.chd+y.rg+y.md; x.ans+=y.ans; return x; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: toptree/toptree.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct TopTree{ enum Type { Compress, Rake, Edge }; struct Node{ Vertex* vs[2]; Cluster dat; Node* p; Node* q; Node* ch[2]; bool rev,guard; Type type; Node(){p=q=nullptr;rev=guard=false;} }; inline static array pool_vertex; inline static size_t ptr_vertex = 0; inline static array pool_node; inline static size_t ptr_node = 0; Cluster id; template inline Vertex* create(Args ...args){ auto t=&pool_vertex[ptr_vertex++]; auto dummy=&pool_vertex[ptr_vertex++]; *t=Vertex(forward(args)...); link(t,id,dummy); return t; } Node* recycle=nullptr; inline void dispose_node(Node* t){ t->p=recycle; recycle=t; } inline Node* get_new_node(){ if(recycle) return new(exchange(recycle,recycle->p)) Node; return &(pool_node[ptr_node++]); } inline Node* edge(Vertex* u,Cluster w,Vertex* v){ auto t=get_new_node(); t->vs[0]=u;t->vs[1]=v;t->dat=w; t->type=Type::Edge; return pushup(t); } inline Node* compress(Node* l,Node* r){ auto t=get_new_node(); t->ch[0]=l;t->ch[1]=r; t->type=Type::Compress; return pushup(t); } inline Node* rake(Node* l,Node* r){ auto t=get_new_node(); t->ch[0]=l;t->ch[1]=r; t->type=Type::Rake; return pushup(t); } int parent_dir(Node* t){ Node* p=t->p; if(!p) return -1; if(p->guard) return -1; if(p->ch[0]==t) return 0; if(p->ch[1]==t) return 1; return -1; } int parent_dir_ignore_guard(Node* t){ Node* p=t->p; if(!p) return -1; if(p->ch[0]==t) return 0; if(p->ch[1]==t) return 1; return -1; } inline Node* pushup(Node* const t){ Node* const l=t->ch[0]; Node* const r=t->ch[1]; if(t->type==Type::Compress){ assert(l->vs[1]==r->vs[0]); t->vs[0]=l->vs[0]; t->vs[1]=r->vs[1]; Cluster lf=l->dat; if(t->q){ assert(l->vs[1]==t->q->vs[1]); lf=Cluster::rake(l->dat,t->q->dat); } t->dat=Cluster::compress(lf,r->vs[0],r->dat); l->vs[1]->handle=t; } if(t->type==Type::Rake){ propagate(t); assert(l->vs[1]==r->vs[1]); t->vs[0]=l->vs[0]; t->vs[1]=l->vs[1]; t->dat=Cluster::rake(l->dat,r->dat); }else{ if(!t->p){ t->vs[0]->handle=t; t->vs[1]->handle=t; }else if(t->p->type==Type::Compress){ if(parent_dir(t)==-1) t->vs[0]->handle=t; }else if(t->p->type==Type::Rake){ t->vs[0]->handle=t; } } return t; } inline void toggle(Node* t){ if(t->type==Type::Edge){ swap(t->vs[0],t->vs[1]); t->dat.toggle(); }else if(t->type==Type::Compress){ swap(t->vs[0],t->vs[1]); t->dat.toggle(); t->rev^=true; }else if(t->type==Type::Rake){ }else abort(); } inline void propagate(Node* t){ if(t->type==Type::Compress){ if(t->rev){ assert(t->ch[0] and t->ch[1]); swap(t->ch[0],t->ch[1]); toggle(t->ch[0]); toggle(t->ch[1]); t->rev=false; } } } void set_toggle(Node* v){ toggle(v);propagate(v); } void pushdown(Node* t){ if(!t) return; pushdown(t->p); propagate(t); } void rotate(Node* t,Node* x,size_t dir){ Node* y=x->p; int par=parent_dir_ignore_guard(x); propagate(t->ch[dir]); x->ch[dir^1]=t->ch[dir]; t->ch[dir]->p=x; t->ch[dir]=x; x->p=t; t->p=y; if(~par) y->ch[par]=t; else if(y and y->type==Type::Compress) y->q=t; pushup(x);pushup(t); if(y and !y->guard) pushup(y); } void splay(Node* t){ assert(t->type!=Type::Edge); propagate(t); while(~parent_dir(t)){ Node* q=t->p; if(q->type!=t->type) break; if(~parent_dir(q) and q->p and q->p->type==q->type){ Node* r=q->p; if(r->p) propagate(r->p); propagate(r);propagate(q);propagate(t); int qt_dir=parent_dir(t); int rq_dir=parent_dir(q); if(rq_dir==qt_dir){ rotate(q,r,rq_dir^1); rotate(t,q,qt_dir^1); }else{ rotate(t,q,qt_dir^1); rotate(t,r,rq_dir^1); } }else{ if(q->p) propagate(q->p); propagate(q);propagate(t); int qt_dir=parent_dir(t); rotate(t,q,qt_dir^1); } } } Node* expose(Node* t){ pushdown(t); while(true){ assert(t->type!=Type::Rake); if(t->type==Type::Compress) splay(t); Node* n=nullptr; { Node* p=t->p; if(!p) break; if(p->type==Type::Rake){ propagate(p); splay(p); n=p->p; } if(p->type==Type::Compress){ propagate(p); if(p->guard and ~parent_dir_ignore_guard(t)) break; n=p; } } splay(n); int dir=parent_dir_ignore_guard(n); if(dir==-1 or n->p->type==Type::Rake) dir=0; Node* const c=n->ch[dir]; if(dir==1){ set_toggle(c); set_toggle(t); } int n_dir=parent_dir(t); if(~n_dir){ Node* const r=t->p; propagate(c); propagate(r); r->ch[n_dir]=c; c->p=r; n->ch[dir]=t; t->p=n; pushup(c);pushup(r); pushup(t);pushup(n); splay(r); }else{ propagate(c); n->q=c; c->p=n; n->ch[dir]=t; t->p=n; pushup(c);pushup(t);pushup(n); } if(t->type==Type::Edge) t=n; } return t; } Node* expose(Vertex* v){ return expose((Node*)(v->handle)); } void soft_expose(Vertex* u,Vertex* v){ pushdown((Node*)u->handle); pushdown((Node*)v->handle); Node* rt=expose(u); if(u->handle==v->handle){ if(rt->vs[1]==u or rt->vs[0]==v) set_toggle(rt); return; } rt->guard=true; Node* soft=expose(v); rt->guard=false; pushup(rt); if(parent_dir(soft)==0) set_toggle(rt); } void bring(Node* rt){ Node* rk=rt->q; if(!rk){ Node* ll=rt->ch[0]; dispose_node(ll->p); ll->p=nullptr; pushup(ll); }else if(rk->type==Type::Compress or rk->type==Type::Edge){ Node* nr=rk; set_toggle(nr); rt->ch[1]=nr; nr->p=rt; rt->q=nullptr; pushup(nr);pushup(rt); }else if(rk->type==Type::Rake){ propagate(rk); while(rk->ch[1]->type==Type::Rake){ propagate(rk->ch[1]); rk=rk->ch[1]; } pushdown(rk); rt->guard=true; splay(rk); rt->guard=false; Node* ll=rk->ch[0]; Node* rr=rk->ch[1]; propagate(ll); set_toggle(rr); rt->ch[1]=rr; rr->p=rt; rt->q=ll; ll->p=rt; dispose_node(rk); pushup(ll);pushup(rr);pushup(rt); } } Node* link(Vertex* u,Cluster w,Vertex* v){ if(!u->handle and !v->handle) return edge(u,w,v); Node* nnu=(Node*)u->handle; Node* nnv=(Node*)v->handle; Node* ee=edge(u,w,v); Node* ll=nullptr; assert(nnv); Node* vv=expose(nnv); propagate(vv); if(vv->vs[1]==v) set_toggle(vv); if(vv->vs[0]==v){ Node* nv=compress(ee,vv); ee->p=nv; pushup(ee); vv->p=nv; pushup(vv);pushup(nv); ll=nv; }else{ Node* nv=vv; Node* ch=nv->ch[0]; propagate(ch); nv->ch[0]=ee; ee->p=nv; pushup(ee); Node* bt=nv->q; Node* rk=nullptr; if(bt){ propagate(bt); rk=rake(bt,ch); bt->p=rk; ch->p=rk; pushup(bt);pushup(ch); }else{ rk=ch; } nv->q=rk; rk->p=nv; pushup(rk);pushup(nv); ll=nv; } assert(nnu); Node* uu=expose(nnu); propagate(uu); if(uu->vs[0]==u) set_toggle(uu); if(uu->vs[1]==u){ Node* tp=compress(uu,ll); uu->p=tp; ll->p=tp; pushup(uu);pushup(ll);pushup(tp); }else{ Node* nu=uu; Node* ch=nu->ch[1]; toggle(ch); propagate(ch); nu->ch[1]=ll; ll->p=nu; pushup(ll); Node* al=nu->q; Node* rk=nullptr; if(al){ propagate(al); rk=rake(al,ch); al->p=rk; ch->p=rk; pushup(al);pushup(ch); }else{ rk=ch; } nu->q=rk; rk->p=nu; pushup(rk);pushup(nu); } return ee; } void cut(Vertex* u,Vertex *v){ soft_expose(u,v); Node* rt=(Node*)u->handle; propagate(rt); Node* rr=rt->ch[1]; rr->p=nullptr; set_toggle(rr); assert(rr->ch[1]->type==Type::Edge); dispose_node(rr->ch[1]); bring(rr);bring(rt); } Node* path(Vertex* u,Vertex* v){ assert(u!=v); soft_expose(u,v); Node* rt=(Node*)u->handle; propagate(rt); propagate(rt->ch[1]); return rt->ch[1]->ch[0]; } void set_vertex(Vertex* u,Vertex v){ auto t=expose(u); *u=v; pushup(t); } void set_edge(Vertex* u,Vertex* v,const Cluster &w){ auto t=path(u,v); assert(t->type==Type::Edge); t->dat=w; while(t) pushup(t),t=t->p; } Cluster get_path(Vertex* u,Vertex* v){ return path(u,v)->dat; } Cluster get_subtree(Vertex* v){ return expose(v)->dat; } // subtree of v when p is root Cluster get_subtree(Vertex* p,Vertex* v){ Node* t=path(p,v); Cluster res=t->p->ch[1]->dat; res.toggle(); Node* rk=t->p->q; if(t->p->q){ assert(rk->vs[1]==t->p->ch[1]->vs[0]); res=Cluster::rake(res,rk->dat); } return res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tree/ahu.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif // http://wwwmayr.in.tum.de/konferenzen/Jass08/courses/1/smal/Smal_Talk.pdf //BEGIN CUT HERE struct AHU{ inline static map, int> I; vector< vector > G; AHU(int n):G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } int dfs(int v,int p){ vector hs; for(int u:G[v]) if(u!=p) hs.emplace_back(dfs(u,v)); sort(hs.begin(),hs.end()); int sz=I.size(); if(!I.count(hs)) I[hs]=sz; return I[hs]; } int build(int r=0){ return dfs(r,-1); } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tree/auxiliarytree.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "lowestcommonancestor.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct AuxiliaryTree : LowestCommonAncestor{ using super = LowestCommonAncestor; vector idx; vector> T; AuxiliaryTree(int n):super(n),idx(n),T(n){} void dfs(int v,int p,int &pos){ idx[v]=pos++; for(int u:G[v]) if(u!=p) dfs(u,v,pos); } void build(int r=0){ super::build(r); int pos=0; dfs(r,-1,pos); } void add_aux_edge(int u,int v){ T[u].emplace_back(v); T[v].emplace_back(u); } using super::lca, super::dep; void query(vector &vs){ assert(!vs.empty()); sort(vs.begin(),vs.end(), [&](int a,int b){return idx[a] st; st.emplace(vs[0]); for(int i=0;i+11){ int c=st.top();st.pop(); add_aux_edge(st.top(),c); } } void clear(const vector &ws){ for(int w:ws) T[w].clear(); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tree/centroid.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct Centroid{ vector sz,dead; vector< vector > G; Centroid(int n):sz(n,1),dead(n,0),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } int dfs(int v,int p){ sz[v]=1; for(int u:G[v]) if(u!=p and !dead[u]) sz[v]+=dfs(u,v); return sz[v]; } void find(int v,int p,int tmp,vector &cs) { int ok=1; for (int u:G[v]){ if(u==p or dead[u]) continue; find(u,v,tmp,cs); ok&=(sz[u]<=tmp/2); } ok&=(tmp-sz[v]<=tmp/2); if(ok) cs.emplace_back(v); } vector build(int r) { int tmp=dfs(r,-1); vector cs; find(r,-1,tmp,cs); return cs; } const vector& operator[](int k)const{return G[k];} void disable(int v){dead[v]=1;} void enable(int v){dead[v]=0;} int alive(int v){return !dead[v];} }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tree/construct_from_distances_to_farthest_vertex.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE vector< vector > construct_from_distances_to_farthest_vertex(vector ds){ int n=ds.size(); vector> G(n),NG; for(int d:ds) if(d>=n) return NG; vector ts(n,0); vector> qs(n); for(int i=0;i xs(n),ys(n); for(int i=0;i<(dm+1)/2;i++){ xs[dm-i]=qs[dm-i].front();qs[dm-i].pop(); ys[dm-i]=qs[dm-i].front();qs[dm-i].pop(); if(i){ add_edge(xs[dm-i+1],xs[dm-i]); add_edge(ys[dm-i+1],ys[dm-i]); } } if(dm&1){ add_edge(xs[dm/2+1],ys[dm/2+1]); }else{ xs[dm/2]=qs[dm/2].front();qs[dm/2].pop(); add_edge(xs[dm/2+1],xs[dm/2]); add_edge(ys[dm/2+1],xs[dm/2]); } for(int i=0;i construct(vector ds) { auto G=construct_from_distances_to_farthest_vertex(ds); if(G.empty()) return {}; vector bs; for(int i=0;i<(int)G.size();i++) for(int j:G[i]) if(i using namespace std; #endif //BEGIN CUT HERE template struct DiameterForEdge{ using Edge = pair; vector dp,ps; vector > G; DiameterForEdge(int n):dp(n),ps(n),G(n){} void add_edge(int u,int v,T c){ G[u].emplace_back(v,c); G[v].emplace_back(u,c); } void dfs(int v,int p,int &s){ ps[v]=p; if(p<0) dp[v]=T(0); if(dp[s] endPoints(){ int s=0; dfs(s,-1,s); int t=s; dfs(t,-1,t); return make_pair(s,t); } T build(){ int t=endPoints().second; return dp[t]; } vector restore(){ int t=endPoints().second; vector seq; while(~t){ seq.emplace_back(t); t=ps[t]; } return seq; } vector distance(int v){ dfs(v,-1,v); return dp; } vector farthest(){ int t=endPoints().second; auto ds=dp; auto dt=distance(t); for(int i=0;i<(int)ds.size();i++) if(ds[i]>n; DiameterForEdge G(n); for(int i=1;i>x>>y; x--;y--; G.add_edge(x,y,1); } int m; cin>>m; DiameterForEdge H(m); for(int i=1;i>x>>y; x--;y--; H.add_edge(x,y,1); } auto dp1=G.farthest(); auto dp2=H.farthest(); sort(dp1.begin(),dp1.end()); sort(dp2.begin(),dp2.end()); using ll = long long; vector s(m+1,0); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template struct DiameterForVertex{ vector vs,dp; vector > G; DiameterForVertex(int n):dp(n),G(n){} DiameterForVertex(vector vs):vs(vs),dp(vs.size()),G(vs.size()){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(int v,int p,int &s){ if(p<0) dp[v]=T(0); dp[v]+=vs[v]; if(dp[s] us){ assert(us.size()==dp.size()); vs=us; return build(); } }; //END CUT HERE #ifndef call_from_test // test build with argument vector signed ARC097_F(){ int n; cin>>n; DiameterForVertex G(n); vector deg(n,0); for(int i=1;i>x>>y; x--;y--; G.add_edge(x,y); deg[x]++; deg[y]++; } string s; cin>>s; int cnt=(n-1)*2,num=0; queue que; vector dead(n,0); for(int i=0;i vs(n,0); for(int i=0;i using namespace std; #define call_from_test #include "levelancestor.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct EulerTourForBFS : LevelAncestor{ using super = LevelAncestor; vector ls; vector> H; EulerTourForBFS(int n):super(n),ls(n),H(n){} using super::par; using super::dep; void build(int r=0){ super::build(r); int pos=0; queue que; que.emplace(r); while(!que.empty()){ int v=que.front();que.pop(); ls[v]=pos++; H[dep[v]].emplace_back(v); for(int u:super::G[v]){ if(u==par[0][v]) continue; que.emplace(u); } } } int idx(int v){return ls[v];} int find(int v,int d,int a){ int l=-1,r=H[d].size(); while(l+1>1; int p=super::up(H[d][m],d-dep[v]); if(ls[v]+a<=ls[p]) r=m; else l=m; } return ls[H[d][0]]+r; } template void exec(int v,int d,F f){ if(dep[v]+d>=(int)H.size()) return; if(H[dep[v]+d].empty()) return; int l=find(v,dep[v]+d,0); int r=find(v,dep[v]+d,1); if(l using namespace std; #endif //BEGIN CUT HERE class EulerTourForEdge{ private: vector ds,us,dep,btm; void dfs(int v,int p,int d){ dep[v]=d; for(int u:G[v]){ if(u==p) continue; ds[u]=btm.size(); btm.emplace_back(u); dfs(u,v,d+1); us[u]=btm.size(); btm.emplace_back(u); } } public: vector< vector > G; EulerTourForEdge(int n): ds(n),us(n),dep(n),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void build(int r=0){ btm.clear(); ds[r]=btm.size(); btm.emplace_back(r); dfs(r,-1,0); us[r]=btm.size(); btm.emplace_back(r); } int child(int u,int v){ return dep[u] void query(int u,int v,F f){ if(dep[u]>dep[v]) swap(u,v); f(ds[u]+1,ds[v]+1); } template void update(int v,T x,G g){ g(ds[v], x); g(us[v],-x); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tree/eulertourforvertex.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE class EulerTourForVertex{ private: vector ls,rs; int pos; void dfs(int v,int p){ ls[v]=pos++; for(int u:G[v]) if(u!=p) dfs(u,v); rs[v]=pos; } public: vector< vector > G; EulerTourForVertex(int n):ls(n),rs(n),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void build(int r=0){ pos=0; dfs(r,-1); } int idx(int v){return ls[v];} template void exec(int v,F f){ f(ls[v],rs[v]); } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tree/heavylightdecomposition.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE class HLD{ private: void dfs_sz(int v) { auto &es=G[v]; if(~par[v]) es.erase(find(es.begin(),es.end(),par[v])); for(int &u:es){ par[u]=v; dfs_sz(u); sub[v]+=sub[u]; if(sub[u]>sub[es[0]]) swap(u,es[0]); } } void dfs_hld(int v,int &pos) { vid[v]=pos++; inv[vid[v]]=v; for(int u:G[v]){ if(u==par[v]) continue; nxt[u]=(u==G[v][0]?nxt[v]:u); dfs_hld(u,pos); } } public: vector< vector > G; // vid: vertex -> idx // inv: idx -> vertex vector vid,nxt,sub,par,inv; HLD(int n):G(n),vid(n,-1),nxt(n),sub(n,1),par(n,-1),inv(n){} void add_edge(int u,int v) { G[u].emplace_back(v); G[v].emplace_back(u); } void build(int r=0) { int pos=0; dfs_sz(r); nxt[r]=r; dfs_hld(r,pos); } int lca(int u,int v){ while(1){ if(vid[u]>vid[v]) swap(u,v); if(nxt[u]==nxt[v]) return u; v=par[nxt[v]]; } } template void for_each(int u,int v,const F& f) { while(1){ if(vid[u]>vid[v]) swap(u,v); f(max(vid[nxt[v]],vid[u]),vid[v]+1); if(nxt[u]!=nxt[v]) v=par[nxt[v]]; else break; } } template void for_each_edge(int u,int v,const F& f) { while(1){ if(vid[u]>vid[v]) swap(u,v); if(nxt[u]!=nxt[v]){ f(vid[nxt[v]],vid[v]+1); v=par[nxt[v]]; }else{ if(u!=v) f(vid[u]+1,vid[v]+1); break; } } } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; }; #endif ================================================ FILE: tree/lca.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct LCA{ const int lg = 12; const int sz = 1< P,D,E,A,B,T,ht; vector > G,dat; LCA(int n): n(n),P(n,-1),D(n),E(n*2,0),A(n*2,-1),B(n*2/lg+1),T(sz,0),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(int v,int p,int d){ int k=0,u; vector iter(n,0); using T = tuple; stack st; START: D[v]=k; A[k]=P[v]=p; E[k++]=d; for(;iter[v]<(int)G[v].size();iter[v]++){ u=G[v][iter[v]]; if(u==p) continue; st.emplace(v,p,d); p=v;v=u;d=d+1; goto START; END: tie(v,p,d)=st.top();st.pop(); } A[k]=P[v]; E[k++]=d-1; if(!st.empty()) goto END; } // if it need leftmost, then add: if(E[i]==E[j]) return i>i)&1) e++; else e--; if(e(m,-1)); ht.assign(m+1,0); for(int j=2;j<=m;j++) ht[j]=ht[j>>1]+1; for(int j=0;j>y)|(ms<<(lg-y)))&ms; return l+T[b]; } inline int ls(int i,int l){ int k=l-i*lg; int b=((B[i]>>k)|(ms<<(lg-k)))&ms; return l+T[b]; } inline int rs(int j,int r){ int k=r-j*lg+1; int b=(B[j]|(ms<D[r]) swap(l,r); int x=D[l],y=D[r]; int m=rmq(x,y); return m==x?l:A[m]; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tree/levelancestor.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct LevelAncestor{ vector > G,par,lad; vector dep,nxt,len,pth,ord,hs; LevelAncestor(int n): G(n),dep(n),nxt(n,-1),len(n),pth(n),ord(n),hs(n+1,0){ int h=1; while((1<(n,-1)); for(int i=2;i<=n;i++) hs[i]=hs[i>>1]+1; } void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(int v,int p,int d,int f){ if(nxt[v]<0){ par[0][nxt[v]=v]=p; len[v]=dep[v]=d; for(int u:G[v]){ if(u==p) continue; dfs(u,v,d+1,0); if(len[v]dep[v]) swap(u,v); for(int k=0;k>k&1) v=par[k][v]; if(u==v) return u; for(int k=h-1;k>=0;k--){ if(par[k][u]==par[k][v]) continue; u=par[k][u]; v=par[k][v]; } return par[0][u]; } int distance(int u,int v){ return dep[u]+dep[v]-dep[lca(u,v)]*2; } int up(int v,int d){ if(d==0) return v; v=par[hs[d]][v]; d-=1<=dep[v]) return par[0][u]; int l=up(v,dep[v]-dep[u]-1); return par[0][l]==u?l:par[0][u]; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tree/lowestcommonancestor.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct LowestCommonAncestor{ int h; vector< vector > G,par; vector dep; LowestCommonAncestor(int n):G(n),dep(n){ h=1; while((1<(n,-1)); } void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(int v,int p,int d){ par[0][v]=p; dep[v]=d; for(int u:G[v]) if(u!=p) dfs(u,v,d+1); } void build(int r=0){ int n=G.size(); dfs(r,-1,0); for(int k=0;k+1dep[v]) swap(u,v); for(int k=0;k>k&1) v=par[k][v]; if(u==v) return u; for(int k=h-1;k>=0;k--) if(par[k][u]!=par[k][v]) u=par[k][u],v=par[k][v]; return par[0][u]; } int distance(int u,int v){ return dep[u]+dep[v]-dep[lca(u,v)]*2; } }; //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: tree/mo_on_tree.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../algorithm/mo.cpp" #include "../tree/eulertourforedge.cpp" #undef call_from_test #endif //BEGIN CUT HERE struct MoOnTree{ Mo* mo; using F = Mo::F; EulerTourForEdge et; vector app,idx; int width; F expand,shrink; MoOnTree(int n,int width,F expand,F shrink): et(n),app(n,0),idx(n),width(width),expand(expand),shrink(shrink){} vector> es,qs; void add_edge(int u,int v){ es.emplace_back(u,v); et.add_edge(u,v); } void add_query(int u,int v){ qs.emplace_back(u,v); } void build(){ et.build(); int num=0; for(auto[u,v]:es) idx[et.child(u,v)]=num++; F exec=[&](int k){ int v=et.bottom(k); int e=idx[v]; app[v]^=1; if(app[v]) expand(e); else shrink(e); }; int n=et.G.size(); mo=new Mo(2*n,width,exec,exec); auto f=[&](int l,int r){mo->add(min(l,r),max(l,r));}; for(auto[u,v]:qs) et.query(u,v,f); mo->build(); } int process(){return mo->process();} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: tree/rerooting.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct ReRooting{ struct Node{ int to,rev; Edge data; Node(int to,Edge data):to(to),data(data){} bool operator<(const Node &v)const{return to; using Lift = function; vector< vector > G; vector< vector > ld,rd; vector lp,rp; const Fold fold; const Lift lift; const T id; ReRooting(int n,const Fold fold,const Lift lift,const T id): G(n),ld(n),rd(n),lp(n),rp(n),fold(fold),lift(lift),id(id){} void add_edge(int u,int v,Edge d,Edge e){ G[u].emplace_back(v,d); G[v].emplace_back(u,e); } void add_edge(int u,int v,Edge d){add_edge(u,v,d,d);} // k: idx for edge (not vertex) T dfs(int v,int k){ while(lp[v]!=k and lp[v]<(int)G[v].size()){ auto &e=G[v][lp[v]]; ld[v][lp[v]+1]=fold(ld[v][lp[v]],lift(dfs(e.to,e.rev),e.data)); lp[v]++; } while(rp[v]!=k and rp[v]>=0){ auto &e=G[v][rp[v]]; rd[v][rp[v]]=fold(rd[v][rp[v]+1],lift(dfs(e.to,e.rev),e.data)); rp[v]--; } if(k<0) return rd[v][0]; return fold(ld[v][k],rd[v][k+1]); } int search(vector &vs,int idx){ return lower_bound(vs.begin(),vs.end(),Node(idx,vs[0].data))-vs.begin(); } vector build(){ int n=G.size(); for(int i=0;i res; for(int i=0;i using namespace std; #endif //BEGIN CUT HERE struct Sack{ using F = function; vector sub,hvy,big; vector< vector > G,Q; F expand,shrink,query; Sack(int n,F expand,F shrink,F query): sub(n,1),hvy(n,-1),big(n,0),G(n),Q(n), expand(expand),shrink(shrink),query(query){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void add_query(int v,int k){ Q[v].emplace_back(k); } void add(int v,int p,int x){ if(x==1) expand(v); else shrink(v); for(int u:G[v]) if(u!=p and !big[u]) add(u,v,x); } void dfs(int v=0,int p=-1,bool k=0){ for(int u:G[v]) if(u!=p and u!=hvy[v]) dfs(u,v,0); if(~hvy[v]){ dfs(hvy[v],v,1); big[hvy[v]]=1; } add(v,p,1); for(int k:Q[v]) query(k); if(~hvy[v]) big[hvy[v]]=0; if(!k) add(v,p,0); } void build(int v=0,int p=-1){ for(int u:G[v]){ if(u==p) continue; build(u,v); if(hvy[v]<0 or sub[hvy[v]] using namespace std; #endif //BEGIN CUT HERE template V compress(V vs){ sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); return vs; } template map dict(const vector &vs){ map res; for(int i=0;i<(int)vs.size();i++) res[vs[i]]=i; return res; } map dict(const string &s){ return dict(vector(s.begin(),s.end())); } template vector compressed(vector vs){ auto dc=dict(compress(vs)); for(auto &v:vs) v=dc[v]; return vs; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: vector/fusion.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template vector fusion(vector bs,Ts... ts){ auto append=[&](auto vs){for(auto v:vs) bs.emplace_back(v);}; initializer_list{(void(append(ts)),0)...}; return bs; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: vector/identity.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE vector identity(int n){ vector ord(n); iota(ord.begin(),ord.end(),0); return ord; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: vector/inversion.cpp ================================================ #ifndef call_from_test #include using namespace std; #define call_from_test #include "../datastructure/binaryindexedtree.cpp" #undef call_from_test #endif //BEGIN CUT HERE template long long inversion(vector vs){ int n=vs.size(); long long res=0; BIT bit(n); for(T v:vs){ assert(v<=n); res+=bit.query(v+1,n+1); bit.add(v,1); } return res; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: vector/multi.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template typename enable_if::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v(e,v...); } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: vector/near.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template vector add(vector vs,vector as){ assert(vs.size()==as.size()); for(int i=0;i<(int)vs.size();i++) vs[i]+=as[i]; return vs; } template vector add(vector vs,U a){ return add(vs,vector(vs.size(),a)); } template vector mul(vector vs,vector as){ assert(vs.size()==as.size()); for(int i=0;i<(int)vs.size();i++) vs[i]*=as[i]; return vs; } template vector mul(vector vs,U a){ return mul(vs,vector(vs.size(),a)); } template vector near(vector vs,Ts... ts){ vector rs; rs.reserve(vs.size()*sizeof...(ts)); auto append=[&](auto a){ for(auto w:add(vs,a)) rs.emplace_back(w); }; initializer_list{(void(append(ts)),0)...}; return rs; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: vector/powers.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE // [0, n] template vector powers(int n,T x){ vector po(n+1,T(1)); for(int i=0;i using namespace std; #endif //BEGIN CUT HERE template vector reversed(vector vs){ reverse(vs.begin(),vs.end()); return vs; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: vector/runlength.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template decltype(auto) runlength(vector vs){ vector> es; for(auto v:vs){ if(es.empty() or es.back().first!=v) es.emplace_back(v,0); es.back().second++; } return es; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif ================================================ FILE: vector/sorted.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template vector sorted(vector vs){ sort(vs.begin(),vs.end()); return vs; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif ================================================ FILE: vector/zip.cpp ================================================ #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template decltype(auto) zip(vector... args){ vector res; int n=min({args.size()...}); res.reserve(n); for(int i=0;i