Meaning of the questions:
hook has a length of n bars, which can be thought of as an n-segment, each segment is a start copper, a period of interval may be selected to change the hook bar properties,
Stick three attributes: 1 = copper, silver = 2, k = 3 sum, the final output of each section bar properties.
Links: http://acm.hdu.edu.cn/showproblem.php?pid=1698
Ideas:
Interval Interval + staining inquiry
Code:
#include <bits/stdc++.h> using namespace std; const int MAXN=1e5+5; typedef long long ll; int lazy[MAXN<<2],tree[MAXN<<2]; void push_up(int node) { tree[node]=tree[node<<1]+tree[node<<1|1]; } void build(int node,int l,int r) { if(l==r) { tree[node]=1;return ; } int mid=(l+r)>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); push_up(node); } void push_down(int node,int l,int r,int mid) { lazy[node<<1]=lazy[node]; lazy[node<<1|1]=lazy[node]; tree[node<<1]=lazy[node]*(mid-l+1); tree[node<<1|1]=lazy[node]*(r-mid); lazy[node]=0; } void update(int node,int l,int r,int x,int y,int z) { if(x<=l&&y>=r) { lazy[node]=z; tree[node]=(r-l+1)*z; return; } int mid=(l+r)>>1; if(lazy[node])push_down(node,l,r,mid); if(x<=mid)update(node<<1,l,mid,x,y,z); if(y>mid)update(node<<1|1,mid+1,r,x,y,z); push_up(node); } you query ( you node, you have to, you're down, you're out, you y) { if(x<=l&&y>=r) { return tree[node]; } int ans=0; int mid=(l+r)>>1; if(lazy[node])push_down(node,l,r,mid); if(x<=mid)ans+=query(node<<1,l,mid,x,y); if(y>mid)ans+=query(node<<1|1,mid+1,r,x,y); return ans; } int main () { int t;scanf("%d",&t);int case_=0; while(t--) { memset(lazy,0,sizeof(lazy)); int n;scanf("%d",&n); int q;scanf("%d",&q); build(1,1,n); while(q--) { int x,y,z; scanf("%d%d%d",&x,&y,&z); update(1,1,n,x,y,z); } printf("Case %d: The total value of the hook is %d.\n",++case_,query(1,1,n,1,n)); } return 0; }