比赛 |
2025.5.24 |
评测结果 |
AAAAAAAAAA |
题目名称 |
魔法传输 |
最终得分 |
100 |
用户昵称 |
李金泽 |
运行时间 |
0.247 s |
代码语言 |
C++ |
内存使用 |
2.23 MiB |
提交时间 |
2025-05-24 09:24:35 |
显示代码纯文本
#include<cstdio>
#include<cstdlib>
#define N 100005
#define ll long long
using namespace std;
int n,m,x,y;ll t1[N],t2[N];const ll mod=1e9+7;char op[2];
void ud1(int x,ll k){while(x<=n)t1[x]=(t1[x]+k)%mod,x+=x&-x;}
void ud2(int x,ll k){while(x<=n)t2[x]=(t2[x]+k)%mod,x+=x&-x;}
void ud(int x,int y){ud1(x,1);ud1(y+1,-1);ud2(x,x-1);ud2(y+1,1-x);}
ll q1(int x){ll sum=0;while(x)sum=(sum+t1[x])%mod,x&=x-1;return sum;}
ll q2(int x){ll sum=0;while(x)sum=(sum+t2[x])%mod,x&=x-1;return sum;}
ll q(int x){return (x*q1(x)-q2(x))%mod;}
int main(){
freopen("magics.in","r",stdin);freopen("magics.out","w",stdout);
scanf("%d%d",&n,&m);
while(m--)
{
scanf("%s%d",op,&x);
if(op[0]=='C')scanf("%d",&y),ud(x,y);
else printf("%lld\n",q(x));
}
return 0;
}