sq表
作者:互联网
#include <iostream> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; int dp[50005][31][2]; int main() { ios::sync_with_stdio(false); int n,m;cin>>n>>m; for(int i=1;i<=n;i++){ cin>>dp[i][0][0]; for(int j=0;j<=30;j++) dp[i][0][1]=100000000; dp[i][0][1]=dp[i][0][0]; } for(int j=1;j<=30;j++) for(int i=1;i+(1<<j)<=n+1;i++){ dp[i][j][0]=min(dp[i][j-1][0],dp[i+(1<<(j-1))][j-1][0]); dp[i][j][1]=max(dp[i][j-1][1],dp[i+(1<<(j-1))][j-1][1]); } while(m--){ int l,r; cin>>l>>r; int k=log2(r-l+1); cout<<max(dp[l][k][1],dp[r-(1<<k)+1][k][1])-min(dp[l][k][0],dp[r-(1<<k)+1][k][0])<<"\n"; } }
标签:std,int,sq,long,include,stdio,dp 来源: https://www.cnblogs.com/qq1415584788/p/14691103.html