比赛 2026.9.5 评测结果 AAAAAAAAAAAAAAA
题目名称 To-Do List 最终得分 100
用户昵称 dream 运行时间 11.326 s
代码语言 C++ 内存使用 73.77 MiB
提交时间 2026-09-05 11:02:13
显示代码纯文本
#include<bits/stdc++.h>
#define ls p*2
#define rs p*2+1
using namespace std;
typedef long long ll;
const int N=1000005,V=1e6;
const ll mod=1e6+3;
int q,cnt;
ll ans;
struct input{
	int s,t;
}in[N];
struct node{
	int l,r;
	ll ld,len,air;
}tr[N*4];
void build(int p,int l,int r){
	tr[p]={l,r,l,0,0};
	if(l==r) return;
	int mid=(l+r)/2;
	build(ls,l,mid);
	build(rs,mid+1,r);
}
void merge(node &p,node l,node r){
	if(l.len==0||r.len==0){
		int ll=p.l,rr=p.r;
		if(l.len==0) p=r;
		if(r.len==0) p=l;
		p.l=ll,p.r=rr;
		return;
	}
	ll lrd=l.ld+l.len-1;
	p.ld=l.ld;
	if(r.ld<=lrd){
		ll airr=r.air;
		ll tmp=lrd+1-r.ld;
		ll tt=tmp-r.air;
		
		if(tt>=0){
			p.len=r.ld+r.len-1-l.ld+1+tt;
			p.air=l.air;
		}
		else{
			p.len=r.ld+r.len-1-l.ld+1;
			p.air=l.air+r.air-tmp;
		}
	}
	else{
		p.len=r.ld+r.len-1-l.ld+1;
		p.air=r.ld-lrd-1+l.air+r.air;
	}
}
void pushup(int p){
	merge(tr[p],tr[ls],tr[rs]);
}
void update(int p,int x,ll v){
	if(tr[p].l==tr[p].r){
		tr[p].len+=v;
		return; 
	}
	int mid=(tr[p].l+tr[p].r)/2;
	if(x<=mid){
		update(ls,x,v);
	}
	else update(rs,x,v);
	pushup(p);
}
int main(){
	freopen("List.in","r",stdin);
	freopen("List.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>q;
    build(1,1,V);
    for(int i=1;i<=q;i++){
    	char op;
    	cin>>op;
    	int x,y;
    	if(op=='A'){
    		cin>>x>>y;
    		x=(x+ans)%mod;
    		y=(y+ans)%mod;
    		update(1,x,y);
    		in[++cnt]={x,y};
		}
		else{
			cin>>x;
			x=(x+ans)%mod;
			update(1,in[x].s,-in[x].t);
		}
		node anss=tr[1];
		ans=anss.ld+anss.len-1;
		cout<<ans<<"\n";
	}
    return 0;
}