求助,开O2全WA,不开能AC
查看原帖
求助,开O2全WA,不开能AC
190701
wloving楼主2023/5/18 11:47

如题。头要挠秃了。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll st[N][20];
int M,n;
ll D;

ll query(int L){//查询最后L个数中的最大值
	int k=log2(L);
	int l=n-L+1;//查询区间[l,n]
	return max(st[l][k],st[n-(1<<k)+1][k]);
}
void upd(ll x){//将x加入数列末尾,并更新st表
	st[++n][0]=x;
	//只需要更新受影响的区间  O(logn)
	for(int j=1;(1<<j)<=n;j++){
		int L=n-(1<<j)+1;//[L,n]
		st[L][j]=max(st[L][j-1],st[L+(1<<(j-1))][j-1]);
	}
}
int main(){
	char c;
	ll x,t;
	cin>>M>>D;
	for(int i=1;i<=M;i++){
		cin>>c>>x;
		if(c=='A'){
			upd(((x+t)%D+D)%D);
		}else{
			t=query(x);
			cout<<t<<endl;
		}
	}
	return 0;
}
2023/5/18 11:47
加载中...