This commit is contained in:
Zengtudor 2024-11-16 15:48:29 +08:00
parent edcfb1e48f
commit 11660860e7
3 changed files with 105 additions and 1 deletions

View File

@ -2,7 +2,6 @@
#include <iostream> #include <iostream>
#include <istream> #include <istream>
#include <map> #include <map>
#include <set>
#include <vector> #include <vector>
using ll = int64_t; using ll = int64_t;

54
src/P3368/P3368.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <cstdint>
#include <iostream>
#include <istream>
using ll = int64_t;
using std::cin, std::cout;
const ll maxn = 500000 + 5;
ll n, m, bit[maxn];
ll lb(const ll &n){
return n&(-n);
}
void rgadd(ll l, ll r, const ll &k){
++r;
while(l<=n){
bit[l]+=k;
l+=lb(l);
}
while(r<=n){
bit[r]-=k;
r+=lb(r);
}
}
int main(){
std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin>>n>>m;
for(ll i{1};i<=n;i++){
ll a;
cin>>a;
rgadd(i, i, a);
}
for(ll i{1};i<=m;i++){
ll t;
cin>>t;
if(t==1){
ll x, y, k;
cin>>x>>y>>k;
rgadd(x, y, k);
}else{
ll x;
cin>>x;
ll res{};
while(x!=0){
res+=bit[x];
x-=lb(x);
}
cout<<res<<'\n';
}
}
}

51
src/P3374/P3374.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <cstdint>
#include <iostream>
#include <istream>
using ll = int64_t;
using std::cin, std::cout;
const ll maxn = 5e5+5;
ll n, m, bit[maxn];
ll lb(const ll &n){
return n&(-n);
}
int main(){
std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin>>n>>m;
for(ll i{1};i<=n;i++){
ll a;
cin>>a;
ll now{i};
while(now<=n){
bit[now]+=a;
now+=lb(now);
}
}
const auto sch = [](ll n)->ll{
ll res{};
while(n!=0){
res+=bit[n];
n-=lb(n);
}
return res;
};
// for(ll i{1};i<=n;i++){
// cout<<sch(i)-sch(i-1)<<'\n';
// }
while(m--){
ll t, x, y;
cin>>t>>x>>y;
if(t==1){
while(x<=n){
bit[x]+=y;
x+=lb(x);
}
}else{
cout<<sch(y)-sch(x-1)<<'\n';
}
}
}