Submission #968160

# Submission time Handle Problem Language Result Execution time Memory
968160 2024-04-23T08:07:55 Z TB_ Curtains (NOI23_curtains) C++17
100 / 100
897 ms 89004 KB
#include <bits/stdc++.h>
using namespace std;

// #undef _GLIBCXX_DEBUG                // disable run-time bound checking, etc
// #pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens
// #pragma GCC optimize ("unroll-loops")

// #pragma GCC target("bmi,bmi2,lzcnt,popcnt")                      // bit manipulation
// #pragma GCC target("movbe")                                      // byte swap
// #pragma GCC target("aes,pclmul,rdrnd")                           // encryption
// #pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD

// #include <bits/extc++.h>
// using namespace __gnu_pbds;
// template<class T>using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// template<class T>using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define INF ((ll)(1e9+7))
#define fo(i, n) for(ll i=0;i<((ll)n);i++)
#define deb(x) cout << #x << " = " << (x) << endl;
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LSOne(S) ((S) & (-S))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
inline int readint(){ int v = 0; char c; while((c = getchar()) != EOF && c != ' ' && c != '\n'){ v *= 10; v += c - '0'; } return v; }
inline int readintsigned() { int v = 0; int sign = 1; char c = getchar(); if (c == '-') { sign = -1; } else { v += c - '0'; } while ((c = getchar()) != EOF && c != ' ' && c != '\n') { v *= 10; v += c - '0'; } return v * sign; }
inline string readstring() { string s; char c; while ((c = getchar()) != EOF && c != '\n' && c != ' ') { s.push_back(c); } return s; }
template <class result_t=std::chrono::milliseconds,class clock_t=std::chrono::steady_clock,class duration_t = std::chrono::milliseconds>
auto since(std::chrono::time_point<clock_t, duration_t> const& start){return std::chrono::duration_cast<result_t>(clock_t::now() - start);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vpii> vvpii;
typedef vector<vpl> vvpl;

struct Node{
    int l, r, val = INF;
    Node *lnode, *rnode;
    Node(int l, int r): l(l), r(r) {
        if(r-l > 1){
            int mid = (r+l) / 2;
            lnode = new Node(l, mid);
            rnode = new Node(mid, r);
        }
    }

    void update(int lo, int hi, int x){
        if(r <= lo || hi <= l) return;
        if(r <= hi && lo <= l){
            val = min(val, x);
            return;
        } 
        lnode->update(lo, hi, x);
        rnode->update(lo, hi, x);
        val = min(val, max(lnode->val, rnode->val));
    }

    int query(int lo, int hi){
        if(r <= lo || hi <= l) return -1;
        if(r <= hi && lo <= l) return val;
        return max(lnode->query(lo, hi), rnode->query(lo, hi));
    }
};

int main() {
    // cout << fixed << setprecision(20);
    // auto start = std::chrono::steady_clock::now(); // since(start).count()
    cin.tie(0)->sync_with_stdio(0);

    int n, m, q;
    cin >> n >> m >> q;

    Node st(0, n+3);
    int a, b;
    vpl sections;
    fo(i, m){
        cin >> a >> b;
        sections.pb({a, b});
    }
    sort(rall(sections));
    vector<tuple<ll, ll, ll>> que;
    fo(i, q){
        cin >> a >> b;
        que.pb({a, b, i});
    }
    sort(all(que));
    // fo(i, q) deb2(get<0>(que[i]), get<1>(que[i]));

    vl ans(q, 0);
    fo(i, m){
        tie(a, b) = sections[i];
        st.update(a, b+1, b);

        if(i == m-1 || sections[i+1].F != a){
            while(que.size() && get<0>(que[que.size()-1])>a) que.pop_back();
            while(que.size() && get<0>(que[que.size()-1])==a){
                ans[get<2>(que[que.size()-1])] = (st.query(get<0>(que[que.size()-1]), get<1>(que[que.size()-1])+1)<=get<1>(que[que.size()-1]));
                que.pop_back();
            }
        }
    }
    fo(i, q) cout << (ans[i]?"YES":"NO") << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 147 ms 22224 KB Output is correct
23 Correct 186 ms 22740 KB Output is correct
24 Correct 199 ms 24868 KB Output is correct
25 Correct 331 ms 37596 KB Output is correct
26 Correct 183 ms 22672 KB Output is correct
27 Correct 340 ms 37564 KB Output is correct
28 Correct 327 ms 37288 KB Output is correct
29 Correct 165 ms 22184 KB Output is correct
30 Correct 189 ms 21384 KB Output is correct
31 Correct 169 ms 23076 KB Output is correct
32 Correct 324 ms 36780 KB Output is correct
33 Correct 152 ms 21548 KB Output is correct
# Verdict Execution time Memory 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 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 149 ms 21736 KB Output is correct
9 Correct 163 ms 22448 KB Output is correct
10 Correct 325 ms 35656 KB Output is correct
11 Correct 151 ms 21516 KB Output is correct
12 Correct 96 ms 18744 KB Output is correct
13 Correct 97 ms 18632 KB Output is correct
14 Correct 73 ms 19184 KB Output is correct
15 Correct 75 ms 19284 KB Output is correct
16 Correct 66 ms 17864 KB Output is correct
17 Correct 75 ms 19140 KB Output is correct
18 Correct 665 ms 86384 KB Output is correct
19 Correct 629 ms 85668 KB Output is correct
20 Correct 413 ms 85380 KB Output is correct
21 Correct 373 ms 85416 KB Output is correct
22 Correct 428 ms 86436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 82 ms 10708 KB Output is correct
23 Correct 83 ms 9904 KB Output is correct
24 Correct 105 ms 19396 KB Output is correct
25 Correct 115 ms 19136 KB Output is correct
26 Correct 95 ms 18188 KB Output is correct
27 Correct 92 ms 18120 KB Output is correct
28 Correct 62 ms 15816 KB Output is correct
29 Correct 91 ms 17860 KB Output is correct
30 Correct 106 ms 18120 KB Output is correct
31 Correct 112 ms 19400 KB Output is correct
32 Correct 97 ms 17948 KB Output is correct
33 Correct 90 ms 18120 KB Output is correct
34 Correct 105 ms 18628 KB Output is correct
35 Correct 132 ms 18064 KB Output is correct
36 Correct 124 ms 19272 KB Output is correct
37 Correct 145 ms 19140 KB Output is correct
38 Correct 128 ms 17856 KB Output is correct
39 Correct 69 ms 18884 KB Output is correct
40 Correct 108 ms 17844 KB Output is correct
41 Correct 74 ms 17816 KB Output is correct
42 Correct 91 ms 17860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
11 Correct 0 ms 484 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 147 ms 22224 KB Output is correct
23 Correct 186 ms 22740 KB Output is correct
24 Correct 199 ms 24868 KB Output is correct
25 Correct 331 ms 37596 KB Output is correct
26 Correct 183 ms 22672 KB Output is correct
27 Correct 340 ms 37564 KB Output is correct
28 Correct 327 ms 37288 KB Output is correct
29 Correct 165 ms 22184 KB Output is correct
30 Correct 189 ms 21384 KB Output is correct
31 Correct 169 ms 23076 KB Output is correct
32 Correct 324 ms 36780 KB Output is correct
33 Correct 152 ms 21548 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 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 149 ms 21736 KB Output is correct
42 Correct 163 ms 22448 KB Output is correct
43 Correct 325 ms 35656 KB Output is correct
44 Correct 151 ms 21516 KB Output is correct
45 Correct 96 ms 18744 KB Output is correct
46 Correct 97 ms 18632 KB Output is correct
47 Correct 73 ms 19184 KB Output is correct
48 Correct 75 ms 19284 KB Output is correct
49 Correct 66 ms 17864 KB Output is correct
50 Correct 75 ms 19140 KB Output is correct
51 Correct 665 ms 86384 KB Output is correct
52 Correct 629 ms 85668 KB Output is correct
53 Correct 413 ms 85380 KB Output is correct
54 Correct 373 ms 85416 KB Output is correct
55 Correct 428 ms 86436 KB Output is correct
56 Correct 82 ms 10708 KB Output is correct
57 Correct 83 ms 9904 KB Output is correct
58 Correct 105 ms 19396 KB Output is correct
59 Correct 115 ms 19136 KB Output is correct
60 Correct 95 ms 18188 KB Output is correct
61 Correct 92 ms 18120 KB Output is correct
62 Correct 62 ms 15816 KB Output is correct
63 Correct 91 ms 17860 KB Output is correct
64 Correct 106 ms 18120 KB Output is correct
65 Correct 112 ms 19400 KB Output is correct
66 Correct 97 ms 17948 KB Output is correct
67 Correct 90 ms 18120 KB Output is correct
68 Correct 105 ms 18628 KB Output is correct
69 Correct 132 ms 18064 KB Output is correct
70 Correct 124 ms 19272 KB Output is correct
71 Correct 145 ms 19140 KB Output is correct
72 Correct 128 ms 17856 KB Output is correct
73 Correct 69 ms 18884 KB Output is correct
74 Correct 108 ms 17844 KB Output is correct
75 Correct 74 ms 17816 KB Output is correct
76 Correct 91 ms 17860 KB Output is correct
77 Correct 897 ms 88832 KB Output is correct
78 Correct 862 ms 87956 KB Output is correct
79 Correct 631 ms 89004 KB Output is correct
80 Correct 621 ms 88296 KB Output is correct
81 Correct 595 ms 87624 KB Output is correct
82 Correct 594 ms 87520 KB Output is correct
83 Correct 831 ms 87952 KB Output is correct
84 Correct 877 ms 88040 KB Output is correct
85 Correct 721 ms 88752 KB Output is correct
86 Correct 739 ms 87656 KB Output is correct
87 Correct 773 ms 86980 KB Output is correct
88 Correct 638 ms 87656 KB Output is correct