错误找了三个小时 ,原因建树的时候。。。 tag没有初始化,,,当场暴毙~~~,,,啊啊啊啊啊 我才想起来是多组数据。。因为我记得结构体中的数是默认为0的 但是我忘了初始化tag。。。emm 一定要养成随手初始化的好习惯。。。呜呜呜呜。。。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
#define lson cnt<<1
#define rson cnt<<1|1
struct node{
int l,r,tag,sum;
}tree[maxn<<2];
void pushUp(int cnt)
{
tree[cnt].sum = tree[lson].sum + tree[rson].sum;
}
void build(int cnt,int l,int r)
{
tree[cnt].l = l;
tree[cnt].r = r;
tree[cnt].tag = 0;
if(l == r)
{
tree[cnt].sum = 1;
return ;
}
int mid = (l+r) >> 1;
build(lson,l,mid);
build(rson,mid+1,r);
pushUp(cnt);
}
void pushDown(int cnt,int l,int r)
{
if(tree[cnt].tag)
{
int m =(l+r) >>1;
tree[lson].tag = tree[rson].tag = tree[cnt].tag;
tree[lson].sum = (m - l + 1) * tree[cnt].tag;
tree[rson].sum = (r - m)*tree[cnt].tag;
tree[cnt].tag = 0;
}
}
void update(int cnt,int l,int r,int L,int R,int v)
{
if(L <= l && R >= r)
{
tree[cnt].tag = v;
tree[cnt].sum = (r-l+1)*v;
return ;
}
pushDown(cnt,l,r);
int mid = (l+r) >> 1;
if(mid >= L)
update(lson,l,mid,L,R,v);
if(R >mid)
update(rson,mid+1,r,L,R,v);
pushUp(cnt);
}
int main()
{
std::ios::sync_with_stdio(false);
int n,m,t,q;
int x,y,z;
int ans = 0;
cin>>t;
while(t--)
{
cin>>n;
build(1,1,n);
cin>>m;
while(m--)
{
cin>>x>>y>>z;
update(1,1,n,x,y,z);
}
printf("Case %d: The total value of the hook is %d.\n",++ans,tree[1].sum);
}
return 0;
}