MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Method main

editorial/chap4-2/prob4-2-2.java:4–36  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

2
3class Main {
4 public static void main(String[] args) {
5 Scanner sc = new Scanner(System.in);
6 int[] A = new int[500009];
7 int[] B = new int[500009];
8 int[] L = new int[500009];
9 int[] R = new int[500009];
10
11 // 入力
12 int T = sc.nextInt();
13 int N = sc.nextInt();
14 for (int i = 1; i <= N; i++) {
15 L[i] = sc.nextInt();
16 R[i] = sc.nextInt();
17 }
18
19 // 階差 B[i] を計算する
20 for (int i = 0; i <= T; i++) B[i] = 0;
21 for (int i = 1; i <= N; i++) {
22 B[L[i]] += 1;
23 B[R[i]] -= 1;
24 }
25
26 // 累積和 A[i] を計算する
27 A[0] = B[0];
28 for (int i = 1; i < T; i++) {
29 A[i] = A[i - 1] + B[i];
30 }
31
32 // 答えを出力
33 for (int i = 0; i < T; i++) {
34 System.out.println(A[i]);
35 }
36 }
37}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected