| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAAAAAEAAAA |
| 题目名称 |
To-Do List |
最终得分 |
93 |
| 用户昵称 |
zcx |
运行时间 |
14.586 s |
| 代码语言 |
C++ |
内存使用 |
92.05 MiB |
| 提交时间 |
2026-09-05 11:53:38 |
显示代码纯文本
#include<bits/stdc++.h>
#define lson p * 2
#define rson p * 2 + 1
#define int long long
using namespace std;
const int N = 1e6 + 5;
const int INF = 1e18;
const int key = 1e6 + 3;
struct tree{
int l,r,maxn,tag;
} tr[4 * N];
int q,tot = 0,n,ans = 0;
int s[N],t[N],a[N],c[N];
void aad(int x,int k){
while(x <= n){
c[x] += k;
x += x & -x;
}
}
int ask(int x){
int sum = 0;
while(x){
sum += c[x];
x -= x & -x;
}
return sum;
}
void build(int p,int L,int R){
tr[p].l = L;tr[p].r = R;tr[p].maxn = -INF;tr[p].tag = 0;
if(L == R) return;
int mid = (L+R)>>1;
build(lson,L,mid);build(rson,mid + 1,R);
}
void ad(int p,int x,int k){
if(tr[p].l == tr[p].r){
tr[p].maxn = k - tr[p].tag;
return ;
}
if(x <= tr[lson].r) ad(lson,x,k - tr[p].tag);
else ad(rson,x,k - tr[p].tag);
tr[p].maxn = max(tr[lson].maxn + tr[lson].tag,tr[rson].maxn + tr[rson].tag);
}
void add(int p,int x,int y,int k){
if(tr[p].l >= x && tr[p].r <= y) {
tr[p].tag += k;
return;
}
if(x <= tr[lson].r) add(lson,x,y,k);
if(y > tr[lson].r) add(rson,x,y,k);
tr[p].maxn = max(tr[lson].maxn + tr[lson].tag,tr[rson].maxn + tr[rson].tag);
}
void change(int p,int x){
if(tr[p].l == tr[p].r){
tr[p].maxn = -INF;
return;
}
if(x <= tr[lson].r) change(lson,x);
else change(rson,x);
tr[p].maxn = max(tr[lson].maxn + tr[lson].tag,tr[rson].maxn + tr[rson].tag);
}
signed main()
{
freopen("List.in","r",stdin);
freopen("List.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>q;n = N - 5;
build(1,1,n);
while(q--){
char op;cin>>op;
if(op == 'A'){
tot++;cin>>s[tot]>>t[tot];
s[tot] = (s[tot] + ans) % key;t[tot] = (t[tot] + ans) % key;
if(s[tot] < n) add(1,s[tot] + 1,n,-t[tot]);
if(!a[s[tot]]) ad(1,s[tot],s[tot] - (ask(s[tot]) + 1));
a[s[tot]]++;aad(s[tot],t[tot]);
ans = ask(n) + max((int)0,tr[1].maxn + tr[1].tag);
cout<<ans<<'\n';
}else{
int x;
cin>>x;x = (x + ans) % key;aad(s[x],-t[x]);a[s[x]]--;
if(!a[s[x]]) change(1,s[x]);
add(1,s[x] + 1,n,t[x]);
ans = ask(n) + max((int)0,tr[1].maxn + tr[1].tag);
cout<<ans<<'\n';
}
}
return 0;
}