提交时间:2022-02-11 09:47:58
运行 ID: 44904
//test #include <bits/stdc++.h> using namespace std; typedef long long ll; ll lazy[500005],bl[500005],a[500005]; ll n,m,block; void Add(ll l, ll r, ll k) { for (ll i=l; i<=min(r,block*bl[l]); i++) a[i]+=k; if (bl[l]!=bl[r]) for (ll i=(bl[r]-1)*block+1; i<=r; i++) a[i]+=k; for (ll i=bl[l]+1; i<=bl[r]-1; i++) lazy[i]+=k; } int main() { scanf("%lld",&n); block=sqrt(n); for (int i=1; i<=n; i++) { scanf("%lld",&a[i]); bl[i]=(i-1)/block+1; } scanf("%lld",&m); for (ll choice,l,r,k; m; m--) { scanf("%lld",&choice); if (choice==1) { scanf("%lld%lld%lld",&l,&r,&k); Add(l,r,k); } else { scanf("%lld",&k); printf("%lld\n",a[k]+lazy[bl[k]]); } } return 0; }