답안 #914256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914256 2024-01-21T13:02:20 Z esomer Curtains (NOI23_curtains) C++17
100 / 100
860 ms 70580 KB
#include<bits/stdc++.h>
 
using namespace std;

struct segTree{
    vector<int> v, upd;
    int sz;
    void init(int n){
        sz = 1;
        while(sz < n) sz *= 2;
        v.assign(2 * sz, 1e9);
        upd.assign(2 * sz, 1e9);
    }
    void set(int l, int r, int val, int x, int lx, int rx){
        if(lx >= l && rx <= r){
            v[x] = min(val, v[x]);
            upd[x] = min(val, upd[x]);
            return;
        }else if(lx >= r || rx <= l) return;
        int m = (lx + rx) / 2;
        set(l, r, val, 2 * x + 1, lx, m);
        set(l, r, val, 2 * x + 2, m, rx);
        v[x] = min(max(v[2 * x + 1], v[2 * x + 2]), upd[x]);
    }

    void set(int l, int r, int val){
        set(l, r, val, 0, 0, sz);
    }

    int compare(int a, int b){
        if(a == 2e9) return b;
        else if(b == 2e9) return a;
        else return max(a, b);
    }

    int calc(int l, int r, int x, int lx, int rx){
        if(lx >= l && rx <= r) return v[x];
        else if(lx >= r || rx <= l) return 2e9;
        int m = (lx + rx) / 2;
        int c1 = calc(l, r, 2 * x + 1, lx, m);
        int c2 = calc(l, r, 2 * x + 2, m, rx);
        // cout << "x "<< x << " lx "<< lx << " rx "<< rx << " v[x] "<< v[x] << " upd[x] "<< upd[x] << " c1 "<< c1 << " c2 "<< c2 << "\n";
        return min(compare(c1, c2), upd[x]);
    }

    int calc(int l, int r){
        return calc(l, r, 0, 0, sz);
    }
};

void solve(){
    int n, m, q; cin >> n >> m >> q;
    vector<vector<int>> startCurtain(n);
    for(int i = 0; i < m; i++){
        int l, r; cin >> l >> r; l--; r--;
        startCurtain[l].push_back(r);
    }
    vector<vector<int>> startQuery(n);
    vector<pair<int, int>> queries(q);
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r; l--; r--;
        queries[i] = {l, r};
        startQuery[l].push_back(i);
    }
    segTree st; st.init(n);
    vector<bool> ans(q);
    for(int i = n - 1; i >= 0; i--){
        for(int r : startCurtain[i]){
            // cout << "add "<< i << " "<< r << " " << endl;
            st.set(i, r + 1, r);
        }
        for(int j : startQuery[i]){
            int l = queries[j].first;
            int r = queries[j].second;
            // cout << "l "<< l << " r "<< r << " calc "<< st.calc(l, r + 1) << "\n";
            if(st.calc(l, r + 1) <= r) ans[j] = true;
            else ans[j] = false;
        }
    }
    for(bool b : ans){
        if(b) cout << "YES\n";
        else cout << "NO\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    // int tt; cin >> tt;
    int tt = 1;
    while(tt--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 146 ms 12868 KB Output is correct
23 Correct 143 ms 13492 KB Output is correct
24 Correct 173 ms 14568 KB Output is correct
25 Correct 278 ms 19284 KB Output is correct
26 Correct 169 ms 13396 KB Output is correct
27 Correct 262 ms 19340 KB Output is correct
28 Correct 267 ms 17080 KB Output is correct
29 Correct 135 ms 11680 KB Output is correct
30 Correct 124 ms 10212 KB Output is correct
31 Correct 119 ms 10856 KB Output is correct
32 Correct 228 ms 15812 KB Output is correct
33 Correct 105 ms 10432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 113 ms 10188 KB Output is correct
9 Correct 119 ms 10724 KB Output is correct
10 Correct 228 ms 15636 KB Output is correct
11 Correct 115 ms 10432 KB Output is correct
12 Correct 82 ms 11720 KB Output is correct
13 Correct 99 ms 11692 KB Output is correct
14 Correct 70 ms 12244 KB Output is correct
15 Correct 65 ms 11984 KB Output is correct
16 Correct 64 ms 11988 KB Output is correct
17 Correct 65 ms 11976 KB Output is correct
18 Correct 556 ms 54304 KB Output is correct
19 Correct 533 ms 54464 KB Output is correct
20 Correct 442 ms 55172 KB Output is correct
21 Correct 438 ms 54964 KB Output is correct
22 Correct 422 ms 54880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 78 ms 5180 KB Output is correct
23 Correct 71 ms 5204 KB Output is correct
24 Correct 102 ms 13136 KB Output is correct
25 Correct 105 ms 13128 KB Output is correct
26 Correct 87 ms 14924 KB Output is correct
27 Correct 115 ms 14932 KB Output is correct
28 Correct 72 ms 12628 KB Output is correct
29 Correct 98 ms 14652 KB Output is correct
30 Correct 112 ms 13136 KB Output is correct
31 Correct 101 ms 13136 KB Output is correct
32 Correct 110 ms 13392 KB Output is correct
33 Correct 88 ms 13908 KB Output is correct
34 Correct 97 ms 12884 KB Output is correct
35 Correct 98 ms 12368 KB Output is correct
36 Correct 92 ms 12884 KB Output is correct
37 Correct 93 ms 11720 KB Output is correct
38 Correct 83 ms 11844 KB Output is correct
39 Correct 69 ms 12040 KB Output is correct
40 Correct 80 ms 12008 KB Output is correct
41 Correct 68 ms 11988 KB Output is correct
42 Correct 76 ms 11976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 146 ms 12868 KB Output is correct
23 Correct 143 ms 13492 KB Output is correct
24 Correct 173 ms 14568 KB Output is correct
25 Correct 278 ms 19284 KB Output is correct
26 Correct 169 ms 13396 KB Output is correct
27 Correct 262 ms 19340 KB Output is correct
28 Correct 267 ms 17080 KB Output is correct
29 Correct 135 ms 11680 KB Output is correct
30 Correct 124 ms 10212 KB Output is correct
31 Correct 119 ms 10856 KB Output is correct
32 Correct 228 ms 15812 KB Output is correct
33 Correct 105 ms 10432 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 856 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 113 ms 10188 KB Output is correct
42 Correct 119 ms 10724 KB Output is correct
43 Correct 228 ms 15636 KB Output is correct
44 Correct 115 ms 10432 KB Output is correct
45 Correct 82 ms 11720 KB Output is correct
46 Correct 99 ms 11692 KB Output is correct
47 Correct 70 ms 12244 KB Output is correct
48 Correct 65 ms 11984 KB Output is correct
49 Correct 64 ms 11988 KB Output is correct
50 Correct 65 ms 11976 KB Output is correct
51 Correct 556 ms 54304 KB Output is correct
52 Correct 533 ms 54464 KB Output is correct
53 Correct 442 ms 55172 KB Output is correct
54 Correct 438 ms 54964 KB Output is correct
55 Correct 422 ms 54880 KB Output is correct
56 Correct 78 ms 5180 KB Output is correct
57 Correct 71 ms 5204 KB Output is correct
58 Correct 102 ms 13136 KB Output is correct
59 Correct 105 ms 13128 KB Output is correct
60 Correct 87 ms 14924 KB Output is correct
61 Correct 115 ms 14932 KB Output is correct
62 Correct 72 ms 12628 KB Output is correct
63 Correct 98 ms 14652 KB Output is correct
64 Correct 112 ms 13136 KB Output is correct
65 Correct 101 ms 13136 KB Output is correct
66 Correct 110 ms 13392 KB Output is correct
67 Correct 88 ms 13908 KB Output is correct
68 Correct 97 ms 12884 KB Output is correct
69 Correct 98 ms 12368 KB Output is correct
70 Correct 92 ms 12884 KB Output is correct
71 Correct 93 ms 11720 KB Output is correct
72 Correct 83 ms 11844 KB Output is correct
73 Correct 69 ms 12040 KB Output is correct
74 Correct 80 ms 12008 KB Output is correct
75 Correct 68 ms 11988 KB Output is correct
76 Correct 76 ms 11976 KB Output is correct
77 Correct 860 ms 62420 KB Output is correct
78 Correct 824 ms 62524 KB Output is correct
79 Correct 749 ms 70392 KB Output is correct
80 Correct 804 ms 70580 KB Output is correct
81 Correct 695 ms 68576 KB Output is correct
82 Correct 778 ms 69588 KB Output is correct
83 Correct 847 ms 62524 KB Output is correct
84 Correct 811 ms 62524 KB Output is correct
85 Correct 833 ms 63828 KB Output is correct
86 Correct 732 ms 57648 KB Output is correct
87 Correct 640 ms 57452 KB Output is correct
88 Correct 824 ms 66388 KB Output is correct