2014 Multi-University Training Contest 9#11

Killing MonstersTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 562    Accepted Submission(s): 308

Problem Description

Kingdom Rush is a popular TD game, in which you should build some towers to protect your kingdom from monsters. And now another wave of monsters is coming and you need again to know whether you can get through it.

The path of monsters is a straight line, and there are N blocks on it (numbered from 1 to N continuously). Before enemies come, you have M towers built. Each tower has an attack range [L, R], meaning that it can attack all enemies in every block i, where L<=i<=R. Once a monster steps into block i, every tower whose attack range include block i will attack the monster once and only once. For example, a tower with attack range [1, 3] will attack a monster three times if the monster is alive, one in block 1, another in block 2 and the last in block 3.

A witch helps your enemies and makes every monster has its own place of appearance (the ith monster appears at block Xi). All monsters go straightly to block N.

Now that you know each monster has HP Hi and each tower has a value of attack Di, one attack will cause Di damage (decrease HP by Di). If the HP of a monster is decreased to 0 or below 0, it will die and disappear.
Your task is to calculate the number of monsters surviving from your towers so as to make a plan B.

Input

The input contains multiple test cases.

The first line of each case is an integer N (0 < N <= 100000), the number of blocks in the path. The second line is an integer M (0 < M <= 100000), the number of towers you have. The next M lines each contain three numbers, Li, Ri, Di (1 <= Li <= Ri <= N, 0 < Di <= 1000), indicating the attack range [L, R] and the value of attack D of the ith tower. The next line is an integer K (0 < K <= 100000), the number of coming monsters. The following K lines each contain two integers Hi and Xi (0 < Hi <= 10^18, 1 <= Xi <= N) indicating the ith monster’s live point and the number of the block where the ith monster appears.

The input is terminated by N = 0.

Output

Output one line containing the number of surviving monsters.

Sample Input

521 3 15 5 251 33 15 27 39 10

Sample Output

3

Hint

In the sample, three monsters with origin HP 5, 7 and 9 will survive.

 
简单的线段树,区间更新就可以!
 
 #include<cstdio>

 using namespace std;

 #define maxn 100000+10

 typedef long long LL;

 struct node{

     int l,r,m;

     LL sum,mark;

 }T[maxn<<];

 int a[maxn];

 void build(int id,int l,int r){

      T[id].l=l;   T[id].r=r;  T[id].m=(l+r)>>;  T[id].mark=;

      if(l==r)   { T[id].sum=a[l]; return;  }

      int m=(l+r)>>;

      build(id<<,l,m);  build((id<<)+,m+,r);

      T[id].sum=(T[id<<].sum+T[(id<<)+].sum);

 }

 void update(int id,int l,int r,int val){

      if(T[id].l==l&&T[id].r==r){

         T[id].mark+=val; return ;

      }

      T[id].sum+=(LL)val*(r-l+);

      if(T[id].m>=r)

           update(id<<,l,r,val);

      else if(T[id].m<l)

           update((id<<)+,l,r,val);

      else{

           update(id<<,l,T[id].m,val);

           update((id<<)+,T[id].m+,r,val);

      }

 }

 LL query(int id,int l,int r){

     if(T[id].l==l&&T[id].r==r)  return T[id].sum+T[id].mark*(LL)(r-l+);

     if(T[id].mark!=) {

         T[id<<].mark+=T[id].mark;

         T[(id<<)+].mark+=T[id].mark;

         T[id].sum+=(LL)(T[id].r-T[id].l+)*T[id].mark;  T[id].mark=;

     }

     if(T[id].m>=r){

           return query(id<<,l,r);

     }

     else if(T[id].m<l){

           return query((id<<)+,l,r);

     }

     else{

           return query(id<<,l,T[id].m)+query((id<<)+,T[id].m+,r);

     }

 }

 int main(){

     int n,Q,m;  char str[];   int b,c,d,l,r,v;

     while(scanf("%d",&n)==&&n){

             scanf("%d",&Q);

           for(int i=;i<=n;i++){

              a[i] = ;

           }

           build(,,n);

           for(int i=;i<Q;i++){

                scanf("%d%d%d",&l,&r,&v);

                     update(,l,r,v);

                }

           scanf("%d",&m);

           LL h;

           int x;

           int ans = ;

           for(int i = ;i<m;i++)

           {

               scanf("%I64d%d",&h,&x);

               if(query(,x,n)<h) ans++;

           }

           printf("%d\n",ans);

     }

     return ;

 }

2014 Multi-University Training Contest 9#11的更多相关文章

  1. HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

    Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  2. hdu 4946 2014 Multi-University Training Contest 8

    Area of Mushroom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. 2014 Multi-University Training Contest 9#6

    2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...

  4. 2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/法)

    解题报告 两人轮流取球,大的人赢,,, 贴官方题解,,,反正我看不懂.,,先留着理解 关于费马小定理 关于原根 找规律找到的,,,sad,,, 非常easy找到循环节为p-1,每个循环节中有一个非零的 ...

  5. 2014 Multi-University Training Contest 1/HDU4864_Task(贪心)

    解题报告 题意,有n个机器.m个任务. 每一个机器至多能完毕一个任务.对于每一个机器,有一个最大执行时间Ti和等级Li,对于每一个任务,也有一个执行时间Tj和等级Lj.仅仅有当Ti>=Tj且Li ...

  6. hdu 4937 2014 Multi-University Training Contest 7 1003

    Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) T ...

  7. hdu 4941 2014 Multi-University Training Contest 7 1007

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  8. hdu 4939 2014 Multi-University Training Contest 7 1005

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  9. 2015 Multi-University Training Contest 10(9/11)

    2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...

随机推荐

  1. java程序设计之完数

    题目:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程 找出1000以内的所有完数. 解题过程也很简单: public class wanshu { ...

  2. django博客功能实现——标签功能

    标签功能添加流程 0.功能概括 标签作为文章中的分类标记,会显示出该文章是关于哪一方面的文章,比如是关于python的还是关于django的. 当我们点击该标签的时候,会出现该博客中所有属于该标签的文 ...

  3. 通过bitmap对100w数字进行排序去重

    首先生成100w随机数,控制最大数 <?php $i = 0; do{ $i++; $num = rand(0, 999999); echo $num."\n"; }whil ...

  4. Log4J日志配置详解

    一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...

  5. Chrome 控制台console的用法(转)

    下面我们来看看console里面具体提供了哪些方法可以供我们平时调试时使用. 目前控制台方法和属性有: ["$$", "$x", "dir" ...

  6. Linux基础 - scp免密码登陆进行远程文件同步

    在工作中经常有遇到需要脚本自动化同步文件的地方,比如数据库异地备份.假设有两台机子A(192.168.16.218)和B(192.168.16.117),需要能够让A免密码连接B. 先来看看正常的ss ...

  7. 初学C#和MVC的一些心得,弯路,总结,还有教训(3)--Dapper

    经过一番深思熟虑,决定先用Dapper吧..... 以下是我感觉比较有用的一些东西 Dapper项目地址  https://github.com/StackExchange/dapper-dot-ne ...

  8. tensorflow学习笔记五:mnist实例--卷积神经网络(CNN)

    mnist的卷积神经网络例子和上一篇博文中的神经网络例子大部分是相同的.但是CNN层数要多一些,网络模型需要自己来构建. 程序比较复杂,我就分成几个部分来叙述. 首先,下载并加载数据: import ...

  9. 《Java学习笔记(第8版)》学习指导

    <Java学习笔记(第8版)>学习指导 目录 图书简况 学习指导 第一章 Java平台概论 第二章 从JDK到IDE 第三章 基础语法 第四章 认识对象 第五章 对象封装 第六章 继承与多 ...

  10. 记一次事件委托在 ios 下的兼容 bug

    项目中碰到的兼容类 bug,记录一二. 页面上有几个同类型的控件,点击它们会触发一些事件,很显然,事件委托优于批量绑定.为了图方便,我将 click 事件绑定到了 document.body 上(绑定 ...