| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAAAAAAAAAA |
| 题目名称 |
To-Do List |
最终得分 |
100 |
| 用户昵称 |
默 |
运行时间 |
11.940 s |
| 代码语言 |
C++ |
内存使用 |
50.85 MiB |
| 提交时间 |
2026-09-05 09:16:30 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX (int)(1e18)
const int N=1e6+10;
const int maxv=1e6+2;
const int mod=1e6+3;
int n;
int cnt[N],a[N],b[N];
inline int read(){
int t=0,f=1;
register char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?(-1):(f),c=getchar();
while(c>='0'&&c<='9') t=(t<<3)+(t<<1)+(c^48),c=getchar();
return t*f;
}
struct Tree{
#define mid (l+r>>1)
int tr[N<<2],tr1[N<<2];
//tr:max tr1:sum_suf
void pushup(int p){
tr[p]=max(tr[p<<1],tr[p<<1|1])+tr1[p];
}
void build(int p,int l,int r){
tr[p]=-INT_MAX;
if(l==r) return;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
}
void update(int p,int l,int r,int L,int R,int x){
if(L<=l&&R>=r) return (void)(tr[p]+=x,tr1[p]+=x);
if(L<=mid) update(p<<1,l,mid,L,R,x);
if(R>mid) update(p<<1|1,mid+1,r,L,R,x);
pushup(p);
}
void update1(int p,int l,int r,int x,bool f){
if(l==r) return (void)(tr[p]=f?x+tr1[p]:-INT_MAX);
if(x<=mid) update1(p<<1,l,mid,x,f);
else update1(p<<1|1,mid+1,r,x,f);
pushup(p);
}
#undef mid
}Tr;
signed main(){
freopen("List.in","r",stdin);
freopen("List.out","w",stdout);
Tr.build(1,0,maxv);
int T=read(),las=0,Cnt=0;
for(int i=1;i<=T;i++){
char op=getchar();
while(op!='A'&&op!='D') op=getchar();
if(op=='A'){
a[++Cnt]=read(),b[Cnt]=read();
a[Cnt]=(a[Cnt]+las)%mod,b[Cnt]=(b[Cnt]+las)%mod;
if(!b[Cnt]) continue;
Tr.update(1,0,maxv,0,a[Cnt],b[Cnt]);
cnt[a[Cnt]]++;
if(cnt[a[Cnt]]==1) Tr.update1(1,0,maxv,a[Cnt],1);
}else{
int x=read();x=(x+las)%mod;
if(!b[x]) continue;
Tr.update(1,0,maxv,0,a[x],-b[x]);
cnt[a[x]]--;
if(!cnt[a[x]]) Tr.update1(1,0,maxv,a[x],0);
}
las=Tr.tr[1]-1;
cout<<las<<"\n";
}
return 0;
}