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. 百度地图离线API及地图数据下载工具

    全面介绍,请看下列介绍地址,改写目前最新版本的百度V2.0地图,已全面实现离线操作,能到达在线功能的95%以上 http://api.jjszd.com:8081/apituiguang/gistg. ...

  2. react-native自定义原生组件

    此文已由作者王翔授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 使用react-native的时候能够看到不少函数调用式的组件,像LinkIOS用来呼起url请求  Link ...

  3. django 实现电子支付功能

    思路:调用第三方支付 API 接口实现支付功能.本来想用支付宝来实现第三方网站的支付功能的,但是在实际操作中发现支付宝没有 Python 接口,网上虽然有他人二次封装的的 Python 接口,但是对我 ...

  4. Mac 安装 mysqlclient

    尝试在虚拟环境下通过 pip 安装: pip install mysqlclient 然后报错:OSError: mysql_config not found 找到官方文档 https://githu ...

  5. 洛谷P1640 [SCOI2010]连续攻击游戏(二分图)

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...

  6. mysql设计-基本操作

    mysql 设计 1)服务器管理 2)数据库管理 3)表管理 4)字段管理 5)索引管理 操作 1)sql语句 2)单表操作 3)多表操作 索引 记录 字段 mysam innodb ibdata1 ...

  7. SDUT OJ 数据结构实验之排序一:一趟快排

    数据结构实验之排序一:一趟快排 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  8. jquery实现淘宝动态图展示商品

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. String Reduction问题分析

    问题描述: Given a string consisting of a,b and c's, we can perform the following operation: Take any two ...

  10. [JLOI2015]管道连接(斯坦纳树)

    [Luogu3264] 原题解 多个频道,每个频道的关键点要求相互联通 详见代码,非常巧妙 #include<cstdio> #include<iostream> #inclu ...