?
by andyli @ 2020-03-23 14:07:04
@[andyli](/user/84282) ?求帮改
by bovine__kebi @ 2020-03-23 14:07:30
比如我输入一串数字,然后开始输入l,r,刚输入完一组l,r,他就给我自动加了一个数字,还删不掉
by bovine__kebi @ 2020-03-23 14:08:19
及其谔谔
by bovine__kebi @ 2020-03-23 14:08:29
那是输出的结果
by andyli @ 2020-03-23 14:09:05
另外: `printf("%d\n",search(l,r));`
by andyli @ 2020-03-23 14:09:16
谢谢,我去改改
by bovine__kebi @ 2020-03-23 14:12:26
@[bovine__kebi](/user/294736) 你没有输出换行符
by IntrepidStrayer @ 2020-03-23 14:12:27
我记得我输出了换行也是错的。。。
by bovine__kebi @ 2020-03-23 14:12:55
```cpp
#include<bits/stdc++.h>
using namespace std;
int a[101000];
int st[101000][30];
inline int read()
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void init(int n)
{
memset(st,0,sizeof(st));
for (int i = 1; i <= n; i++)
st[i][0] = a[i];
for (int i = 1; (1 << i) <= n; i++)
{
for (int j = 1; j + (1 << i) - 1 <= n; ++j)
st[j][i] = max(st[j][i - 1],st[j + (1 << (i - 1))][i - 1]);
}
}
int search(int l, int r)
{
int k=log2(r-l+1);
return max(st[l][k],st[r - (1 << k) + 1][k]);
}
int main()
{
int n,m;
n=read();
m=read();
for (int i = 0; i < n; i++)
a[i]=read();
init(n);
for(int i=1;i<=m;i++)
{
int l, r;
l=read();
r=read();
printf("%d\n",search(l,r));
}
return 0;
}
```
还是错的为什么。。。
by bovine__kebi @ 2020-03-23 14:50:20