다른 풀이법으로 세그먼트 트리, 라인스위핑이 생각나긴 하는데 N,Q <= 1000 이라 O(NQ)기 때문에 들어오는대로 그때그때 처리해 주면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
 
int t,n,q,a,b;
int arr[1001];
 
int main(void) {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> t;
    for (int tc = 1; tc <= t; ++tc) {
        cin >> n >> q;
        memset(arr, 0sizeof(arr));
        for (int i = 1; i <= q; ++i) {
            cin >> a >> b;
            for (; a <= b; a++) arr[a] = i;
        }
        cout << "#" << tc << " ";
        for (int i = 1; i <= n; ++i) cout << arr[i] << " ";
        cout << '\n';
    }
    return 0;
}
cs


'SWEA' 카테고리의 다른 글

5548. 태양이의 캠프 조합  (0) 2018.10.16
5785. 살아남은 투자가는 누구일까  (0) 2018.10.16
1824. 혁진이의 프로그램 검증  (0) 2018.10.08
2112. 보호 필름  (0) 2018.10.08
4740. 밍이의 블록게임  (0) 2018.10.07

+ Recent posts