Submission #997526

#TimeUsernameProblemLanguageResultExecution timeMemory
997526AbitoPassport (JOI23_passport)C++17
6 / 100
70 ms16976 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt #define int long long #define ll long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=2e5+5; int dis[N],L[N],R[N],n,q; set<int> s; void bfs(){ for (int i=2;i<=n;i++) dis[i]=INT_MAX; queue<int> q;q.push(1);s.erase(1); while (!q.empty()){ int x=q.front();q.pop(); while (true){ auto it=s.lower_bound(L[x]); if (it==s.end()) break; if (*it>R[x]) break; int y=*it; s.erase(it); dis[y]=dis[x]+1; q.push(y); } }return; } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n; for (int i=1;i<=n;i++) cin>>L[i]>>R[i],s.ep(i); cin>>q; while (q--){ int x;cin>>x; bfs(); int mx=0; for (int i=1;i<=n;i++) mx=max(mx,dis[i]); if (mx>=INT_MAX) cout<<-1<<endl; else cout<<mx<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...