# 解析：

### 思路：

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline int getint(){
re int num;
re char c;
while(!isdigit(c=gc()));num=c^48;
while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
return num;
}

inline void outint(int a){
static char ch[23];
if(a==0)pc('0');
while(a)ch[++ch[0]]=a-a/10*10,a/=10;
while(ch[0])pc(ch[ch[0]--]^48);
}

inline char getalpha(){
re char c;
while(!isalpha(c=gc()));
return c;
}

cs int N=1000006;
int block[N];
int B;
int a[N];
int b[N];
int n,q;

inline void sort(int x){
int l=(x-1)*B+1,r=min(x*B,n);
for(int re i=l;i<=r;++i)b[i]=a[i];
sort(b+l,b+r+1);
}

inline int find(int x,int v){
int l=(x-1)*B+1,r=min(x*B,n);
int last=r;
while(l<=r)
{
int mid=(l+r)>>1;
if(b[mid]<v)l=mid+1;
else r=mid-1;
}
return last-l+1;
}

inline int query(int l,int r,int v){
int ans=0;
if(block[l]==block[r]){
for(int re i=l;i<=r;++i)
return ans;
}
return ans;
}

inline void update(int l,int r,int v){
if(block[l]==block[r]){
for(int re i=l;i<=r;++i)a[i]+=v;
sort(block[l]);
return ;
}
for(int re i=l;block[i]==block[l];++i)a[i]+=v;sort(block[l]);
for(int re i=r;block[i]==block[r];--i)a[i]+=v;sort(block[r]);
}

signed main(){
n=getint();q=getint();
B=sqrt(n);
for(int re i=1;i<=n;++i){
a[i]=getint();
block[i]=(i-1)/B+1;
}
for(int re i=1;i<=n/B+(n%B!=0);++i)sort(i);
while(q--){
char op=getalpha();int l=getint(),r=getint(),v=getint();
(op=='M')?(update(l,r,v)):(outint(query(l,r,v)),(void)pc('\n'));
}
return 0;
}

posted on 2018-10-14 16:14  zxyoi_dreamer  阅读(96)  评论(0编辑  收藏