【模板】 ST表
1 void ST(int n) { 2 for (int i = 1; i <= n; i++) 3 dp[i][0] = A[i]; 4 for (int j = 1; (1 << j) <= n; j++) { 5 for (int i = 1; i + (1 << j) - 1 <= n; i++) { 6 dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]); 7 } 8 } 9 } 10 int RMQ(int l, int r) { 11 int k = 0; 12 while ((1 << (k + 1)) <= r - l + 1) k++; 13 return max(dp[l][k], dp[r - (1 << k) + 1][k]); 14 }
1 #include<bits/stdc++.h> 2 #define maxn 100010 3 using namespace std; 4 int stmin[maxn][20]; 5 int stmax[maxn][20]; 6 int n,m; 7 void st(){ 8 for(int j=1;(1<<j)<=n;j++) 9 for(int i=1;i+(1<<i)-1 <= n ;i++){ 10 stmin[i][j] =min(stmin[i][j-1],stmin[i+(1<<(j-1))][j-1]); 11 stmax[i][j] =min(stmax[i][j-1],stmax[i+(1<<(j-1))][j-1]); 12 } 13 } 14 int rmq_max (int l,int r){ 15 int k=0; 16 while(( 1<<(k+1) ) <=(r-l+1) ) k++; 17 return max(stmax[l][k],stmax[r-(1<<k)+1][k]); 18 } 19 int rmq_min (int l,int r){ 20 int k=0; 21 while(( 1<<(k+1) ) <=(r-l+1) ) k++; 22 return min(stmin[l][k],stmin[r-(1<<k)+1][k]); 23 } 24 int main(void){ 25 cin>>n>>m; 26 for(int i=1;i<=n;i++) cin>>stmin[i][0]; 27 st(); 28 for(int i=1;i<m-1;i++) cout<<0<<endl; 29 for(int i=m;i<=n+1;i++){ 30 cout<<rmq_min(i-m,i)<<endl; 31 } 32 }
困得不行,可能是个傻逼错误qwq
改天再改
“胡须如草芥疯长,悲欢不过梦一场”