GTW likes gt

 Accepts: 75
 Submissions: 261
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 131072/131072 K (Java/Others)
Problem Description

Long long ago, there were nn 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 b​i​​. 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 mm times, of which the i−th time of emitting energy is c​i​​. After the c​i​​ second, b​1​​,b​2​​,...,b​c​i​​​​ 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 integerT(≤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 nn and mm, which indicate the number of GTs and the number of emitting energy, respectively.(1≤n,m≤50000)

In the following nn lines, the i−th line contains two integers a​i​​ and b​i​​, which indicate the group of the i−th GT and his value of ability, respectively. (0≤a​i​​≤1,1≤b​i​​≤10^​6​​)

In the following mm lines, the i−th line contains an integer c​i​​, 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.

GTW likes gt

 Accepts: 75
 Submissions: 261
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 131072/131072 K (Java/Others)
问题描述
从前,有nn只萌萌的GT,他们分成了两组在一起玩游戏。他们会排列成一排,第i只GT会随机得到一个能力值b​i​​。在第i秒的时候,第i只GT可以消灭掉所有排在他前面的和他不是同一组的且能力值小于他的GT。
为了使游戏更加有趣,GT的首领GTW会发功mm次,第ii次发功的时间为c​i​​,则在第c​i​​秒结束后,b​1​​,b​2​​,...,b​c​i​​​​都会增加1。
现在,GTW想知道在第nn秒之后,会有几只GT存活下来。
输入描述
第一行只有一个整数T(T≤5),表示测试数据组数。
第二行有两个整数n,m。表示GT的个数和GTW发功的次数。( 500001≤n≤50000,1≤m≤50000)
第三到n+2行,每行有两个整数a​i​​,b​i​​,表示第ii只GT在哪个组和他的能力值 (0≤a[i]≤1,1≤b[i]≤10​6​​)
第n+3行到第n+m+2行,每行有一个整数c​i​​,表示GTW第i次发功的时间。 1≤c[i]≤n
输出描述
总共T行,第i行表示第i组数据中,GT存活的个数。
输入样例
1
4 3
0 3
1 2
0 3
1 1
1
3
4
输出样例
3
Hint
第1秒后 能力值为4 2 3 1
第2秒后 能力值为4 2 3 1
第3秒后 能力值为5 3 4 1,第2只GT被第3只GT消灭掉了
第4秒后 能力值为6 4 5 2
c​i​​并不是有序的
我们先通过题意先计算出最后他们有多少能力值,然后,我们用两个容器分别装他们,如果可以干掉,就把它删除,然后就两个容器大小之和就好
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
map<int,int> q;
multiset<int> q0;
multiset<int> q1;
multiset<int>::iterator it;
int i,j;
int t;
int n,m;
struct P
{
int a,b;
}L[100000];
int c;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d%d",&L[i].a,&L[i].b);
}
for(i=1;i<=m;i++)
{
scanf("%d",&c);
q[c]++;
}
for(i=n-1;i>=1;i--)
{
q[i]+=q[i+1];
}
for(i=1;i<=n;i++)
{
L[i].b+=q[i];
// cout<<L[i].b<<endl;
}
for(i=1;i<=n;i++)
{
if(L[i].a==0)
{
while(q1.size())
{
it=q1.begin();
if(*it<L[i].b)
{
q1.erase(it);
}
else
{
break;
}
}
q0.insert(L[i].b);
}
else if(L[i].a==1)
{
while(q0.size())
{
it=q0.begin();
if(*it<L[i].b)
{
q0.erase(it);
}
else
{
break;
}
}
q1.insert(L[i].b);
}
}
// cout<<q0.size()+q1.size()<<endl;
printf("%d\n",q0.size()+q1.size());
q.clear();q0.clear();q1.clear();
} return 0;
}

  

 

BestCoder Round #66 1002的更多相关文章

  1. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  2. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  3. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  4. Manacher BestCoder Round #49 ($) 1002 Three Palindromes

    题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...

  5. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  6. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  7. BestCoder Round #66 (div.2) 1002

    GTW likes gt  Accepts: 132  Submissions: 772  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  8. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

  9. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

随机推荐

  1. CORS实现跨域Ajax

    客户端 #!/usr/bin/env python import tornado.ioloop import tornado.web class MainHandler(tornado.web.Req ...

  2. [转]PHP 面试问哪些问题可以比较准确的反映出应聘者的开发水平?

    基础题 场景: 你入职了一家新公司. 上班第一天,接待人给你安排好了座位,然后拉过来一台没拆封的新电脑. 你把电脑连接好之后,按下电源.... 好吧,这真是一台新电脑,里边竟然内置了个DOS系统!! ...

  3. Windows 安装 Microsoft Visual Studio 2010

    Windows 安装 VS2010 我的电脑系统:Windows 10 x64位 我要安装的Microsoft Visual Studio 是:VS2010 注意: VS2010 没有专门的64位版. ...

  4. parseXXX的用法

    转换字符串. parseXXX是Integer类.等基本数据类型包装类的方法,用于实现String和int型数据的转换.例如, Integer.getInteger(String s) 从字符串中获取 ...

  5. p3295 [SCOI2016]萌萌哒

    传送门 分析 我们可以将一个点拆成logN个点,分别代表从点i开始,长度为2^k的子串 那么当我们处理两个区间相等的关系时,对区间做二进制拆分,拆成log个区间,分别并起来即可 当然我们这样做修改是省 ...

  6. Luogu 1514 [NOIP2010] 引水入城

    我就是过来开心一下……这道题从开坑以来已经堆积了大半年了……今天才发现广搜一直写挂…… 丢个线段覆盖的模板,设$f_{i}$表示覆盖区间[1, i]的最小代价,$g_{i, j}$表示覆盖区间[i, ...

  7. Luogu 4323 [JSOI2016]独特的树叶

    新技能get 树哈希,考虑到两棵树相同的条件,把每一个结点的哈希值和树的siz写进哈希值里去. 做出A树每一个结点为根时的树的哈希值丢进set中,然后暴力枚举B树中度数为1的点,求出删掉这个点之后的哈 ...

  8. debug---null Pointer Exception--一步步查找(2)

    添加PartyLocationRepository后,再次在Ubuntu中编译项目,再次报空指针异常. 直接在createDto处打断点,然后debug每个表达式的值,找出来到底是哪个为null. 经 ...

  9. SSH框架(四) struts2+spring3.0的登陆示例

    (一)关键理念及需要注意的地方: 使用struts2+spring3.0的框架搭建web程序,就是使用spring来进行依赖注入(依赖注入请参考baidu上面的解释:http://baike.baid ...

  10. SSH (Struts2+Spring3.0+Hibernate3)框架(二) 框架的配置

    一.准备工作: 1. JDK -> jdk1.6.0_17 安装(环境变量配置): JAVA_HOME = C:\ jdk1.6.0_17; PATH = %JAVA_HOME%\bin; %J ...