Skip to content

Commit 582ae55

Browse files
chore: update minified library versions
1 parent 65bb98b commit 582ae55

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

cp-algo/min/geometry/closest_pair.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
#include "point.hpp"
66
#include <vector>
77
#include <map>
8-
namespace cp_algo::geometry{auto closest_pair(auto const&r){using point=std::decay_t<decltype(r[0])>;size_t n=size(r);int64_t md=1e18;for(size_t i=0;i<n/100;i++){auto A=random::rng()%n;auto B=random::rng()%n;if(A!=B){md=std::min(md,norm(r[A]-r[B]));if(md==0){return std::pair{A,B};}}}std::map<point,big_vector<size_t>>neigs;md=(int64_t)ceil(sqrt((double)md));for(size_t i=0;i<n;i++){neigs[r[i]/md].push_back(i);}size_t a=0,b=1;md=norm(r[a]-r[b]);for(auto&[p,id]:neigs){for(int dx:{-1,0,1}){for(int dy:{-1,0,1}){auto pp=p+point{dx,dy};if(!neigs.count(pp)){continue;}for(size_t i:neigs[pp]){for(size_t j:id){if(j==i){break;}int64_t cur=norm(r[i]-r[j]);if(cur<md){md=cur;a=i;b=j;}}}}}}return std::pair{a,b};}}
8+
namespace cp_algo::geometry{auto closest_pair(auto const&r){using point=std::decay_t<decltype(r[0])>;size_t n=size(r);int64_t md=1e18;for(size_t i=0;i<n/100;i++){auto A=random::rng()%n;auto B=random::rng()%n;if(A!=B){md=std::min(md,norm(r[A]-r[B]));if(md==0){return std::pair{A,B};}}}big_map<point,big_vector<size_t>>neigs;md=(int64_t)ceil(sqrt((double)md));for(size_t i=0;i<n;i++){neigs[r[i]/md].push_back(i);}size_t a=0,b=1;md=norm(r[a]-r[b]);for(auto&[p,id]:neigs){for(int dx:{-1,0,1}){for(int dy:{-1,0,1}){auto pp=p+point{dx,dy};if(!neigs.count(pp)){continue;}for(size_t i:neigs[pp]){for(size_t j:id){if(j==i){break;}int64_t cur=norm(r[i]-r[j]);if(cur<md){md=cur;a=i;b=j;}}}}}}return std::pair{a,b};}}
99
#endif

cp-algo/min/graph/shortest_path.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include "base.hpp"
44
#include <algorithm>
55
#include <queue>
6-
namespace cp_algo::graph{struct shortest_path_context{big_vector<int64_t>dist;big_vector<edge_index>pre;static constexpr int64_t inf=1e18;shortest_path_context(int n):dist(n,inf),pre(n){}};struct dijkstra_context:shortest_path_context{struct que_t{int64_t dist;node_index v;bool operator<(que_t const&other)const{return dist>other.dist;}};std::priority_queue<que_t>pq;dijkstra_context(int n):shortest_path_context(n){}void push(node_index,edge_index,node_index v){pq.push({dist[v],v});}std::optional<node_index>next_node(){while(!empty(pq)){auto[dv,v]=pq.top();pq.pop();if(dv==dist[v]){return v;}}return std::nullopt;}};struct spfa_context:shortest_path_context{big_queue<node_index>que;big_vector<char>flags;static constexpr char in_queue=1;static constexpr char invalidated=2;spfa_context(int n):shortest_path_context(n),flags(n){}void push(node_index,edge_index,node_index v){if(!(flags[v]&in_queue)){que.push(v);flags[v]|=in_queue;}}std::optional<node_index>next_node(){while(!que.empty()){node_index v=que.front();que.pop();flags[v]&=~in_queue;if(!(flags[v]&invalidated)){return v;}}return std::nullopt;}};struct deep_spfa_context:spfa_context{struct traverse_edge{edge_index e;node_index v;};big_vector<std::basic_string<traverse_edge>>dependents;deep_spfa_context(int n):spfa_context(n),dependents(n){}void push(node_index u,edge_index e,node_index v){invalidate_subtree(v);dependents[u].push_back({e,v});flags[v]&=~invalidated;spfa_context::push(u,e,v);}void invalidate_subtree(node_index v){big_vector<node_index>to_invalidate={v};while(!empty(to_invalidate)){node_index u=to_invalidate.back();to_invalidate.pop_back();flags[u]|=invalidated;flags[u]&=~in_queue;for(auto[e,v]:dependents[u]){if(pre[v]==e){to_invalidate.push_back(v);}}dependents[u].clear();}}};template<typename Context,weighted_graph_type graph>Context sssp_impl(graph const&g,node_index s){Context context(g.n());context.dist[s]=0;context.pre[s]=-1;context.push(s,-1,s);while(auto ov=context.next_node()){node_index v=*ov;for(auto e:g.outgoing(v)){node_index u=g.edge(e).traverse(v);auto w=g.edge(e).w;if(context.dist[v]+w<context.dist[u]){context.dist[u]=context.dist[v]+w;context.pre[u]=e;context.push(v,e,u);}}}return context;}template<weighted_graph_type graph>shortest_path_context dijkstra(graph const&g,node_index s){return sssp_impl<dijkstra_context>(g,s);}template<weighted_graph_type graph>shortest_path_context spfa(graph const&g,node_index s){return sssp_impl<spfa_context>(g,s);}template<weighted_graph_type graph>shortest_path_context deep_spfa(graph const&g,node_index s){return sssp_impl<deep_spfa_context>(g,s);}template<weighted_graph_type graph>shortest_path_context single_source_shortest_path(graph const&g,node_index s){bool negative_edges=false;for(auto e:g.edges()){negative_edges|=e.w<0;}return negative_edges?deep_spfa(g,s):dijkstra(g,s);}big_vector<edge_index>recover_path(auto const&g,auto const&pre,node_index s,node_index t){big_vector<edge_index>path;node_index v=t;while(v!=s){path.push_back(pre[v]);v=g.edge(pre[v]).traverse(v);}std::ranges::reverse(path);return path;}template<weighted_graph_type graph>std::optional<std::pair<int64_t,big_vector<edge_index>>>shortest_path(graph const&g,node_index s,node_index t){auto[dist,pre]=single_source_shortest_path(g,s);if(dist[t]==shortest_path_context::inf){return std::nullopt;}return{{dist[t],recover_path(g,pre,s,t)}};}}
6+
namespace cp_algo::graph{struct shortest_path_context{big_vector<int64_t>dist;big_vector<edge_index>pre;static constexpr int64_t inf=1e18;shortest_path_context(int n):dist(n,inf),pre(n){}};struct dijkstra_context:shortest_path_context{struct que_t{int64_t dist;node_index v;bool operator<(que_t const&other)const{return dist>other.dist;}};big_priority_queue<que_t>pq;dijkstra_context(int n):shortest_path_context(n){}void push(node_index,edge_index,node_index v){pq.push({dist[v],v});}std::optional<node_index>next_node(){while(!empty(pq)){auto[dv,v]=pq.top();pq.pop();if(dv==dist[v]){return v;}}return std::nullopt;}};struct spfa_context:shortest_path_context{big_queue<node_index>que;big_vector<char>flags;static constexpr char in_queue=1;static constexpr char invalidated=2;spfa_context(int n):shortest_path_context(n),flags(n){}void push(node_index,edge_index,node_index v){if(!(flags[v]&in_queue)){que.push(v);flags[v]|=in_queue;}}std::optional<node_index>next_node(){while(!que.empty()){node_index v=que.front();que.pop();flags[v]&=~in_queue;if(!(flags[v]&invalidated)){return v;}}return std::nullopt;}};struct deep_spfa_context:spfa_context{struct traverse_edge{edge_index e;node_index v;};big_vector<big_basic_string<traverse_edge>>dependents;deep_spfa_context(int n):spfa_context(n),dependents(n){}void push(node_index u,edge_index e,node_index v){invalidate_subtree(v);dependents[u].push_back({e,v});flags[v]&=~invalidated;spfa_context::push(u,e,v);}void invalidate_subtree(node_index v){big_vector<node_index>to_invalidate={v};while(!empty(to_invalidate)){node_index u=to_invalidate.back();to_invalidate.pop_back();flags[u]|=invalidated;flags[u]&=~in_queue;for(auto[e,v]:dependents[u]){if(pre[v]==e){to_invalidate.push_back(v);}}dependents[u].clear();}}};template<typename Context,weighted_graph_type graph>Context sssp_impl(graph const&g,node_index s){Context context(g.n());context.dist[s]=0;context.pre[s]=-1;context.push(s,-1,s);while(auto ov=context.next_node()){node_index v=*ov;for(auto e:g.outgoing(v)){node_index u=g.edge(e).traverse(v);auto w=g.edge(e).w;if(context.dist[v]+w<context.dist[u]){context.dist[u]=context.dist[v]+w;context.pre[u]=e;context.push(v,e,u);}}}return context;}template<weighted_graph_type graph>shortest_path_context dijkstra(graph const&g,node_index s){return sssp_impl<dijkstra_context>(g,s);}template<weighted_graph_type graph>shortest_path_context spfa(graph const&g,node_index s){return sssp_impl<spfa_context>(g,s);}template<weighted_graph_type graph>shortest_path_context deep_spfa(graph const&g,node_index s){return sssp_impl<deep_spfa_context>(g,s);}template<weighted_graph_type graph>shortest_path_context single_source_shortest_path(graph const&g,node_index s){bool negative_edges=false;for(auto e:g.edges()){negative_edges|=e.w<0;}return negative_edges?deep_spfa(g,s):dijkstra(g,s);}big_vector<edge_index>recover_path(auto const&g,auto const&pre,node_index s,node_index t){big_vector<edge_index>path;node_index v=t;while(v!=s){path.push_back(pre[v]);v=g.edge(pre[v]).traverse(v);}std::ranges::reverse(path);return path;}template<weighted_graph_type graph>std::optional<std::pair<int64_t,big_vector<edge_index>>>shortest_path(graph const&g,node_index s,node_index t){auto[dist,pre]=single_source_shortest_path(g,s);if(dist[t]==shortest_path_context::inf){return std::nullopt;}return{{dist[t],recover_path(g,pre,s,t)}};}}
77
#endif

cp-algo/min/number_theory/two_squares.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
#include <utility>
88
#include <vector>
99
#include <map>
10-
namespace cp_algo::math{template<typename T>using gaussint=complex<T>;template<typename _Int>auto two_squares_prime_any(_Int p){if(p==2){return gaussint<_Int>{1,1};}assert(p%4==1);using Int=std::make_signed_t<_Int>;using base=dynamic_modint<Int>;return base::with_mod(p,[&](){base g=primitive_root(p);int64_t i=bpow(g,(p-1)/4).getr();int64_t q0=1,q1=0;int64_t r=i,m=p;do{int64_t d=r/m;q0=std::exchange(q1,q0+d*q1);r=std::exchange(m,r%m);}while(q1<p/q1);return gaussint<_Int>{q0,(base(i)*base(q0)).rem()};});}template<typename Int>big_vector<gaussint<Int>>two_squares_all(Int n){if(n==0){return{0};}auto primes=factorize(n);std::map<Int,int>cnt;for(auto p:primes){cnt[p]++;}big_vector<gaussint<Int>>res={1};for(auto[p,c]:cnt){big_vector<gaussint<Int>>nres;if(p%4==3){if(c%2==0){auto mul=bpow(gaussint<Int>(p),c/2);for(auto p:res){nres.push_back(p*mul);}}}else if(p%4==1){auto base=two_squares_prime_any(p);for(int i=0;i<=c;i++){auto mul=bpow(base,i)*bpow(conj(base),c-i);for(auto p:res){nres.push_back(p*mul);}}}else if(p%4==2){auto mul=bpow(gaussint<Int>(1,1),c);for(auto p:res){nres.push_back(p*mul);}}res=nres;}big_vector<gaussint<Int>>nres;for(auto p:res){while(p.real()<0||p.imag()<0){p*=gaussint<Int>(0,1);}nres.push_back(p);if(!p.real()||!p.imag()){nres.emplace_back(p.imag(),p.real());}}return nres;}}
10+
namespace cp_algo::math{template<typename T>using gaussint=complex<T>;template<typename _Int>auto two_squares_prime_any(_Int p){if(p==2){return gaussint<_Int>{1,1};}assert(p%4==1);using Int=std::make_signed_t<_Int>;using base=dynamic_modint<Int>;return base::with_mod(p,[&](){base g=primitive_root(p);int64_t i=bpow(g,(p-1)/4).getr();int64_t q0=1,q1=0;int64_t r=i,m=p;do{int64_t d=r/m;q0=std::exchange(q1,q0+d*q1);r=std::exchange(m,r%m);}while(q1<p/q1);return gaussint<_Int>{q0,(base(i)*base(q0)).rem()};});}template<typename Int>big_vector<gaussint<Int>>two_squares_all(Int n){if(n==0){return{0};}auto primes=factorize(n);big_map<Int,int>cnt;for(auto p:primes){cnt[p]++;}big_vector<gaussint<Int>>res={1};for(auto[p,c]:cnt){big_vector<gaussint<Int>>nres;if(p%4==3){if(c%2==0){auto mul=bpow(gaussint<Int>(p),c/2);for(auto p:res){nres.push_back(p*mul);}}}else if(p%4==1){auto base=two_squares_prime_any(p);for(int i=0;i<=c;i++){auto mul=bpow(base,i)*bpow(conj(base),c-i);for(auto p:res){nres.push_back(p*mul);}}}else if(p%4==2){auto mul=bpow(gaussint<Int>(1,1),c);for(auto p:res){nres.push_back(p*mul);}}res=nres;}big_vector<gaussint<Int>>nres;for(auto p:res){while(p.real()<0||p.imag()<0){p*=gaussint<Int>(0,1);}nres.push_back(p);if(!p.real()||!p.imag()){nres.emplace_back(p.imag(),p.real());}}return nres;}}
1111
#endif

cp-algo/min/util/big_alloc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ return static_cast<T*>(::operator new(padded,std::align_val_t(align)));}void dea
2222
#if CP_ALGO_USE_MMAP
2323
if(padded>=MEGABYTE){munmap(p,padded);return;}
2424
#endif
25-
::operator delete(p,padded,std::align_val_t(align));}private:static constexpr std::size_t MEGABYTE=1<<20;static constexpr std::size_t round_up(std::size_t x)noexcept{return(x+Align-1)/Align*Align;}};template<typename T>using big_vector=std::vector<T,big_alloc<T>>;template<typename T>using big_basic_string=std::basic_string<T,std::char_traits<T>,big_alloc<T>>;template<typename T>using big_deque=std::deque<T,big_alloc<T>>;template<typename Key,typename Value,typename Compare=std::less<Key>>using big_map=std::map<Key,Value,Compare,big_alloc<std::pair<const Key,Value>>>;using big_string=big_basic_string<char>;template<typename T>using big_stack=std::stack<T,big_deque<T>>;template<typename T>using big_queue=std::queue<T,big_deque<T>>;}
25+
::operator delete(p,padded,std::align_val_t(align));}private:static constexpr std::size_t MEGABYTE=1<<20;static constexpr std::size_t round_up(std::size_t x)noexcept{return(x+Align-1)/Align*Align;}};template<typename T>using big_vector=std::vector<T,big_alloc<T>>;template<typename T>using big_basic_string=std::basic_string<T,std::char_traits<T>,big_alloc<T>>;template<typename T>using big_deque=std::deque<T,big_alloc<T>>;template<typename Key,typename Value,typename Compare=std::less<Key>>using big_map=std::map<Key,Value,Compare,big_alloc<std::pair<const Key,Value>>>;using big_string=big_basic_string<char>;template<typename T>using big_stack=std::stack<T,big_deque<T>>;template<typename T>using big_queue=std::queue<T,big_deque<T>>;template<typename T>using big_priority_queue=std::priority_queue<T,big_vector<T>>;}
2626
#endif

0 commit comments

Comments
 (0)