RT.(和答案只差几十)
#include<bits/stdc++.h>
//#include<bits/extc++.h>
#define gt getchar
#define pt putchar
#define y1 y233
#define int long long
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);++(i))
#define per(i,a,b) for(int (i)=(a);(i)>=(b);--(i))
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
const int N=5e4+5;
using namespace std;
//using namespace __gnu_pbds;
inline bool _(char ch){return ch>=48&&ch<=57;}
inline int read(){
int x=0,sgn=0;char ch=gt();
while(!_(ch)){sgn|=(ch=='-');ch=gt();}
while(_(ch)){x=(x<<1)+(x<<3)+(ch-'0');ch=gt();}
return sgn?-x:x;
}
inline void print(int x){
static char st[70];int top=0;
if(x<0)pt('-'),x=-x;
do{st[++top]=((x%10)^48),x/=10;}while(x);
while(top)pt(st[top--]);
}
inline void printsp(int x){
static char st[70];int top=0;
if(x<0)pt('-'),x=-x;
do{st[++top]=((x%10)^48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
inline void println(int x){
static char st[70];int top=0;
if(x<0)pt('-'),x=-x;
do{st[++top]=((x%10)^48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
struct block{
int l,r,id;
int tag;
}blo[N];
int n,m,a[N],len,num;
inline int get_sqrt(int x){
int bad_sqrt=sqrt(x)-1;
for(;bad_sqrt+1<=x/(bad_sqrt+1);++bad_sqrt);
return bad_sqrt;
}
inline void build(){
len=get_sqrt(n),num=(n+len-1)/len;
rep(i,1,num) blo[i].l=(i-1)*len+1,blo[i].r=i*len;
blo[num].r=n;
rep(i,1,num) rep(j,blo[i].l,blo[i].r) blo[j].id=i;
rep(i,1,num) sort(a+blo[i].l,a+blo[i].r+1);
}
inline void add(int l,int r,int x){
int L=blo[l].id,R=blo[r].id;
if(L==R){
rep(i,l,r) a[i]+=x;
sort(a+blo[L].l,a+blo[L].r+1);
return;
}
rep(i,l,blo[L].r) a[i]+=x;
sort(a+blo[L].l,a+blo[L].r+1);
rep(i,blo[R].l,r) a[i]+=x;
sort(a+blo[R].l,a+blo[R].r+1);
rep(i,L+1,R-1) blo[i].tag+=x;
}
inline int query(int l,int r,int x){
int L=blo[l].id,R=blo[r].id,res=0;
if(L==R){
rep(i,l,r) if(a[i]+blo[L].tag<x)res++;
return res;
}
rep(i,l,blo[L].r) if(a[i]+blo[L].tag<x)res++;
rep(i,blo[R].l,r) if(a[i]+blo[R].tag<x)res++;
rep(i,L+1,R-1) res+=lower_bound(a+blo[i].l,a+blo[i].r+1,x-blo[i].tag)-a-blo[i].l;
return res;
}
signed main(){
n=read();
rep(i,1,n) a[i]=read();
build();
rep(i,1,n){
int opt=read(),l=read(),r=read(),x=read();
if(opt==0)add(l,r,x);
else println(query(l,r,x*x));
}
return 0;
}