标签:name tps code clu through return span scanf space
光写板子好像不太好
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define int long long using namespace std; int n,k,a[100050],dp1[100050][55],dp2[100050][55]; void init() { for(int i=1;i<=n;i++)dp1[i][0]=a[i]; for(int j=1;(1<<j)<=n;j++) for(int i=1;i+(1<<j)-1<=n;i++) dp1[i][j]=min(dp1[i][j-1],dp1[i+(1<<j-1)][j-1]); for(int i=1;i<=n;i++)dp2[i][0]=a[i]; for(int j=1;(1<<j)<=n;j++) for(int i=1;i+(1<<j)-1<=n;i++) dp2[i][j]=max(dp2[i][j-1],dp2[i+(1<<j-1)][j-1]); } int maxnum(int l,int r) { int k=log2(r-l+1); return max(dp2[l][k],dp2[r-(1<<k)+1][k]); } int minnum(int l,int r) { int k=log2(r-l+1); return min(dp1[l][k],dp1[r-(1<<k)+1][k]); } signed main() { scanf("%lld%lld",&n,&k); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); init(); for(int i=1;i<=n-k+1;i++) printf("%lld %lld\n",maxnum(i,i+k-1),minnum(i,i+k-1)); return 0; }
标签:name tps code clu through return span scanf space
原文地址:https://www.cnblogs.com/qxds/p/11468580.html