滴滴9月17第二题ak代码,差分数组

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(); int p=sc.nextInt(); int q=sc.nextInt();
        sc.nextLine();
        int[][] a=new int[n][3];
        a[0]=Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        a[1]=Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        a[2]=Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        Map<Integer,int[]> map=new HashMap<>();
        for(int i=0;i<n;i++){
            int[] tmp1=map.getOrDefault(a[0][i]-1, new int[2]);
            int[] tmp2=map.getOrDefault(a[1][i], new int[2]);
            tmp1[a[2][i]-1]--;
            tmp2[a[2][i]-1]++;
            map.put(a[0][i]-1, tmp1);
            map.put(a[1][i], tmp2);
        }
        List<Map.Entry<Integer,int[]>> list=new ArrayList<>();
        for(Map.Entry<Integer,int[]> v:map.entrySet()){
            list.add(v);
        }
        Collections.sort(list,(x, y)->{
            return y.getKey()-x.getKey();
        });
        // System.out.println(list.size());
        int res=0;
        int curp=0, curq=0;
        int lastk=-1;
        for(Map.Entry<Integer,int[]> v : list){
            int tmpk=v.getKey();
            //System.out.println(tmpk);
            int[] tmpv=v.getValue();
            if(lastk==-1){
                curp+=tmpv[0];
                curq+=tmpv[1];
                lastk=tmpk;
            }else{
                if(curp>=p&&curq>=q){
                    res+=lastk-tmpk;
                }
                curp+=tmpv[0];
                curq+=tmpv[1];
                lastk=tmpk;
            }
        }
        System.out.println(res);
    }
}

全部评论
差分离散化😖忘记离散化了
点赞 回复 分享
发布于 2022-09-17 16:52 陕西

相关推荐

04-02 10:09
门头沟学院 Java
用微笑面对困难:这里面问题还是很多的,我也不清楚为啥大家会感觉没啥问题。首先就是全栈开发实习9个月的内容都没有java实习生的内容多,1整个技术栈没看出太核心和难点的内容,感觉好像被拉过去打杂了,而且全栈基本上很容易被毙。里面能问的bug是在太多了比如L:继承 BaseMapper 可直接使用内置方法’。请问你的 BaseMapper 是如何扫描实体类注解如果瞬时产生 100 个上传任务,MySQL 的索引设计是否会有瓶颈?你做过分库分表或者索引优化吗?全栈的内容可以针对动态难点去搞,技能特长写在下面吧,你写了这么多技能,项目和实习体现了多少?你可以在项目里多做文章然后把这个放下去,从大致来看实习不算太水,有含金量你也要写上内容针对哨兵里面的节点变化能问出一万个问题,这个很容易就爆了。
提前批简历挂麻了怎么办
点赞 评论 收藏
分享
评论
2
3
分享

创作者周榜

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