Submission #1041560

#TimeUsernameProblemLanguageResultExecution timeMemory
1041560irmuunRailway Trip 2 (JOI22_ho_t4)C++17
16 / 100
2079 ms524288 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,k; cin>>n>>k; ll l[n+5],r[n+5]; iota(l+1,l+n+1,1); iota(r+1,r+n+1,1); ll m; cin>>m; while(m--){ ll a,b; cin>>a>>b; if(a<b){ for(ll i=a;i<=min(a+k-1,b-1);i++){ r[i]=max(r[i],b); } } else{ for(ll i=a;i>=max(a-k+1,b+1);i--){ l[i]=min(l[i],b); } } } vector<vector<ll>>ans(n+5,vector<ll>(n+5,-1)); for(ll i=1;i<=n;i++){ ll lc=i,rc=i,d=0; vector<ll>v; v.pb(i); while(!v.empty()){ ll x=lc,y=rc; for(ll j:v){ ans[i][j]=d; x=min(x,l[j]); y=max(y,r[j]); } d++; v.clear(); for(ll j=lc-1;j>=x;j--){ v.pb(j); } for(ll j=rc+1;j<=y;j++){ v.pb(j); } lc=x; rc=y; } } ll q; cin>>q; while(q--){ ll s,t; cin>>s>>t; cout<<ans[s][t]<<"\n"; } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...