标签:cst def i++ 进不去 fine color 并且 void UNC
UESTCOJ不知道为什么进不去了哇
跟着叉姐的算法讲堂写的板子
叉姐的思路真的好清晰啊,一定是练习的多并且理解的够深了
希望自己也可以每天进步一点点吧
代码:
#include <map> #include <set> #include <cmath> #include <ctime> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <bitset> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> #define fuck(x) cout<<"["<<x<<"]"; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w+",stdout); #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; typedef pair<int, int> PII; const int maxn = 1e5+5; int n,a[maxn],q; struct node{ int l,r; long long sum,lazy; void update(long long x){ sum+=1ll*(r-l+1)*x; lazy+=x; } }tree[maxn*4]; void push_up(int x){ tree[x].sum=tree[x<<1].sum+tree[x<<1|1].sum; } void push_down(int x){ int lazyval=tree[x].lazy; if(lazyval){ tree[x<<1].update(lazyval); tree[x<<1|1].update(lazyval); tree[x].lazy=0; } } void build(int x,int l,int r){ tree[x].l=l,tree[x].r=r; tree[x].sum=tree[x].lazy=0; if(l==r){ tree[x].sum=a[l]; }else{ int mid=(l+r)/2; build(x<<1,l,mid); build(x<<1|1,mid+1,r); push_up(x); } } void update(int x,int l,int r,long long val){ int L=tree[x].l,R=tree[x].r; if(l<=L&&R<=r){ tree[x].update(val); }else{ push_down(x); int mid=(L+R)/2; if(mid>=l) update(x<<1,l,r,val); if(r>mid) update(x<<1|1,l,r,val); push_up(x); } } long long query(int x,int l,int r){ int L=tree[x].l,R=tree[x].r; if(l<=L&&R<=r){ return tree[x].sum; }else{ push_down(x); long long ans=0; int mid=(L+R)/2; if(mid>=l) ans+=query(x<<1,l,r); if(r>mid) ans+=query(x<<1|1,l,r); push_up(x); return ans; } } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } scanf("%d",&q); for(int i=1;i<=q;i++){ int l,r,val; scanf("%d%d%d",&l,&r,&val); update(1,l,r,val); printf("%lld\n",query(1,l,r)); } }
标签:cst def i++ 进不去 fine color 并且 void UNC
原文地址:https://www.cnblogs.com/buerdepepeqi/p/9368871.html