Submission #1086277

#TimeUsernameProblemLanguageResultExecution timeMemory
1086277pemguimnPassport (JOI23_passport)C++14
6 / 100
505 ms120880 KiB
#include<bits/stdc++.h> #define ll long long #define ntr "\n" #define mod (ll)(1e9+7) #define taskname "temp" #define frep freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout); using namespace std; vector<pair<ll,ll>> adj[800100]; ll id[200010]; void build(ll pos,ll l,ll r){ if(l==r){ id[l]=pos; } else{ ll mid=(l+r)/2; build(2*pos,l,mid); build(2*pos+1,mid+1,r); adj[2*pos].push_back({pos,0}); adj[2*pos+1].push_back({pos,0}); } } void add(ll pos,ll l,ll r,ll u,ll v,ll x){ if(v<l||u>r) return ; else if(u<=l&&r<=v){ adj[pos].push_back({id[x],1}); } else{ ll mid=(l+r)/2; add(2*pos,l,mid,u,v,x); add(2*pos+1,mid+1,r,u,v,x); } } ll n,q; ll ans[800010]; ll dist[800010]; ll vis[800010]; ll a[200010]; ll b[200010]; ll l[200001]; ll r[200001]; void proc(ll st){ memset(dist,0x3f,sizeof(dist)); memset(vis,0,sizeof(vis)); deque<ll> dq; dq.push_front(id[st]); dist[id[st]]=0; while(!dq.empty()){ ll u=dq.front(); dq.pop_front(); if(vis[u]) continue; for(auto [v,w]:adj[u]){ if(dist[v]>dist[u]+w){ dist[v]=dist[u]+w; if(w==0){ dq.push_front(v); } else{ dq.push_back(v); } } } } dist[id[st]]=1; for(int i=1;i<=n;i++){ if(st==1) a[i]=dist[id[i]]; if(st==n) b[i]=dist[id[i]]; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //frep; cin>>n; build(1,1,n+1); for(int i=1;i<=n;i++){ cin>>l[i]>>r[i]; add(1,1,n+1,l[i],r[i],i); } proc(1); proc(n); // for(int i=1;i<=n;i++){ // cout<<a[i]<<' '; // } // cout<<ntr; // for(int i=1;i<=n;i++){ // cout<<b[i]<<' '; // } // cout<<ntr; // for(int i=1;i<=n+1;i++){ // cout<<id[i]<<' '; // } // cout<<ntr; for(int i=1;i<=n;i++){ adj[id[n+1]].push_back({id[i],max(1LL,a[i]+b[i]-1)}); //cout<<n+1<<' '<<i<<' '<<a[i]+b[i]<<ntr; } // cout<<ntr; // for(auto [v,w]:adj[id[n+1]]){ // cout<<id[n+1]<<' '<<v<<' '<<w<<ntr; // } priority_queue<pair<ll,ll>> pq; pq.push({0,id[n+1]}); memset(dist,0x3f,sizeof(dist)); memset(vis,0,sizeof(vis)); dist[id[n+1]]=0; while(!pq.empty()){ ll u=pq.top().second; pq.pop(); if(vis[u]) continue; vis[u]=1; for(auto [v,w]:adj[u]){ if(dist[v]>dist[u]+w){ dist[v]=dist[u]+w; pq.push({-dist[v],v}); } } } for(int i=1;i<=n;i++){ ans[i]=a[i] + b[i] - 1; } cin>>q; for(int i=1;i<=q;i++){ ll x; cin>>x; cout<<(ans[x]<1e18 ? ans[x] : -1)<<ntr; } }

Compilation message (stderr)

passport.cpp: In function 'void proc(long long int)':
passport.cpp:51:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         for(auto [v,w]:adj[u]){
      |                  ^
passport.cpp: In function 'int main()':
passport.cpp:110:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  110 |         for(auto [v,w]:adj[u]){
      |                  ^
#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...