标签:vector show print ace eve pushd click display cas
裸题模板
#include<iostream> #include<queue> #include<map> #include<vector> #include<cstdio> #include<algorithm> #include<stack> #include<string> #include<cstring> using namespace std; typedef long long ll; const int N=1e5+10; const int inf=0x3f3f3f3f; struct node{ int l,r; int sum; int lazy; }tr[N<<2]; void pushup(int u){ tr[u].sum=tr[u<<1].sum+tr[u<<1|1].sum; } void build(int u,int l,int r){ if(l==r){ tr[u]={l,l,1,0}; } else{ int mid=l+r>>1; tr[u]={l,r,0,0}; build(u<<1,l,mid); build(u<<1|1,mid+1,r); pushup(u); } } void pushdown(int u){ if(tr[u].lazy){ tr[u<<1].lazy=tr[u<<1|1].lazy=tr[u].lazy; tr[u<<1].sum=(tr[u<<1].r-tr[u<<1].l+1)*tr[u].lazy; tr[u<<1|1].sum=(tr[u<<1|1].r-tr[u<<1|1].l+1)*tr[u].lazy; tr[u].lazy=0; } } void modify(int u,int l,int r,int x){ if(tr[u].l>=l&&tr[u].r<=r){ tr[u].sum=(tr[u].r-tr[u].l+1)*x; tr[u].lazy=x; return ; } pushdown(u); int mid=tr[u].l+tr[u].r>>1; if(l<=mid) modify(u<<1,l,r,x); if(r>mid) modify(u<<1|1,l,r,x); pushup(u); } int main(){ int t; int n; cin>>t; int cnt=1; while(t--){ cin>>n; int m; cin>>m; int i; build(1,1,n); for(i=1;i<=m;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); modify(1,x,y,z); } printf("Case %d: The total value of the hook is %d.\n",cnt++,tr[1].sum); } }
标签:vector show print ace eve pushd click display cas
原文地址:https://www.cnblogs.com/ctyakwf/p/12513223.html