hdu 1698

#include<stdio.h>
#include<string.h>
#define N 100000
struct st{
 int x,y,yanchi;
}a[N*4];
void build(int t,int x,int y) {
 a[t].x=x;
 a[t].y=y;
 a[t].yanchi=1;
 if(x==y)
  return ;
 int temp=t*2;
 int mid=(a[t].x+a[t].y)/2;
 build(temp,x,mid);
 build(temp+1,mid+1,y);
 return ;
}
void change(int t,int x,int y,int z) {
   if(a[t].yanchi==z)
    return ;
   if(a[t].x==x&&a[t].y==y) {
    a[t].yanchi=z;
    return ;
   }
   int temp=t*2;
 int mid=(a[t].x+a[t].y)/2;
   if(a[t].yanchi!=-1) {
    a[temp].yanchi=a[temp+1].yanchi=a[t].yanchi;
    a[t].yanchi=-1;
   }
 if(y<=mid)
  change(temp,x,y,z);
else
if(x>mid)
change(temp+1,x,y,z);
else {
 change(temp,x,mid,z);
 change(temp+1,mid+1,y,z);
}
}
__int64 seach(int t) {
 if(a[t].yanchi!=-1)
  return (a[t].y-a[t].x+1)*a[t].yanchi;
 else
  return seach(t*2)+seach(t*2+1);
}
int main() {
 int i,j,k,n,m,t,s=0;
 scanf("%d",&t);
 while(t--) {
     scanf("%d%d",&n,&m);
  build(1,1,n);
  while(m--) {
  scanf("%d%d%d",&i,&j,&k);
  change(1,i,j,k);
  }
   printf("Case %d: The total value of the hook is %I64d. ",++s,seach(1));
 }
 return 0;
}


 

原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410979.html