Submission #886046

# Submission time Handle Problem Language Result Execution time Memory
886046 2023-12-11T12:18:30 Z vjudge1 Curtains (NOI23_curtains) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9;

struct segtree{
    int n, tl, tr;
    vector<int> t, st, marked;
    int base = -1;

    segtree(vector<int>a){
        n = a.size();
        st.resize(4*n, -1);
        t.resize(4*n,-1);
        marked.resize(4*n);
    }

    void push(int v, int l, int r){
        if(l<r){
            if(st[v*2] < t[v]){
                st[v*2] = t[v];
                t[v*2] = t[v];
                marked[v*2] = 1;
            }
            if(st[v*2+1] < t[v]){
                st[v*2+1] = t[v];
                t[v*2+1] = t[v];
                marked[v*2+1] = 1;
            }   

            st[v] = merge(st[v*2], st[v*2+1]);
            
        }
        marked[v] = 0; t[v] = -1;
    }

    int merge(int x, int y){
        return min(x, y);
    }

    void update(int v, int l, int r, int val){
        push(v, l, r);
        if(l>tr || r< tl) return;
        else if(r<=tr&&l>=tl){
            if(st[v] < val){
                t[v] = val;
                st[v] = t[v];
                marked[v] = 1;
            }
        }
        else{
            int mid = (l+r) / 2;
            update(v*2, l, mid, val); update(v*2+1, mid+1, r, val);
            st[v] = merge(st[v*2], st[v*2+1]);
        }
    }

    void update(int l, int r, int val){
        if(r<l) return;
        tl = l; tr = r;
        update(1, 0, n-1, val);
    }

    int get(int v, int l, int r){
        push(v, l, r);
        if(l>tr || r<tl) return 1e9;
        else if(l>=tl&&r<=tr) return st[v];
        else{
            int mid = (l+r) / 2;
            return merge(get(v*2, l, mid), get(v*2+1, mid+1, r));
        }
    }

    int operator()(int l, int r){
        int tl = l, tr = r;

        if(r<l) return base;
        else return get(1, 0, n-1);
    }
};

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

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

    vector<vector<int>> g(n);
    vector<int> vis(n, 0), ma(n, -1), mi(n, INF);


    for(int i=0; i<m; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        g[y].push_back(x);
        ma[y] = max(ma[y], x);
        mi[x] = min(mi[x], y);
    }

    vector<array<int, 2>> s;
    vector<int> a(n, -1);



    segtree st(a);
    vector<array<int, 3>> qu(q);
    vector<int> ans(q);

    for(int i=0; i<q; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        qu[i]={x, y, i};
    }

    sort(qu.begin(), qu.end(), [&](array<int, 3> a, array<int, 3> b){
        return a[1] < b[1];
    });

    int l = 0;
    for(auto [left, right, ind]: qu){
        while(l<=right){
            for(auto j: g[l]) st.update(j+1, l-1, j);
            l++;
        }
        if(ma[right] < left || mi[left] > right) ans[ind]=0;
        else if(st(left+1, right-1) < left) ans[ind]=0;
        else ans[ind]=1; 
    }

    for(int i=0; i<q; i++){
        if(ans[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
}

Compilation message

curtains.cpp: In member function 'long long int segtree::operator()(long long int, long long int)':
curtains.cpp:75:13: warning: unused variable 'tl' [-Wunused-variable]
   75 |         int tl = l, tr = r;
      |             ^~
curtains.cpp:75:21: warning: unused variable 'tr' [-Wunused-variable]
   75 |         int tl = l, tr = r;
      |                     ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -