GTW likes gt

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 833    Accepted Submission(s): 299

Problem Description
Long long ago, there were n adorkable GT. Divided into two groups, they were playing games together, forming a column. The i−th GT would randomly get a value of ability bi. At the i−th second, the i−th GT would annihilate GTs who are in front of him, whose group differs from his, and whose value of ability is less than his.

In order to make the game more interesting, GTW, the leader of those GTs, would emit energy for m times, of which the i−th time of emitting energy is ci. After the ci second, b1,b2,...,bci would all be added 1.

GTW wanted to know how many GTs would survive after the n−th second.

 
Input
The first line of the input file contains an integer T(≤5), which indicates the number of test cases.

For each test case, there are n+m+1 lines in the input file.

The first line of each test case contains 2 integers n and m, which indicate the number of GTs and the number of emitting energy, respectively.(1≤n,m≤50000)

In the following n lines, the i−th line contains two integers ai and bi, which indicate the group of the i−th GT and his value of ability, respectively. (0≤ai≤1,1≤bi≤106)

In the following m lines, the i−th line contains an integer ci, which indicates the time of emitting energy for i−th time.

 
Output
There should be exactly T lines in the output file.

The i−th line should contain exactly an integer, which indicates the number of GTs who survive.

 
Sample Input
1
4 3
0 3
1 2
0 3
1 1
1
3
4
 
Sample Output
3

Hint

After the first seconds,$b_1=4,b_2=2,b_3=3,b_4=1$
After the second seconds,$b_1=4,b_2=2,b_3=3,b_4=1$
After the third seconds,$b_1=5,b_2=3,b_3=4,b_4=1$,and the second GT is annihilated by the third one.
After the fourth seconds,$b_1=6,b_2=4,b_3=5,b_4=2$
$c_i$ is unordered.

 
Source
 

题目大意:有n个gt(认为是一种动物),每个有一个法力值b[i],有0,1两个组,在第i秒的时候,第i只gt可以消灭前面不跟他一组且法力值小于他的gt。有一个巫师,发m次功,在c[i]秒的时候发功,在第c[i]秒结束后,b[i],b[2]...b[c[i]]都会增加1。问你最后活下来的有多少只gt。

解题思路:倒着处理,首先预处理出来第i秒时第i只gt的法力值增量dv[i]。然后维护每组当前的最大法力值Max。对于每只gt,我们判断他跟另外一组最大法力值的关系,同时维护该组的最大法力值。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+2000;
struct GT{
int group,val;
}gts[maxn];
int dv[maxn], b[maxn];
int main(){
int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i = 1;i <= n; i++){
scanf("%d%d",&gts[i].group,&gts[i].val);
dv[i] = 0;
}
dv[n+1] = 0;
for(int i = 1;i <= m; i++){
scanf("%d",&b[i]);
dv[b[i]]++;
}
for(int i = n; i >= 1; i--){
dv[i] += dv[i+1];
}
int Max0 = -1, Max1 = -1, ans = 0;
for(int i = n; i >= 1; i--){
if(gts[i].group == 1){
if(gts[i].val + dv[i] < Max0){
ans++;
}
if(gts[i].val + dv[i] > Max1){
Max1 = gts[i].val + dv[i];
}
}else{
if(gts[i].val + dv[i] < Max1){
ans++;
}
if(gts[i].val + dv[i] > Max0){
Max0 = gts[i].val + dv[i];
}
}
}
printf("%d\n",n-ans);
}
return 0;
}

  

HDU 5596 ——GTW likes gt——————【想法题】的更多相关文章

  1. HDU 5596 GTW likes gt 倒推

    GTW likes gt 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Long long ago, there w ...

  2. hdu 5596 GTW likes gt

    题目链接: hdu 5596 题意不难懂(虽然我还是看了好久)大概就是说 n 个人排成一列,分成两组, 第 i 秒时第 i 个人会消灭掉前面比他 b[i] 值低的且和他不同组的人,c[i] 表示第 c ...

  3. HDU 5597 GTW likes function 打表

    GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...

  4. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  5. HDU 4972 Bisharp and Charizard 想法题

    Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He ...

  6. HDU - 5969 最大的位或 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5969 (合肥)区域赛签到题...orz 题意:给你l,r,求x|y的max,x,y满足l<=x<=y ...

  7. Hdu 5595 GTW likes math

    题意: 问题描述 某一天,GTW听了数学特级教师金龙鱼的课之后,开始做数学<从自主招生到竞赛>.然而书里的题目太多了,GTW还有很多事情要忙(比如把妹),于是他把那些题目交给了你.每一道题 ...

  8. HDU 5632 Rikka with Array [想法题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5632 ------------------------------------------------ ...

  9. HDU 5597 GTW likes function 欧拉函数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contes ...

随机推荐

  1. CI框架集成Smarty

    1.下载smarty源码包,解压放置于项目目录 libriaries中 2.在libraries中建立Cismarty.php ,填写如下代码 <?php if(!defined('BASEPA ...

  2. windows查看和杀死占用端口的进程

    1.首先使用 netstat -ano查看占用端口的进程号 2.然后使用 taskkill /PID (进程号)杀死进程

  3. LoadRunner11_MySQL数据库脚本

    记录一次压测过程中,通过LoadRunner向MySQL数据库插入大量数据的过程. [1]需要使用到MySQL的libmysql.dll动态链接库,因此需要安装MySQL:注:本地安装的MySQL最好 ...

  4. leecode刷题(4)-- 存在重复数组

    leecode刷题(4)-- 存在重复数组 存在重复数组 题目描述: 给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 ...

  5. LAMP课程(3)

    LAMP课程(3) 一.bash的使用 1.1.输出重定向 >:覆盖输出(写入内容) 具体实例1:将内容写入到文件中   >>:追加输出 具体实例2:   1.2 && ...

  6. 利用百度翻译API批量翻译文本

    有时间再做总结! # coding=utf-8 #authority:bing #2017-7-18 import httplib import md5 import urllib import ur ...

  7. MongDB from execCommand not master

    count failed: not master{ , "errmsg" : "not master" } at src/mongo/shell/query.j ...

  8. Flink学习笔记:异步I/O访问外部数据

    本文为<Flink大数据项目实战>学习笔记,想通过视频系统学习Flink这个最火爆的大数据计算框架的同学,推荐学习课程: Flink大数据项目实战:http://t.cn/EJtKhaz ...

  9. Eclipse 使用TFS

    Install Soft , –> add http://dl.microsoft.com/eclipse/tfs   form:http://msdn.microsoft.com/en-us/ ...

  10. 编写高质量代码:Web前端开发修炼之道(一)

    最近老大给我们买来一些技术方面的书籍,其实很少搬着一本书好好的完整的看完过,每每看电子档的,也是打游击式的看看这章,瞅瞅那章,在那5本书中挑了一本比较单薄的<编写高质量代码web前端开发修炼之道 ...