HDU 5596/BC 66B GTW likes gt

很巧妙的一道题 

首先在要发功影响的时间点添加标记 然后从后往前扫 同时累计标记 并且记录两组中已经扫过的最大值 扫到当前位置时 就可以进行统计了

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define INF (1ll<<62)
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
using namespace std;
typedef long long ll;
#define bug puts("===========");
const double pi=(acos(-1.0));
const double eps=1e-8;
const int inf=1e9+10;
const int maxn=300000+5;
const int mod=1e9+7;
/*===============================*/
struct rd
{
    int zu,v;
} a[maxn];
int add[maxn],c[maxn];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int max0=-1,max1=-1;
        memset(add,0,sizeof(add));
        int n,m,ans=0;
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++){
            scanf("%d%d",&a[i].zu,&a[i].v);
        }
        for(int i=0; i<m; i++){
            scanf("%d",&c[i]);
            add[c[i]]++;
        }
        for(int i=n; i>=1; i--){
            add[i]+=add[i+1];
            a[i].v+=add[i];
            if(a[i].zu){
                max1=max(max1,a[i].v);
                if(max0>=a[i].v) ans++;
            }
            else {
                max0=max(max0,a[i].v);
                if(max1>=a[i].v) ans++;
            }
        }
        printf("%d\n",n-ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值