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. C语言中无符号与有符号问题

    unsigned char a[5] = { 12,36,96,128,182 }; a[]范围为0~256. 数组中数都有效. char a[5] = { 12,36,96,128,182 }; a ...

  2. 解决git一直输入用户名和密码的问题

    git config --system --unset credential.helper,在git中输入此命令后,每次拉去代码需要重新输入用户名和密码,可以使用git config --global ...

  3. 【大数据系统架构师】0.2 Linux基础

    1. Linux基本环境 1.1 大数据Hadoop前置大纲讲解 1)Linux系统,基本命令 2)Java语言,JavaSE相关知识 3)MySQL基本的DML和DDL 1.2 常见Linux系统. ...

  4. kali linux之webshell

    webacoo(web backdoor cookie) 类终端的shell 编码通信内容通过cookie头传输,隐蔽性较强 cm:base64编码的命令 cn:服务器用于返回数据的cookie头的名 ...

  5. underscore里面的debounce与throttle

    throttle 策略的电梯.保证如果电梯第一个人进来后,15秒后准时运送一次,不等待.如果没有人,则待机. debounce 策略的电梯.如果电梯里有人进来,等待15秒.如果又人进来,15秒等待重新 ...

  6. Tarjan 点双+割点+DFS【洛谷P3225】 [HNOI2012]矿场搭建

    P3225 [HNOI2012]矿场搭建 题目描述 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤 ...

  7. java集合之Set接口

    Set集合通常不能记住元素添加的顺序,其他的操作和它的父接口基本相同.只是行为上有细微的差别,Set集合不能包含相同的元素.如果尝试添加相同的元素,调用add()方法将返回false,且新元素不能被加 ...

  8. _.each _.map _.filter javascript 语法

    1.forEach():没有返回值,只是针对每个元素调用func     简单来说,就是将数组中的每个值,依次进行遍历,执行功能函数     如果只需对数组元素进行操作,不需返回任何值时适用 var ...

  9. Android 生成xml文件及xml的解析

    1.生成xml文件的两种方式 (1)采用拼接的方式生成xml(不推荐使用) (2)利用XmlSerializer类生成xml文件 package com.example.lucky.test52xml ...

  10. 老男孩python作业6-选课系统开发

    角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. 课程包含,周期,价格 ...