1 条题解

  • 4
    @ 2024-8-9 15:00:58
    #include<bits/stdc++.h>
    using namespace std;
    
    int a[200005],st[200005];
    
    int main(){
    	int m,p,lt=0,n=0,top=0;
    	cin>>m>>p;
    	while(m--){
    		char c;
    		cin>>c;
    		if(c=='A'){
    			int x;
    			cin>>x;
    			a[++n]=(x+lt)%p;
    			while(top&&a[st[top]]<=a[n])top--;
    			st[++top]=n;
    		}
    		else{
    			int L;
    			cin>>L;
    			int l=1,r=top,res=1;
    			while(l<=r){
    				int mid=l+r>>1;
    				if(st[mid]>=n-L+1)res=mid,r=mid-1;
    				else l=mid+1;
    			}
    			lt=a[st[res]];
    			cout<<a[st[res]]<<"\n";
    		}
    	}
    	return 0;
    } 
    

    信息

    ID
    756
    时间
    1000ms
    内存
    512MiB
    难度
    7
    标签
    递交数
    29
    已通过
    9
    上传者