Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LG (17)
- #define MX (1<<LG)
- #define P2(v) (!(v&(v-1)))
- int dp[MX][LG+2],G[MX],XX,O=-1;
- void ini(int *A,int n){
- if(!XX++)FT(1,MX)G[k]=O+=P2(k);
- F(n)dp[i][0]=i;
- FT(1,k-(1<<k)+n+1)F(n+1-(1<<k))
- if(A[dp[i][k-1]]<A[dp[i+(1<<(k-1))][k-1]])
- dp[i][k]=dp[i][k-1];
- else dp[i][k]=dp[i+(1<<(k-1))][k-1];
- }
- int qy(int *A,int L,int R){
- int j(G[R-L+1]);
- if(A[dp[L][j]]<=A[dp[R-(1<<j)+1][j]])
- return A[dp[L][j]];
- return A[dp[R-(1<<j)+1][j]];
- }
- \end{lstlisting}
- Obdobně maxium
- \begin{lstlisting}[language=C++]
- int dp[MX][LG+2],G[MX],XX,O=-1;
- void ini(int *A,int n){
- if(!XX++)FT(1,MX)G[k]=O+=P2(k);
- F(n)dp[i][0]=i;
- FT(1,k-(1<<k)+n+1)F(n+1-(1<<k))
- if(A[dp[i][k-1]]>A[dp[i+(1<<(k-1))][k-1]])
- dp[i][k]=dp[i][k-1];
- else dp[i][k]=dp[i+(1<<(k-1))][k-1];
- }
- int qy(int *A,int L,int R){
- int j(G[R-L+1]);
- if(A[dp[L][j]]>=A[dp[R-(1<<j)+1][j]])
- return A[dp[L][j]];
- return A[dp[R-(1<<j)+1][j]];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement