본문 바로가기

Coding Test/백준

[백준/자바] 10810 - 공 넣기

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        int[] balls = new int[n];
        for(int i=0; i<m; i++){
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());

            for(int j=a; j<=b; j++){
                balls[j - 1] = k;
            }
        }

        StringBuilder sb = new StringBuilder();
        for(int ball : balls){
            sb.append(ball + " ");
        }

        System.out.println(sb);

        br.close();
    }
}