比赛 |
2025.5.24 |
评测结果 |
AAAAAAAAAA |
题目名称 |
魔法传输 |
最终得分 |
100 |
用户昵称 |
徐诗畅 |
运行时间 |
0.806 s |
代码语言 |
C++ |
内存使用 |
5.53 MiB |
提交时间 |
2025-05-24 08:25:31 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,m,t[N<<2],tag[N<<2];
void push_up(int p){t[p]=t[p<<1]+t[p<<1|1];}
void addtag(int p,int l,int r,int d){
t[p]+=(r-l+1)*d;
tag[p]+=d;
}
void push_down(int p,int l,int r){
if(tag[p]!=0){
int mid=(l+r)>>1;
addtag(p<<1,l,mid,tag[p]);
addtag(p<<1|1,mid+1,r,tag[p]);
tag[p]=0;
}
}
void update(int p,int l,int r,int L,int R,int d){
if(L<=l&&R>=r){
addtag(p,l,r,d);
return;
}
int mid=(l+r)>>1;
push_down(p,l,r);
if(L<=mid) update(p<<1,l,mid,L,R,d);
if(R>mid) update(p<<1|1,mid+1,r,L,R,d);
push_up(p);
}
int query(int p,int l,int r,int L,int R){
if(L<=l&&R>=r) return t[p];
int mid=(l+r)>>1;
push_down(p,l,r);
int ans=0;
if(L<=mid) ans+=query(p<<1,l,mid,L,R);
if(R>mid) ans+=query(p<<1|1,mid+1,r,L,R);
return ans;
}
signed main(){
freopen("magics.in","r",stdin);
freopen("magics.out","w",stdout);
scanf("%lld%lld",&n,&m);
while(m--){
char op; int l,r,x;
cin>>op;
if(op=='C'){
scanf("%lld%lld",&l,&r);
update(1,1,n,l,l,1);
update(1,1,n,l+1,r,1);
update(1,1,n,r+1,r+1,-(1+(r-l)));
}
else{
scanf("%lld",&x);
printf("%lld\n",query(1,1,n,1,x));
}
}
return 0;
}