快速幂
读入量大于1e5不要用cin读入,要用也要关闭同步流
第i个o次方的父亲
#include<bits/stdc++.h>usingnamespacestd;
#definemaxn 110000#definell long longintn, a[maxn], f[maxn][40];
intquery(intl, intr){
intk = (int)(log((r - l + 1) * 1.0) / log(2.0));
returnmin(f[l][k], f[r - (1<< k) + 1][k]);
}
intmain(){
scanf("%d", &n);
for(inti = 1; i <= n; ++ i )
scanf("%d", &a[i]), f[i][0] = a[i];
for(intj = 1; j <= (int)(log(n * 1.0) / log(2.0)); ++ j )
for(inti = 1; i + (1<< j) - 1<= n; ++ i )
f[i][j] = min(f[i][j - 1], f[i + (1<< (j - 1))][j - 1]);
intq;
scanf("%d", q);
while(q -- )
{
intl, r;
scanf("%d%d", &l, &r);
printf("%d\n", query(l, r));
}
return0;
}
#include<bits/stdc++.h>usingnamespacestd;
#definemaxn 110000#definell long longintn, a[maxn], f[maxn][40];
intquery(intl, intr){
intk = (int)(log((r - l + 1) * 1.0) / log(2.0));
returnmin(f[l][k], f[r - (1<< k) + 1][k]);
}
intmain(){
scanf("%d", &n);
for(inti = 1; i <= n; ++ i )
scanf("%d", &a[i]), f[i][0] = a[i];
for(intj = 1; j <= (int)(log(n * 1.0) / log(2.0)); ++ j )
for(inti = 1; i + (1<< j) - 1<= n; ++ i )
f[i][j] = min(f[i][j - 1], f[i + (1<< (j - 1))][j - 1]);
intq;
scanf("%d", q);
while(q -- )
{
intl, r;
scanf("%d%d", &l, &r);
printf("%d\n", query(l, r));
}
return0;
}