public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); Map<Integer,List<Integer>> map = new HashMap<Integer, List<Integer>>(n); List<Integer> list; for(int i=1; i<=n; i++){ int ki = in.nextInt(); if(map.containsKey(ki)){ list = map.get(ki); list.add(i); }else{ list = new ArrayList<Integer>(); list.add(i); map.put(ki,list); } } int count; int q = in.nextInt(); for(int i=0; i<q; i++){ int l = in.nextInt(); int r = in.nextInt(); int k = in.nextInt(); count = 0; if(!map.containsKey(k)){ System.out.println(count); continue; } list = map.get(k); for(Integer num : list){ if(num>=l && num<=r){ count++; } } System.out.println(count); } } 我这样暴搜也没超,还AC了
点赞 1

相关推荐

废铁汽车人:秋招真是牛鬼蛇神齐聚一堂
点赞 评论 收藏
分享
牛客网
牛客企业服务