GTW likes gt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 363 Accepted Submission(s): 130
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.
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.
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.
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
3HintAfter 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.
恩,题目大意就是说,分两队而站,后面是该人的能力值,然后之后的每次发功都可以使第1个到第c [ i ]个人的能力值都增加1同时第 i 个人可以打败他前面所有比他能力弱的人。恩,这一种是记录能力增加的次数
#include <iostream>
#include<cstdio>
#include<cstring>
#define maxn 50050
using namespace std;
int c[maxn];
struct Node
{
int s,p;
};
Node node[maxn];
int main()
{
int T,n,m,p;
scanf("%d\n",&T);
while(T--)
{
memset(c,0,sizeof(c));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
scanf("%d%d",&node[i].s,&node[i].p);
c[0]=c[n+1]=0;
for(int i=1;i<=m;++i)
{
scanf("%d",&p);
c[p]++;
}
for(int i=n;i>=1;i--)
c[i]+=c[i+1];
int ans=n;
int max0=-9999999;
int max1=-9999999;
for(int i=n;i>=1;i--)
{
if(node[i].s)
{
if(node[i].p+c[i]<max0)
ans--;
max1=max(max1,node[i].p+c[i]);
}
else
{
if(node[i].p+c[i]<max1)
ans--;
max0=max(max0,node[i].p+c[i]);
}
}
printf("%d\n",ans);
}
return 0;
}
恩,从第1到第c [i ]个人能力的增加相当于第c [ i+1 ] 人之后所有人的能力值减1 ,这个就是记录减的
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 50050
using namespace std;
int c[maxn];
struct Node
{
int pos,val;
};
Node node[maxn];
int main()
{
int T,n,m,p;
scanf("%d",&T);
while(T--)
{
memset(c,0,sizeof(c));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
scanf("%d%d",&node[i].pos,&node[i].val);
c[0]=c[n+1]=0;
for(int i=1;i<=m;++i)
{
scanf("%d",&p);
c[p+1]++;
}
for(int i=1;i<=n;++i)
{
c[i]+=c[i-1];
node[i].val-=c[i];
}
int ans=0;
int max0=-99999999,max1=-99999999;
for(int i=n;i>=1;i--)
{
if(node[i].pos)
{
if(node[i].val>=max0)
ans++;
max1=max(max1,node[i].val);
}
else
{
if(node[i].val>=max1)
ans++;
max0=max(max0,node[i].val);
}
}
printf("%d\n",ans);
}
return 0;
}
恩,还可以用树状数组和线段树做,但我还木写出来。。。。