1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #define ll long long using namespace std; namespace Ehnaev{ inline ll read() { ll ret=0,f=1;char ch=getchar(); while(ch<48||ch>57) {if(ch==45) f=-f;ch=getchar();} while(ch>=48&&ch<=57) {ret=(ret<<3)+(ret<<1)+ch-48;ch=getchar();} return ret*f; } inline void write(ll x) { static char buf[22];static ll len=-1; if(x>=0) {do{buf[++len]=x%10+48;x/=10;}while(x);} else {putchar(45);do{buf[++len]=-(x%10)+48;x/=10;}while(x);} while(len>=0) putchar(buf[len--]); } }using Ehnaev::read;using Ehnaev::write; inline void writeln(ll x) {write(x);putchar(10);}
const ll N=2e6,M=2e3,L=2e3;
ll n,m,nn; ll a[N+5],pos[N+5];
struct node{ ll val,id; inline node() {} inline node(ll x,ll y):val(x),id(y){} inline bool operator<(const node& rhs) const{return val<rhs.val;} };
struct Block{node a[M+5];ll l,r,laz;}blo[L+5];
int main() {
n=read();m=read(); nn=max(1ll,(ll)sqrt(n)); for(ll i=1;i<=n;i++) {a[i]=read();} for(ll i=1,cnt=1;i<=n;i+=nn,cnt++) { blo[cnt].l=i;blo[cnt].r=i+nn-1;if(blo[cnt].r>n) blo[cnt].r=n; for(ll j=blo[cnt].l,k=1;j<=blo[cnt].r;j++,k++) { blo[cnt].a[k].val=a[j];blo[cnt].a[k].id=j;pos[j]=cnt; } ll len=blo[cnt].r-blo[cnt].l+1; sort(blo[cnt].a+1,blo[cnt].a+len+1); }
while(m--) { char op[5];cin>>op; ll l,r,k;l=read();r=read();k=read(); if(op[0]=='M') { if(pos[l]==pos[r]) { ll len=blo[pos[l]].r-blo[pos[l]].l+1; for(ll i=1;i<=len;i++) { if(blo[pos[l]].a[i].id>=l&&blo[pos[l]].a[i].id<=r) { blo[pos[l]].a[i].val+=k; } } sort(blo[pos[l]].a+1,blo[pos[l]].a+len+1); } else { if(l==blo[pos[l]].l) {blo[pos[l]].laz+=k;} else { ll len=blo[pos[l]].r-blo[pos[l]].l+1; for(ll i=1;i<=len;i++) { if(blo[pos[l]].a[i].id>=l) { blo[pos[l]].a[i].val+=k; } } sort(blo[pos[l]].a+1,blo[pos[l]].a+len+1); } if(r==blo[pos[r]].r) {blo[pos[r]].laz+=k;} else { ll len=blo[pos[r]].r-blo[pos[r]].l+1; for(ll i=1;i<=len;i++) { if(blo[pos[r]].a[i].id<=r) { blo[pos[r]].a[i].val+=k; } } sort(blo[pos[r]].a+1,blo[pos[r]].a+len+1); } for(ll i=pos[l]+1;i<pos[r];i++) blo[i].laz+=k; } } if(op[0]=='A') { ll ans=0; if(pos[l]==pos[r]) { ll len=blo[pos[l]].r-blo[pos[l]].l+1; for(ll i=1;i<=len;i++) { if(blo[pos[l]].a[i].id>=l&&blo[pos[l]].a[i].id<=r) { if(blo[pos[l]].a[i].val+blo[pos[l]].laz>=k) ans++; } } } else { ll len=blo[pos[l]].r-blo[pos[l]].l+1; for(ll i=1;i<=len;i++) { if(blo[pos[l]].a[i].id>=l) { if(blo[pos[l]].a[i].val+blo[pos[l]].laz>=k) ans++; } } len=blo[pos[r]].r-blo[pos[r]].l+1; for(ll i=1;i<=len;i++) { if(blo[pos[r]].a[i].id<=r) { if(blo[pos[r]].a[i].val+blo[pos[r]].laz>=k) ans++; } } for(ll i=pos[l]+1;i<pos[r];i++) { ll len=blo[i].r-blo[i].l+1; ll tmp=lower_bound(blo[i].a+1,blo[i].a+len+1 ,node(k-blo[i].laz,0))-blo[i].a-1; ans+=len-tmp; } } writeln(ans); } }
return 0; }
|