__int__ @ 2023-07-13 23:12:05
RT,搞不懂为什么全错
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
int n, q, a[N], b[N];
int t, len, L[N], R[N], add[N], pos[N];
#define p_l pos[l]
#define p_r pos[r]
#define p_p pos[p]
inline void bf_update(int p, int l, int r, int d) {
for (int i = l; i <= r; i ++ ) a[i] += d;
for (int i = L[p_p]; i <= R[p_p]; i ++ ) b[i] = a[i];
sort(b + L[p_p], b + 1 + R[p_p]);
}
inline void update(int l, int r, int d) {
if (p_l == p_r) bf_update(l, l, r, d);
else {
bf_update(l, l, R[p_l], d), bf_update(l, L[p_r], r, d);
for (int i = p_l + 1; i <= p_r - 1; i ++ )
add[i] += d;
}
}
inline int bf_query(int p, int l, int r, int d, int &res) {
for (int i = l; i <= r; i ++ )
if (add[p_p] + a[i] >= d) res ++ ;
}
inline int query(int l, int r, int d) {
int res = 0;
if (p_l == p_r) bf_query(l, l, r, d, res);
else {
bf_query(l, l, R[p_l], d, res), bf_query(r, L[p_r], r, d, res);
for (int i = p_l + 1; i <= p_r - 1; i ++ )
res += R[i] - (lower_bound(b + L[i], b + 1 + R[i], d - add[i]) - b) + 1;
}
return res;
}
signed main()
{
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i ++ )
scanf("%d", a + i), b[i] = a[i];
len = t = sqrt(n);
for (int i = 1; i <= t; i ++ )
L[i] = (i - 1) * t + 1, R[i] = i * t;
if (R[t] < n) t ++ , L[t] = R[t - 1] + 1, R[t] = n;
for (int i = 1; i <= t; i ++ )
for (int j = L[i]; j <= R[i]; j ++ )
pos[j] = i;
for (int i = 1; i <= t; i ++ )
sort(b + L[i], b + 1 + R[i]);
char opt;
for (int l, r, c; q -- ; ) {
cin >> opt >> l >> r >> c;
if (opt == 'M') update(l, r, c);
else printf("%d\n", query(l, r, c));
}
return 0;
}
by __int__ @ 2023-07-14 06:16:00
找到一个错误:l25 bf_update(l, L[p_r], r, d)中l应为r;但仍为0pts
by FurippuWRY @ 2023-07-14 08:52:09
can can word
90分(悲) 评测记录
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,q,w,c,height[11451419],l,r,b=0;
char p;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>q;
for(ll i=0;i<n;++i){
cin>>height[i];
}
for(ll i=0;i<q;++i){
cin>>p;
if(p=='M'){
cin>>l>>r>>w;
for(ll j=l-1;j<=r-1;++j){
height[j]+=w;
}
}
else
if(p=='A'){
cin>>l>>r>>c;
for(ll j=l-1;j<=r-1;++j){
if(height[j]>=c){
++b;
}
}cout<<b<<endl;
}
b=0;
}
return 0;
}
by FurippuWRY @ 2023-07-14 10:28:41
好的现在蹭测试点过了()
by panwangxi @ 2023-07-14 11:31:38
for (int i = 1; i <= t; i ++ )
for (int j = L[i]; j <= R[i]; j ++ )
pos[j] = i;
要加一个b[j]=a[j];
by __int__ @ 2023-07-14 13:15:40
@panwangxi 我前面已经有for(int i = 1; i <= n; i ++ ) b[i] = a[i];
by __int__ @ 2023-07-14 16:50:37
好,把bf_query()的类型从int改成void就由0pts到了100pts,警示后人,此帖结
by FurippuWRY @ 2023-08-17 22:08:27
@int 烤咕 你这bf_query用int也能过了