Submission #888698

# Submission time Handle Problem Language Result Execution time Memory
888698 2023-12-18T05:48:40 Z vjudge1 Passport (JOI23_passport) C++14
0 / 100
632 ms 1048576 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=2e5+5;
vector <int> g[N];
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);
    int n;
    cin>>n;
    vector <int> l(n),r(n);
    for(int i=0;i<n;i++)cin>>l[i]>>r[i];
    for(int i=0;i<n;i++){
        for(int j=l[i];j<=r[i];j++){
            g[i+1].pb(j);
        }
    }
    int q;cin>>q;
    set <pair <int,int> > st;
    while(q--){
        int x;cin>>x;
        vector <int> d(n+1,1e18),p(n+1);
        d[x]=0;
        st.insert({0,x});
        while(!st.empty()){
            int v=st.begin()->second;
            d[v]++;
            st.erase(st.begin());
            for(auto to : g[v]){
                if(d[to]>d[v]){
                    p[to]=v;
                    st.erase({d[to],to});
                    d[to]=d[v];
                    st.insert({d[to],to});
                }
            }
        }
        int mx=0;
        set <int> s;
        for(int i=1;i<=n;i++){
            mx=max(mx,d[i]);
            if(d[i]==1e18)break;
            int curv=i;
            while(curv!=x){
                curv=p[curv];
                s.insert(curv);
                //cout<<curv<<" ";
            }
            //cout<<endl;
        }
        if(mx==1e18)cout<<-1<<"\n";
        else cout<<s.size()<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Runtime error 632 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4960 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Incorrect 1 ms 4952 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4960 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Incorrect 1 ms 4952 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4960 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Incorrect 1 ms 4952 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Runtime error 632 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -