Skip to content

Commit

Permalink
xor range
Browse files Browse the repository at this point in the history
  • Loading branch information
ttamx committed Nov 27, 2024
1 parent 5b2c873 commit 67dfe4e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions content/various/chapter.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ \chapter{Various}
\kactlimport{GaussianElimination.hpp}
\kactlimport{BinaryTrie.hpp}
\kactlimport{InfixPropostfix.hpp}
\kactlinport{xor_range.hpp}

\section{LP Duality}
\import{lp_dual.tex}

\section{Optimization tricks}
\verb@__builtin_ia32_ldmxcsr(40896);@ disables denormals (which make floats 20x slower near their minimum value).
Expand Down
10 changes: 10 additions & 0 deletions content/various/lp_dual.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\begin{tabular}{c|c}
Maximization & Minimization \\
\hline
Inequality constraint $\le$ & Nonnegative variable $\ge$ \\
Inequality constraint $\ge$ & Nonpositive variable $\le$ \\
Equality constraint $=$ & Free variable \\
Nonnegative variable $\ge$ & Inequality constraint $\ge$ \\
Nonpositive variable $\le$ & Inequality constraint $\le$ \\
Free variable & Equality constraint $=$ \\
\end{tabular}
26 changes: 26 additions & 0 deletions content/various/xor_range.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

/**
* Author: Teetat T.
* Date: 2024-11-27
* Description: find all range of $x$ such that $l \le x$ xor $p < r$.
*/

template<class F>
void xor_range(ll p,ll l,ll r,const F &query){
for(int i=0;i<60;i++){
if(l==r)break;
ll b=1LL<<i;
if(l&b){
query(l^p,(l^p)+b);
l+=b;
}
if(r&b){
r-=b;
query(r^p,(r^p)+b);
}
if(p&b){
p^=b;
}
}
}

0 comments on commit 67dfe4e

Please sign in to comment.