萌新求助 24pts
查看原帖
萌新求助 24pts
294875
Oildum楼主2022/1/26 17:54

用了我们老师给的板子+快读板子+输入输出,然后后面9个点全部RE

显示是Segmentation Fault 11,非法内存访问

计算了一下开这个大小应该没问题

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 100010;
const int MAXT = 24;
int a[MAXN], st[MAXN][MAXT];
inline 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;
}
void build_st(int *a, int n)
{
    for (int i = 1; i <= n; i++) st[i][0] = a[i];
    for (int j = 1; (1 << j) <= n; j++)
    {
        for (int i = 1; i <= n; i++)
        {
            st[i][j] = max(st[i][j-1], st[i + (1 << (j - 1))][j - 1]);
        }
    }
}
int query(int l, int r)
{
    int k = (int)(__lg(r - l + 1));
    return max(st[l][k], st[r - (1 << k) + 1][k]);
}
signed main()
{
    int n, m;
    n = read(), m = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    build_st(a, n);
    for (int i = 1; i <= m; i++)
    {
        int l = read();
        int r = read();
        printf("%d\n", query(l, r));
    }
    return 0;
}
2022/1/26 17:54
加载中...