Submission #1024075

# Submission time Handle Problem Language Result Execution time Memory
1024075 2024-07-15T11:14:41 Z vjudge1 Osumnjičeni (COCI21_osumnjiceni) C++17
0 / 110
56 ms 19796 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second

const int N = 2e5 + 10, LG = 18; 
int n, q, par[N][LG];
pair<int, int> a[N];

set<pair<int, int>> st;
bool check(int i){
    if (st.find({a[i].first, a[i].second}) != st.end())
        return 0;

    bool good = 1;

    st.insert({a[i].first, a[i].second});
    auto p = st.find({a[i].first, a[i].second});

    p++;
    if (p != st.end()){
        auto P = *p;
        if (P.F > a[i].second)
            good = 1;
        else
            good = 0;
    }
    p--;
    if (p != st.begin()){
        p--;
        auto P = *p;
        if (P.S < a[i].first)
            good = 1;
        else
            good = 0;
    }

    if (!good)
        st.erase({a[i].first, a[i].second});
    return good;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> a[i].first >> a[i].second;

    par[n + 1][0] = n + 1;
    int r = 1;
    for (int i = 1; i <= n; i ++){
        while (r <= n and check(r))
            r++;
        par[i][0] = r;
        st.erase({a[i].first, a[i].second});
    }

    for (int jump = 1; jump < LG; jump ++)
        for (int i = 1; i <= n + 1; i ++)
            par[i][jump] = par[par[i][jump - 1]][jump - 1];

    cin >> q;
    while (q--){
        int u, v;
        cin >> u >> v;

        int ans = 0;
        for (int j = LG - 1; j >= 0; j --){
            if ((par[u][j]) <= v){
                u = par[u][j];
                ans += (1 << j);
            }
        }

        cout << ans + 1 << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 19056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 19796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 19056 KB Output isn't correct
2 Halted 0 ms 0 KB -