1 条题解
-
0
ST表模板题
竟然用了快读 逃#include<cstdio> #include<algorithm> using namespace std; #define maxn 200005 #define maxm 21 int f[maxn][maxm]; int logn[maxn]; int n,m; void pre() { logn[1]=0; logn[2]=1; for(int i=3; i<maxn; i++) logn[i]=logn[i>>1]+1; } int read() { int x=0,f=1; char ch=getchar(); while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } while (ch>='0'&&ch<='9') { x=x*10+ch-48; ch=getchar(); } return x*f; } int x,y; int main() { n=read(); m=read(); pre(); for(int i=1; i<=n; i++)f[i][0]=read(); for (int j = 1; j < maxm; j++) for (int i = 1; i + (1 << j) - 1 <= n; i++) f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]); for (int i = 1; i <= m; i++) { int x = read(), y = read(); int s = logn[y - x + 1]; printf("%d\n", max(f[x][s], f[y - (1 << s) + 1][s])); } return 0; }
- 1
信息
- ID
- 7893
- 时间
- 800ms
- 内存
- 125MiB
- 难度
- 3
- 标签
- 递交数
- 72
- 已通过
- 23
- 上传者