ST表求调
2026-02-04 09:59:28
发布于:上海
20阅读
0回复
0点赞
为什么洛谷过了,这里过不了?
#include<bits/stdc++.h>
using namespace std;
long long q,d,t,n,a[200005],Log[200005],st[200005][20];
void init()
{
Log[1]=0;
for(int i=2;i<=200000;i++)Log[i]=Log[i/2]+1;
return;
}
int main()
{
cin>>q>>d;
init();
while(q--)
{
char op;
cin>>op;
if(op=='A')
{
n++;
cin>>st[n][0];
st[n][0]=(st[n][0]+t)%d;
for(int i=1;i<=Log[n];i++)st[n-(1<<i)+1][i]=max(st[n-(1<<i)+1][i-1],st[n-(1<<(i-1))+1][i-1]);
}
else
{
int x;
cin>>x;
t=max(st[n-x+1][Log[x]],st[n-(1<<Log[x])+1][Log[x]]);
cout<<t<<endl;
}
}
return 0;
}
这里空空如也



有帮助,赞一个