cxlian25 @ 2023-11-19 13:17:33
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<vector>
#define ll long long
#define lx (x<<1)
#define rx (x<<1|1)
#define db double
#define pb push_back
#define mp make_pair
#define pa pair<int,int>
#define mid ((l+r)>>1)
#define mem(a) memset(a,0,sizeof(a))
#define memf(a) memset(a,127,sizeof(a))//浮点,int数最大
#define memm(a) memset(a,0x3f,sizeof(a))//1e9
#define memn(a) memset(a,0xcf,sizeof(a))//int最小
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ct(a) (__builtin_popcount(a))
#define lowbit(i) (i&(-i))
using namespace std;
const int N=2e6+7,M=1e6+10;
const double eps=1e-9,pi=acos(-1.0);
int tt;
int n,m,k,cnt=0;
int a[N];
vector<int>v[20105];
int lazy[20150];
void gai(int l,int r,int x,int w){
for(int i=l;i<=r;i++){
a[i]+=w;
}
vector<int>().swap(v[x]);
for(int i=(x-1)*k;i<x*k;i++){
v[x].pb(a[i]);
}
sort(v[x].begin(),v[x].end());
}
int qu(int l,int r,int x,int c){
if(lazy[x]!=0){
for(int i=(x-1)*k;i<x*k;i++){
a[i]+=lazy[x];
}
for(int i=0;i<v[x].size();i++){
v[x][i]+=lazy[x];
}
lazy[x]=0;
}
int sum=0;
for(int i=l;i<=r;i++){
if(a[i]>=c)sum++;
}
return sum;
}
int check(int x,int c){
int l=0,r=v[x].size()-1;
while(l<=r){
if(v[x][mid]+lazy[x]>=c)r=mid-1;
else l=mid+1;
}
return v[x].size()-r-1;
}
void solve(){
scanf("%d%d",&n,&m);
k=sqrt(n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
v[i/k+1].pb(a[i]);
}
int mx=n/k+1;
for(int i=1;i<=mx;i++){
sort(v[i].begin(),v[i].end());
}
char op[2];
while(m--){
scanf("%s",op);
if(op[0]=='M'){
int l,r,w;
scanf("%d%d%d",&l,&r,&w);
int sl=l/k+1;
int sr=r/k+1;
if(sl==sr){
gai(l,r,sl,w);
continue;
}
gai(l,sl*k-1,sl,w);
gai((sr-1)*k,r,sr,w);
for(int i=sl+1;i<=sr-1;i++){
lazy[i]+=w;
}
}
if(op[0]=='A'){
int l,r,c;
scanf("%d%d%d",&l,&r,&c);
int sl=l/k+1;
int sr=r/k+1;
int ans=0;
if(sl==sr){
ans+=qu(l,r,sl,c);
printf("%d\n",ans);
continue;
}
ans+=qu(l,sl*k-1,sl,c);
ans+=qu((sr-1)*k,r,sr,c);
for(int i=sl+1;i<=sr-1;i++){
ans+=check(i,c);
}
printf("%d\n",ans);
}
}
}
/*
5 3
1 2 3 4 5
A 1 5 4
M 3 5 1
A 1 5 4
*/
signed main(){
// scanf("%d",&tt);
tt=1;
while(tt--){
solve();
}
return 0;
}
/*
1
1 2 3 4 5
1 2 2 3 3
*/
by _little_Cabbage_ @ 2023-11-19 13:28:37
@cxlian25 因为一个数组开1e6的话访问不到a[1000000],N设为1e6+10也能过
by cxlian25 @ 2023-11-19 14:28:06
@Thomas121213 我是1e6+7啊,我基本上都要多几个的
by _little_Cabbage_ @ 2023-11-19 14:34:11
@cxlian25 那我不知道了(这什么鬼啊)
by cxlian25 @ 2023-11-19 14:36:41
我的评测记录
by Furina_Saikou @ 2023-11-25 11:32:09
@cxlian25 可能是开少导致访问到奇奇怪怪的东西然后循环越界了