๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][10810][๊ณต ๋„ฃ๊ธฐ]

๋‰ด์ด NUEY 2023. 10. 22. 20:01
๋ฐ˜์‘ํ˜•

ํ’€์ด๋ณด๋‹ค ๋ฌธ์ œํ•ด์„์ด ์ œ์ผ ์–ด๋ ค์› ๋‹ค...

  • n๊ฐœ์˜ ๋ฐ”๊ตฌ๋‹ˆ, 1๋ถ€ํ„ฐ n๊นŒ์ง€ ์ ํžŒ ๊ณต.
  • m๋ฒˆ ๋„ฃ๋Š”๋‹ค.
  • ๊ณต์„ ํ•˜๋‚˜๋งŒ ๋„ฃ์„ ์ˆ˜ ์žˆ๊ณ , ๊ณต์ด ์žˆ์œผ๋ฉด ๋นผ์„œ ๋‹ค์‹œ ๋„ฃ๋Š”๋‹ค.

    ๊ทธ๋ž˜์„œ ์˜ˆ์ œ์ž…๋ ฅ ํ•˜๋‹จ
    1 4 1 
    2 2 2
    ๊ฐ€ ์˜ˆ์ œ์ถœ๋ ฅ์ด ๋˜๋Š” ๊ฑฐ๋‹ค.
    ์œ„์— ๋„ฃ์—ˆ๋˜ ๊ฑฐ ๋‹ค ๋นผ๊ณ  ์ƒˆ๋กœ ๋„ฃ์–ด์„œ.
    1 4 1 : 1๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ๋ถ€ํ„ฐ 4๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ๊นŒ์ง€ 1์„ ๋„ฃ์—ˆ๋‹ค.
    2 2 2 : 2๋ฒˆ ๊ณต์„ 2๋ฒˆ ๋ฐ”๊ตฌ๋‹ˆ์— ๋„ฃ๋Š”๋‹ค.
import java.util.Scanner;

public class Main {

	// 10810	๊ณต ๋„ฃ๊ธฐ
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] res = new int[sc.nextInt()+1];
		int m = sc.nextInt();
		
		for (int a=1; a<=m; a++) {
			int i = sc.nextInt();
			int j = sc.nextInt();
			int k = sc.nextInt();
			
			for (int b=i; b<=j; b++) {
				res[b] = k;
			}
		}
		sc.close();
		
		for (int i=1; i<res.length; i++) {
			System.out.print(res[i] + " ");
		}
	}
}
๋ฐ˜์‘ํ˜•