• HDU 1698Just a Hook


    题意:水题线段树,区间更新带上+lazy标记,最后统计即可;

    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<stack>
    #include<map>
    #include<vector>
    #include<set>
    #include<cstring>
    #include<cstdio>
    #define N 100005
    using namespace std;
    typedef struct node{
    	int x;int y;int date;int p;
    }node;
    node a[N*4];
    void built(int root,int first,int end){
    	if(first==end){
    		a[root].date=1;
    		a[root].x=first;
    		a[root].y=end;
    		a[root].p=0;
    		return ;
    	}
    	int mid=(first+end)/2;
    	built(root*2,first,mid);
    	built(root*2+1,mid+1,end);
    	a[root].x=a[root*2].x;a[root].y=a[root*2+1].y;a[root].date=a[root*2+1].date+a[root*2].date;a[root].p=0;
    }
    void U(int root,int first,int end,int l,int r,int e){
    	if(l<=first&&end<=r){
    		a[root].date=(end-first+1)*e;a[root].p=e;
    		return ;
    	}
    	int mid=(first+end)/2;
    	if(a[root].p!=0){
    		a[root*2+1].date=(end-mid)*a[root].p;
    		a[root*2+1].p=a[root].p;
    		a[root*2].date=(mid-first+1)*a[root].p;
    		a[root*2].p=a[root].p;
    		a[root].p=0;
    	}
    	if(l<=mid)  U(root*2,first,mid,l,r,e);
    	if(r>mid)  U(root*2+1,mid+1,end,l,r,e);
    	a[root].date=a[root*2].date+a[root*2+1].date;
    }
    void Q(int root,int first,int end){
    	if(first==end){
    		return ;
    	}
    	int mid=(first+end)/2;
    		if(a[root].p!=0){
    		a[root*2+1].date=(end-mid)*a[root].p;
    		a[root*2+1].p=a[root].p;
    		a[root*2].date=(mid-first+1)*a[root].p;
    		a[root*2].p=a[root].p;
    		a[root].p=0;
    	}
    	Q(root*2,first,mid);
    	Q(root*2+1,mid+1,end);
    	a[root].date=a[root*2+1].date+a[root*2].date;
    }
    int main(){
    	int m;
    	scanf("%d",&m);
    	for(int i=1;i<=m;i++){
    		int n;
    		scanf("%d",&n);
    		built(1,1,n);
    		int k;
    		scanf("%d",&k);
    		int b,c,d;
    		for(int j=1;j<=k;j++){
    			scanf("%d%d%d",&b,&c,&d);
    			U(1,1,n,b,c,d);
    		}
    		Q(1,1,n);
    		printf("Case %d: ",i);
    		printf("The total value of the hook is %d.
    ",a[1].date);
    	}
    	return 0;
    }


  • 相关阅读:
    开源电话交换平台FreeSwitch的安装与配置
    快速编辑 Shell 命令行
    RedHat在字符模式下安装图形界面
    Linux字符界面切换到图形界面
    row cache lock
    cursor: pin S
    Excel 2010高级应用-气泡图(八)
    JDBC异常之数据库表不存在
    java.sql.SQLException之数组越界
    java中JDBC报错(一)
  • 原文地址:https://www.cnblogs.com/wang9897/p/7624399.html
Copyright © 2020-2023  润新知