树状数组 WA 求条能过样例
查看原帖
树状数组 WA 求条能过样例
1226952
Cosine_Func楼主2024/9/15 13:06
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define endl '\n'
#define itn int
#define pi pair<int,int>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int N=2e5+5;
int m,d,l,n,p,a[N],t[N];
char op;
int lowbit(int x){
	return x&(-x);
}
void update(itn x,int k){
	a[x]=k; 
	for(int i=x;i<=n;i+=lowbit(i)){
        t[i]=max(t[i],k);
    }
}
int ask(int l,int r){
	int ans=0;
	while(l<=r){
        ans=max(ans,a[r]);
        r--;
		while(r-lowbit(r)>=l){
			ans=max(ans,t[r]);
			r-=lowbit(r);
		}
	}
	return ans;
}
inline void Solve(){
	cin>>m>>d;
	for(int i=1;i<N;i++)
		update(i,-0x7fffffff);
	while(m--){
		cin>>op>>l;
		if(op=='Q')
			p=ask(n-l+1,n),cout<<p<<endl;
		if(op=='A')
			update(++n,(p+l)%d);
	}
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int T=1;
    //cin>>T;
    while(T--)
    	Solve();
    return 0;
}

2024/9/15 13:06
加载中...