Link:
Luogu https://www.luogu.com.cn/problem/P3865
一开始没想到log可以预处理
然后没想到预处理可以不用o(nlogn)
然后以为被卡读入了
结果是cout被卡了,关同步也没用
wysl(双关)
那挺刺激的 棒棒哒
好久没写frBB辣
意外地记得还挺牢就不做笔记了真是非常抱歉
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
#define getchar() (frS==frT&&(frT=(frS=frBB)+fread(frBB,1,1<<12,stdin),frS==frT)?EOF:*frS++)
char frBB[1<<12], *frS=frBB, *frT=frBB;
const int MAXN = 1e5 + 10;
const int LOGN = 25;
//#define log2(x) (31-__builtin_clz(x))
int n, m;
int a[MAXN];
int st[LOGN][MAXN];
int la[MAXN];
char wch;
int xx;
void fstread()
{
xx = 0;
wch = getchar();
while (!isdigit(wch)) wch = getchar();
while (isdigit(wch)) xx = xx * 10 + (wch ^ 48), wch = getchar();
}
#define fuc(n) fstread(),n=xx
int main()
{
fuc(n); fuc(m);
la[0] = -1;
for (int i = 1; i <= n; ++i)
{
fuc(st[0][i]);
la[i] = la[i-1];
if(!(i&(i-1))) ++la[i];
}
for (int tn, kk, j = 1; j <= 20; ++j)
{
tn = n - (1 << j) + 1;
kk = 1 << (j - 1);
for (int i = 1; i <= tn; ++i)
{
st[j][i] = max(st[j-1][i], st[j-1][i+kk]);
}
}
for (int li, ri, laa, i = 1; i <= m; ++i)
{
fuc(li); fuc(ri);
laa = la[ri-li+1];
printf("%d
", max(st[laa][li], st[laa][ri-(1<<laa)+1]));
}
return 0;
}