[每日一题] 4.21 糖糖别胡说,我真的不是签到题目

糖糖别胡说,我真的不是签到题目

http://www.nowcoder.com/questionTerminal/9d5b203a30bc4e7b85f1838d60cf2236

题意:



解法:





时间复杂度:

std:

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int maxn = 500005;
struct node{
    int x;
    ll y;
}a[maxn];
ll b[maxn];
int main()
{
    int t,n,m,x;
    scanf("%d",&t);
    while(t--){
        memset(b,0,sizeof(b));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)scanf("%d%lld",&a[i].x,&a[i].y);
        for(int i=1;i<=m;i++)scanf("%d",&x),b[x]++;
        for(int i=n;i>=1;i--)b[i] += b[i+1] , a[i].y += b[i];
        int cnt = 0;
        ll max0 = 0, max1 = 0;
        for(int i=n;i>=1;i--){
            if(a[i].x == 0){
                max0 = max(max0 , a[i].y);
                if(max1 > a[i].y)
                    cnt++;
            }
            else{
                max1 = max(max1 , a[i].y);
                if(max0 > a[i].y)
                    cnt++;
            }
        }
        printf("%d\n",n - cnt);
    }
    return 0;
}
acm菜鸡日常 文章被收录于专栏

一般写一些打过的比赛题解以及不会的算法

全部评论
博主 18 19行的操作叫什么啊,感觉好神奇 和差分有点像
1 回复 分享
发布于 2020-06-25 22:01
1 4 3 0 3 1 6 0 3 1 1 1 1 1 这组数据你这解法好像存在问题,和题意不符合
点赞 回复 分享
发布于 2021-04-14 18:16

相关推荐

身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
程序员小白条:木的办法, 以后越来越差,还是家附近宅着吧,毕业的人越来越多,岗位都提供不出来,经济又过了人口红利期
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 13:47
点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
24
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务