qwq2519 @ 2021-08-23 21:37:02
#include<bits/stdc++.h>
#define rep(i,j,k) for(register int i(j);i<=k;++i)
#define drp(i,j,k) for(register int i(j);i>=k;--i)
using namespace std;
#define int long long
typedef long long lxl;
template<typename T>
inline T max(T &a, T &b) {
return a > b ? a : b;
}
template<typename T>
inline T min(T &a, T &b) {
return a < b ? a : b;
}
const int N = 1e6 + 79;
const int SIZ = 1e3 + 79;
int n, q;
int a[N];
int block, belong[N], tag[SIZ],tot;
int b[N];
int L[SIZ],R[SIZ];
inline void reset(int x){
rep(i,L[x],R[x]) b[i]=a[i];
sort(b+L[x],b+R[x]+1);
}
inline void build(){
block = sqrt(n);
tot=n/block;
if(n%block) tot++;
rep(i, 1, n) {
belong[i] = (i - 1) / block + 1;
}
rep(i,1,tot){
L[i]=(i-1)*block+1;
R[i]=i*block;
}
R[tot]=n;
rep(i,1,tot){
reset(i);
}
}
inline void add(int l, int r, int x) {
rep(i, l,R[belong[l]]) {
a[i] += x;
}
reset(belong[l]);
if(belong[l] != belong[r]) {
rep(i, L[belong[r]], r) {
a[i] += x;
}
reset(belong[r]);
}
rep(i, belong[l] + 1, belong[r] - 1)
tag[i] += x;
}
inline void query(int l, int r, int x) { //大于等于x的数字
int ans(0);
rep(i, l,R[belong[l]]) {
if(a[i] + tag[belong[i]] >= x) ans++;
}
if(belong[l] != belong[r]) {
rep(i,L[belong[r]], r) {
if(a[i] + tag[belong[i]] >= x) ans++;
}
}
rep(i, belong[l] + 1, belong[r] - 1) {
int ll=L[i],rr=R[i],mid,res=0;
while(ll<=rr){
mid=ll+rr>>1;
if(b[mid]+tag[i]>=x){
rr=mid-1;
res=R[i]-mid+1;
}
else{
ll=mid+1;
}
}
ans+=res;
}
cout << ans << '\n';
}
main() {
ios::sync_with_stdio(false);
cin >> n >> q;
rep(i,1,n){
cin>>a[i];
}
build();
char op;
int l, r, w;
while(q--) {
cin >> op >> l >> r >> w;
if(op == 'M') {
add(l, r, w);
} else {
query(l, r, w);
}
}
return 0;
}
by qwq2519 @ 2021-08-23 21:39:37
有人吗
by niuma @ 2021-08-24 16:31:32
加油zzj
by qwq2519 @ 2021-08-24 20:36:20
第十组发现很小。。下载下来,就发现了。。不得不说,数据好水.
把query函数的l所在块的右边界改为
min(r,R[belong[r])
即可。。
此贴终