比赛 2024.5.23练习赛 评测结果 AAAAAAAAAA
题目名称 新年快乐! 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 6.047 s
代码语言 C++ 内存使用 5.44 MiB
提交时间 2024-05-23 19:19:08
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in inline
#define re register
#define pii pair<int,int>
#define se second
#define pb(x) push_back(x)
#define D(i,a,b) for(re int i = a;i >= b;i--)
#define F(i,a,b) for(re int i = a;i <= b;i++)
const int N = 1e5+10,M = 320;
const ll inf = 1e17;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}

int n,m;
int B,bl[N],L[M],R[M],t;
ll a[N],la[M];
vector<ll>c[M];
void prework(){
    B = sqrt(n),t = (n-1)/B+1;
    F(i,1,t)L[i] = (i-1)*B+1,R[i] = i*B;
    F(i,1,n)bl[i] = (i-1)/B+1;
}
void change(int l,int r,int p,ll z){
    F(i,l,r)a[i] += z;
    c[p].clear();
    F(i,L[p],R[p])c[p].pb(a[i]);
    sort(c[p].begin(),c[p].end());
} 
void add(int l,int r,ll z){
    int p = bl[l],q = bl[r];
    if(p == q)return change(l,r,p,z),void();
    change(l,R[p],p,z),change(L[q],r,q,z);
    F(i,p+1,q-1)la[i] += z;
}
ll ask(int l,int r,ll z){
    ll ans = 0;int p = bl[l],q = bl[r];
    if(p == q){
        F(i,l,r)if(a[i] + la[p] <= z)ans++;
        return ans;
    }
    F(i,l,R[p])if(a[i] + la[p] <= z)ans++;
    F(i,L[q],r)if(a[i] + la[q] <= z)ans++;
    F(i,p+1,q-1){
        ans += upper_bound(c[i].begin(),c[i].end(),z - la[i]) - c[i].begin();
    }
    return ans;
}
int main(){
    freopen("dss.in","r",stdin);
    freopen("dss.out","w",stdout);
    n = read();
    prework();
    F(i,1,n)a[i] = read(),c[bl[i]].pb(a[i]);
    F(i,1,t)sort(c[i].begin(),c[i].end());
    m = read();
    F(i,1,m){
        int op = read(),l = read(),r = read();ll v = read();
        if(op == 1)add(l,r,v);
        else printf("%lld\n",ask(l,r,v));
    }
    
	return cerr << "Time : " << clock() << " ms" << endl, 0;
        
}
/*
5
2 2 4 1 2
12
2 1 5 4
2 1 5 1
*/