zoukankan      html  css  js  c++  java
  • Just a Hook HDU

    Just a Hook  HDU - 1698 

    In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. 



    Now Pudge wants to do some operations on the hook. 

    Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks. 
    The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows: 

    For each cupreous stick, the value is 1. 
    For each silver stick, the value is 2. 
    For each golden stick, the value is 3. 

    Pudge wants to know the total value of the hook after performing the operations. 
    You may consider the original hook is made up of cupreous sticks. 

    InputThe input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases. 
    For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations. 
    Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind. 
    OutputFor each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example. 
    Sample Input

    1
    10
    2
    1 5 2
    5 9 3

    Sample Output

    Case 1: The total value of the hook is 24.

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <string>
     5 #include <vector>
     6 #include <map>
     7 #include <set>
     8 #include <list>
     9 #include <deque>
    10 #include <queue>
    11 #include <stack>
    12 #include <cstdlib>
    13 #include <cstdio>
    14 #include <cmath>
    15 #include <iomanip>
    16 #define ull unsigned long long
    17 #define ll long long
    18 #define pb push_back
    19 #define mem(sum,x) memset(sum,x,sizeof(sum))
    20 #define rep(i,start,end) for(int i=start;i<=end;i++)
    21 #define per(i,end,start) for(int i=end;i>=start;i--)
    22 #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    23 using namespace std;
    24 const int mod = 998244353;
    25 const int mxn = 1e5 +7;
    26 int _,n,m,t,u,ans,cnt,ok,lim;
    27 ll w[mxn] , cost[mxn] , dp[mxn] , far[mxn] , siz[mxn];
    28 double num[mxn];
    29 #define lc now<<1
    30 #define rc now<<1|1
    31 string str ;
    32 struct node {int l,r,val,lazy;}p[mxn<<4];
    33 void pushup(int now){p[now].val = p[lc].val+p[rc].val;}
    34 void pushdown(int now)
    35 {
    36     if(p[now].lazy)
    37     {
    38         p[lc].lazy = p[rc].lazy = p[now].lazy;
    39         p[lc].val = p[now].lazy*(p[lc].r-p[lc].l+1);
    40         p[rc].val = p[now].lazy*(p[rc].r-p[rc].l+1);
    41         p[now].lazy = 0 ;
    42     }
    43 }
    44 void build(int l,int r,int now)
    45 {
    46     p[now].l = l,p[now].r = r , p[now].val = 1 ,p[now].lazy = 1 ;
    47     if(l==r) return ;
    48     int mid = (l+r)>>1;
    49     build(l,mid,lc);build(mid+1,r,rc);pushup(now);
    50 }
    51 void add(int l,int r,int k,int now)
    52 {
    53     if(l<= p[now].l && r>=p[now].r){
    54         p[now].val = k*(p[now].r-p[now].l+1) ;
    55         p[now].lazy = k ;
    56         return ;
    57     }
    58     pushdown(now);
    59     int mid = (p[now].l+p[now].r)>>1;
    60     if(l<=mid) add(l,r,k,lc);
    61     if(r>mid) add(l,r,k,rc);
    62     pushup(now);
    63 }
    64 int ask(int l,int r,int now)
    65 {
    66     if(l<=p[now].l && r>=p[now].r){
    67         return p[now].val;
    68     }
    69     int mid = (p[now].l+p[now].r)>>1 , ans = 0;
    70     if(l<=mid) ans+=ask(l,r,lc);
    71     if(r>mid) ans+=ask(l,r,rc);
    72     return ans;
    73 }
    74 int main()
    75 {
    76     tle;
    77     int Case = 1 ;
    78     for(cin>>t;t;t--)
    79     {
    80         cin>>n>>m;
    81         build(1,n,1);
    82         int l,r,k;
    83         while(m--)
    84         {
    85             cin>>l>>r>>k;
    86             add(l,r,k,1);
    87         }
    88         cout<<"Case "<<Case++<<": The total value of the hook is "<<ask(1,n,1)<<"."<<endl;
    89     }
    90 }
    所遇皆星河
  • 相关阅读:
    作业一:淘宝的创新点
    asp.net面试题130道
    windows7系统下怎么将“我的电脑”图标添加到任务栏
    用jquery控制html控件
    C# windows窗口项目
    无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NET START命令启动它
    c#用反射动态获取类型
    C# 提取逗号分割的字符串
    搜索框动态匹配——前端方式(只在页面加载时从后端获取一次数据)(推荐)
    汉字转拼音的代码——(js版)
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12828827.html
Copyright © 2011-2022 走看看