1 void RMQ_Init(const vector<int>& A) 2 { 3 int n=A.size(); 4 for (int i=0;i<n;i++) d[i][0]=A[i]; 5 for (int j=1;(1<<j)<=n;j++) 6 for (int i=0;i+(1<<j)-1<n;i++) 7 d[i][j]=min(d[i][j-1],d[i+(1<<(j-1))][j-1]); 8 } 9 10 int RMQ(int L,int R)11 {12 int k=0;13 for (k=0;1<<(k+1)<=R-L+1;k++);14 return min(d[L][k],d[R-(1<<k)+1][k]); 15 }
RMQ 模板一份
时间: 2024-10-14 19:03:06