Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
44756 | ZZQ | 数列操作1 | C++ | 通过 | 100 | 323 MS | 2052 KB | 1705 | 2022-02-10 08:54:16 |
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN=5e4+10; int a[MAXN], Tag[MAXN], Rank[MAXN]; vector<int> Vec[MAXN]; int n,block; inline int Read(int ans=0,int f=0) { char c=getchar(); for(; c<'0' || c>'9'; f^=(c=='-'),c=getchar()); for(; c<='9' && c>='0'; c=getchar()) ans=(ans<<3)+(ans<<1)+(c^48); return f? -ans : ans; } void ReSet(int pos) { Vec[pos].clear(); for (int i=(pos-1)*block+1; i<=min(pos*block, n); i++) Vec[pos].push_back(a[i]); sort(Vec[pos].begin(), Vec[pos].end()); } void Update(int l, int r, int c) { for (int i=l; i<=min(r, Rank[l]*block); i++) a[i]+=c; ReSet(Rank[l]); if (Rank[l]^Rank[r]) { for (int i=(Rank[r]-1)*block+1; i<=r; i++) a[i]+=c; ReSet(Rank[r]); } for (int i = Rank[l] + 1; i <= Rank[r] - 1; i++) Tag[i] += c; } int Query(int l, int r, int c) { int cnt = 0; for (int i=l; i<=min(r, Rank[l]*block); i++) if (a[i]+Tag[Rank[i]]<c) cnt++; if (Rank[l]^Rank[r]) for (int i=max((Rank[r]-1)*block+1, l); i<=r; i++) if (a[i]+Tag[Rank[i]]<c) cnt++; for (int i=Rank[l]+1; i<=Rank[r]-1; i++) cnt+=lower_bound(Vec[i].begin(), Vec[i].end(), c-Tag[i])-Vec[i].begin(); return cnt; } int main() { n=Read(); block=sqrt(n); for (int i=1; i<=n; i++) a[i]=Read(); for (int i=1,k=1,b=0; i<=n; i++) { if(b==block) k++,b=0; Rank[i]=k; Vec[Rank[i]].push_back(a[i]); b++; } for (int i=1; i<=Rank[n]; i++) sort(Vec[i].begin(), Vec[i].end()); for (int i=1,op, l, r, c; i<=n; i++) { op=Read(), l=Read(), r=Read(), c=Read(); if (op==0) Update(l, r, c); else printf("%d\n", Query(l, r, c*c)); } return 0; }