for(int j=1;j<=log[n];j++){
    for(int i=1;i+(1<<j)-1<=n;i++){
        f[i][j]=min(f[i][j-1],f[i+(1<<j-1)][j-1]);
    }
}