1 条题解

  • -1
    @ 2025-12-26 8:44:42

    这题好像有比较巧妙的单调做法,但它都强制在线了直接线段树尊重一下,按题意模拟即可。

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #define int long long
    #define lc (x<<1)
    #define rc ((x<<1)|1)
    #define mid ((l+r)>>1)
    using namespace std;
    const int N=2e5+17;
    int n,m,sum[4*N],k;
    void change(int x,int l,int r,int from,int to,int v){
    	if(from<=l&&r<=to){
    		sum[x]=v;return;
    	}
    	if(from<=mid) change(lc,l,mid,from,to,v);
    	if(to>mid) change(rc,mid+1,r,from,to,v);
    	sum[x]=max(sum[lc],sum[rc]);
    }
    int query(int x,int l,int r,int from,int to){
    	if(from<=l&&r<=to){
    		return sum[x];
    	}int res=0;
    	if(from<=mid) res=max(res,query(lc,l,mid,from,to));
    	if(to>mid) res=max(res,query(rc,mid+1,r,from,to));
    	return res;
    }int top=0,ans=0;
    signed main(){
    	//freopen("C.in","r",stdin);
    	//freopen("c.out","w",stdout);
    	ios::sync_with_stdio(0);
    	cin.tie(0), cout.tie(0);
    	cin >> n >> m;
    	for(int i=1;i<=n;i++){
    		char op;int x;
    		cin >> op >> x;
    		if(op=='A'){
    			top++;//记录当前的最后位置 
    			change(1,1,n,top,top,(x+ans)%m);//鄙人不会写单点修改说是 
    		}else{
    			int res=query(1,1,n,top-x+1,top);
    			ans=res;cout << res << '\n';//处理强制在线 
    		}
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    122
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    (无)
    递交数
    21
    已通过
    15
    上传者