输出格式
对于每次询问,输出一行一个数字表示答案。
样例
样例输入
4
1 2 2 3
0 1 3 1
1 1 3 2
1 1 4 1
1 2 3 2
样例输出
3
0
2
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 5;
int blo, n, opt, l, r, c, a[maxn], pos[maxn], atag[maxn];
vector<int>ve[505];
void reset(int x)
{ve[x].clear();for (int i = (x - 1)*blo+1; i <= min(x*blo, n); i++)ve[x].push_back(a[i]);sort(ve[x].begin(), ve[x].end());
}
int add(int l, int r, int c)
{for (int i = l ; i <= min(pos[l]*blo, r); i++) a[i] += c;reset(pos[l]);if(pos[l] != pos[r]){for (int i = (pos[r] - 1) * blo + 1; i <= r; i++) a[i] += c;reset(pos[r]); }for (int i = pos[l]+1; i <= pos[r]-1; i++) atag[i] += c;
}
int query(int l , int r, int c)
{int ans = 0;for (int i = l; i <= min(pos[l]*blo, r); i++)if(a[i]+atag[pos[l]] < c) ans++;if(pos[l] != pos[r]){for (int i = (pos[r] - 1) * blo + 1; i <= r; i++)if(a[i]+atag[pos[r]] < c) ans++;}for (int i = pos[l]+1; i <= pos[r]-1; i++){int x = c - atag[i];ans += lower_bound(ve[i].begin(), ve[i].end(), x) - ve[i].begin();}return ans;
}
int main()
{scanf("%d", &n);blo = sqrt(n);for (int i = 1; i <= n; i++) scanf("%d",&a[i]), pos[i] = (i - 1) / blo + 1, ve[pos[i]].push_back(a[i]);for (int i = 1; i <= pos[n]; i++){sort(ve[i].begin(), ve[i].end());}for (int i = 0; i < n; i++){scanf("%d%d%d%d", &opt, &l, &r, &c);if(opt == 0){add(l, r, c);}else{printf("%d\n", query(l, r, c*c));}}return 0;
}