献上我一次性AC的代码,第二题看花的题目 public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); int m = scanner.nextInt(); int[] watch = new int[n+1]; int i = 1; while (i < n+1) { watch[i++] = scanner.nextInt(); } int q = scanner.nextInt(); i = 0; int[][] questions = new int[q][2]; while (i < q) { questions[i][0] = scanner.nextInt(); questions[i][1] = scanner.nextInt(); i++; } processData(watch, questions, n); } } public static void processData(int[] watch, int[][] ques, int n) { Set<Integer> flours = null; for (int i = 0; i < ques.length; i++) { int start = ques[i][0]; int end = ques[i][1]; if (start < 1) start = 1; if (end > n) end = n; flours = new HashSet<>(); while (start <= end) { flours.add(watch[start++]); } System.out.println(flours.size()); } }
点赞 评论

相关推荐

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