From 11660860e7f0e14ffee6326bf577a0fc41891996 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sat, 16 Nov 2024 15:48:29 +0800 Subject: [PATCH] update --- src/20241116/U498420.cpp | 1 - src/P3368/P3368.cpp | 54 ++++++++++++++++++++++++++++++++++++++++ src/P3374/P3374.cpp | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/P3368/P3368.cpp create mode 100644 src/P3374/P3374.cpp diff --git a/src/20241116/U498420.cpp b/src/20241116/U498420.cpp index 0cd9378..f8a2769 100644 --- a/src/20241116/U498420.cpp +++ b/src/20241116/U498420.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include using ll = int64_t; diff --git a/src/P3368/P3368.cpp b/src/P3368/P3368.cpp new file mode 100644 index 0000000..e65b1d9 --- /dev/null +++ b/src/P3368/P3368.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +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< +#include +#include + +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<>t>>x>>y; + if(t==1){ + while(x<=n){ + bit[x]+=y; + x+=lb(x); + } + }else{ + cout<