比赛 |
2024.5.23练习赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
新年快乐! |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
6.528 s |
代码语言 |
C++ |
内存使用 |
6.50 MiB |
提交时间 |
2024-05-23 18:55:52 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
const int N=1e5+5;
const int M=400+5;
int n,m;
ll a[N];
int S,tot;
int L[M],R[M],bl[N],sz[M];
ll tag[M];
vector<ll>val[N];
void init(){
S=sqrt(n),tot=n/S;
for (int i=1;i<=tot;i++)L[i]=R[i-1]+1,R[i]=i*S;
if (R[tot]<n)tot++,L[tot]=R[tot-1]+1,R[tot]=n;
for (int i=1;i<=tot;i++){
sz[i]=R[i]-L[i]+1;
tag[i]=0;
for (int j=L[i];j<=R[i];j++)bl[j]=i,val[i].pb(a[j]);
sort(val[i].begin(),val[i].end());
}
return ;
}
void force(int l,int r,ll w){
int p=bl[l];
for (int i=L[p];i<=R[p];i++)a[i]+=tag[p];
tag[p]=0,val[p].clear();
for (int i=l;i<=r;i++)a[i]+=w;
for (int i=L[p];i<=R[p];i++)val[p].pb(a[i]);
sort(val[p].begin(),val[p].end());
return ;
}
void modify(int l,int r,ll x){
int pl=bl[l],pr=bl[r];
if (pl==pr)return force(l,r,x);
force(l,R[pl],x),force(L[pr],r,x);
for (int i=pl+1;i<=pr-1;i++)tag[i]+=x;
return ;
}
int calc(int l,int r,ll x){
int ans=0;
for (int i=l;i<=r;i++)ans+=(a[i]+tag[bl[i]]<=x);
return ans;
}
int query(int l,int r,ll x){
int pl=bl[l],pr=bl[r];
if (pl==pr)return calc(l,r,x);
int ans=calc(l,R[pl],x)+calc(L[pr],r,x);
for (int i=pl+1;i<=pr-1;i++)ans+=upper_bound(val[i].begin(),val[i].end(),x-tag[i])-val[i].begin();
return ans;
}
int main(){
freopen ("dss.in","r",stdin);
freopen ("dss.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
init();
scanf("%d",&m);
for (int i=1;i<=m;i++){
int opt,l,r;ll x;scanf("%d%d%d%lld",&opt,&l,&r,&x);
if (opt==1)modify(l,r,x);
else printf("%d\n",query(l,r,x));
}
return 0;
}