Submission #915961

# Submission time Handle Problem Language Result Execution time Memory
915961 2024-01-25T03:15:23 Z imarn Passport (JOI23_passport) C++14
100 / 100
955 ms 104780 KB
#include<bits/stdc++.h>
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define pb push_back
#define f first
#define s second
#define vi vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define ll long long
#define sz(x) (int)x.size()
using namespace std;
const int N=2e5+5;
vector<pii>g[6*N];
int n;
void build(int i,int l,int r){
    if(l==r)return void(g[l].pb({i+n,0}));
    int m=(l+r)>>1;build(2*i,l,m);build(2*i+1,m+1,r);
    g[2*i+n].pb({i+n,0});g[2*i+1+n].pb({i+n,0});
}
void upd(int i,int l,int r,int tl,int tr,int id){
    if(r<tl||l>tr)return;
    if(r<=tr&&l>=tl){
        g[i+n].pb({id,1});return;
    }int m=(l+r)>>1;
    upd(2*i,l,m,tl,tr,id);upd(2*i+1,m+1,r,tl,tr,id);
}
int d[3][6*N];
bool vis[6*N]{0};
void distar(int st,int i){
    for(int v=0;v<6*N;v++)d[i][v]=1e9;
    d[i][st]=0;priority_queue<pii,vector<pii>,greater<pii>>pq;
    pq.push({0,st});
    while(!pq.empty()){
        auto u=pq.top();pq.pop();
        if(vis[u.s])continue;
        vis[u.s]=1;
        for(auto v:g[u.s]){
            if(d[i][v.f]>u.f+v.s)d[i][v.f]=u.f+v.s,pq.push({d[i][v.f],v.f});
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;build(1,1,n);
    for(int i=1;i<=n;i++){
        int l,r;cin>>l>>r;upd(1,1,n,l,r,i);
    }distar(1,0);memset(vis,0,sizeof vis);distar(n,1);memset(vis,0,sizeof vis);
    for(int i=0;i<6*N;i++)d[2][i]=1e9;priority_queue<pii,vector<pii>,greater<pii>>pq;
    for(int i=1;i<=n;i++)d[2][i]=d[0][i]+d[1][i]-(i>1&&i<n),pq.push({d[2][i],i});
    while(!pq.empty()){
        auto u=pq.top();pq.pop();
        if(vis[u.s])continue;
        vis[u.s]=1;
        for(auto v:g[u.s]){
            if(d[2][v.f]>u.f+v.s)d[2][v.f]=u.f+v.s,pq.push({d[2][v.f],v.f});
        }
    }int q;cin>>q;
    while(q--){
        int x;cin>>x;cout<<(d[2][x]>=1e9?-1:d[2][x])<<'\n';
    }
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:51:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   51 |     for(int i=0;i<6*N;i++)d[2][i]=1e9;priority_queue<pii,vector<pii>,greater<pii>>pq;
      |     ^~~
passport.cpp:51:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   51 |     for(int i=0;i<6*N;i++)d[2][i]=1e9;priority_queue<pii,vector<pii>,greater<pii>>pq;
      |                                       ^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 43864 KB Output is correct
2 Correct 12 ms 43868 KB Output is correct
3 Correct 13 ms 43900 KB Output is correct
4 Correct 864 ms 95964 KB Output is correct
5 Correct 397 ms 74056 KB Output is correct
6 Correct 227 ms 68028 KB Output is correct
7 Correct 298 ms 67284 KB Output is correct
8 Correct 169 ms 73060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 43868 KB Output is correct
2 Correct 13 ms 44064 KB Output is correct
3 Correct 13 ms 43868 KB Output is correct
4 Correct 12 ms 43888 KB Output is correct
5 Correct 12 ms 43864 KB Output is correct
6 Correct 12 ms 43904 KB Output is correct
7 Correct 14 ms 43868 KB Output is correct
8 Correct 12 ms 43868 KB Output is correct
9 Correct 13 ms 43868 KB Output is correct
10 Correct 13 ms 43864 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 13 ms 44012 KB Output is correct
13 Correct 13 ms 43868 KB Output is correct
14 Correct 13 ms 43752 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 43868 KB Output is correct
2 Correct 13 ms 44064 KB Output is correct
3 Correct 13 ms 43868 KB Output is correct
4 Correct 12 ms 43888 KB Output is correct
5 Correct 12 ms 43864 KB Output is correct
6 Correct 12 ms 43904 KB Output is correct
7 Correct 14 ms 43868 KB Output is correct
8 Correct 12 ms 43868 KB Output is correct
9 Correct 13 ms 43868 KB Output is correct
10 Correct 13 ms 43864 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 13 ms 44012 KB Output is correct
13 Correct 13 ms 43868 KB Output is correct
14 Correct 13 ms 43752 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
16 Correct 17 ms 44380 KB Output is correct
17 Correct 15 ms 44316 KB Output is correct
18 Correct 17 ms 44488 KB Output is correct
19 Correct 16 ms 44544 KB Output is correct
20 Correct 15 ms 44124 KB Output is correct
21 Correct 15 ms 44124 KB Output is correct
22 Correct 14 ms 44124 KB Output is correct
23 Correct 16 ms 44120 KB Output is correct
24 Correct 17 ms 44380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 43868 KB Output is correct
2 Correct 13 ms 44064 KB Output is correct
3 Correct 13 ms 43868 KB Output is correct
4 Correct 12 ms 43888 KB Output is correct
5 Correct 12 ms 43864 KB Output is correct
6 Correct 12 ms 43904 KB Output is correct
7 Correct 14 ms 43868 KB Output is correct
8 Correct 12 ms 43868 KB Output is correct
9 Correct 13 ms 43868 KB Output is correct
10 Correct 13 ms 43864 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 13 ms 44012 KB Output is correct
13 Correct 13 ms 43868 KB Output is correct
14 Correct 13 ms 43752 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
16 Correct 17 ms 44380 KB Output is correct
17 Correct 15 ms 44316 KB Output is correct
18 Correct 17 ms 44488 KB Output is correct
19 Correct 16 ms 44544 KB Output is correct
20 Correct 15 ms 44124 KB Output is correct
21 Correct 15 ms 44124 KB Output is correct
22 Correct 14 ms 44124 KB Output is correct
23 Correct 16 ms 44120 KB Output is correct
24 Correct 17 ms 44380 KB Output is correct
25 Correct 12 ms 43864 KB Output is correct
26 Correct 12 ms 43868 KB Output is correct
27 Correct 17 ms 44392 KB Output is correct
28 Correct 16 ms 44124 KB Output is correct
29 Correct 14 ms 44124 KB Output is correct
30 Correct 15 ms 44252 KB Output is correct
31 Correct 15 ms 44124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 43864 KB Output is correct
2 Correct 12 ms 43868 KB Output is correct
3 Correct 13 ms 43900 KB Output is correct
4 Correct 864 ms 95964 KB Output is correct
5 Correct 397 ms 74056 KB Output is correct
6 Correct 227 ms 68028 KB Output is correct
7 Correct 298 ms 67284 KB Output is correct
8 Correct 169 ms 73060 KB Output is correct
9 Correct 13 ms 43868 KB Output is correct
10 Correct 13 ms 44064 KB Output is correct
11 Correct 13 ms 43868 KB Output is correct
12 Correct 12 ms 43888 KB Output is correct
13 Correct 12 ms 43864 KB Output is correct
14 Correct 12 ms 43904 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
16 Correct 12 ms 43868 KB Output is correct
17 Correct 13 ms 43868 KB Output is correct
18 Correct 13 ms 43864 KB Output is correct
19 Correct 13 ms 43868 KB Output is correct
20 Correct 13 ms 44012 KB Output is correct
21 Correct 13 ms 43868 KB Output is correct
22 Correct 13 ms 43752 KB Output is correct
23 Correct 14 ms 43868 KB Output is correct
24 Correct 17 ms 44380 KB Output is correct
25 Correct 15 ms 44316 KB Output is correct
26 Correct 17 ms 44488 KB Output is correct
27 Correct 16 ms 44544 KB Output is correct
28 Correct 15 ms 44124 KB Output is correct
29 Correct 15 ms 44124 KB Output is correct
30 Correct 14 ms 44124 KB Output is correct
31 Correct 16 ms 44120 KB Output is correct
32 Correct 17 ms 44380 KB Output is correct
33 Correct 12 ms 43864 KB Output is correct
34 Correct 12 ms 43868 KB Output is correct
35 Correct 17 ms 44392 KB Output is correct
36 Correct 16 ms 44124 KB Output is correct
37 Correct 14 ms 44124 KB Output is correct
38 Correct 15 ms 44252 KB Output is correct
39 Correct 15 ms 44124 KB Output is correct
40 Correct 955 ms 102276 KB Output is correct
41 Correct 410 ms 78624 KB Output is correct
42 Correct 514 ms 104780 KB Output is correct
43 Correct 510 ms 104552 KB Output is correct
44 Correct 253 ms 72588 KB Output is correct
45 Correct 293 ms 79956 KB Output is correct
46 Correct 185 ms 56280 KB Output is correct
47 Correct 570 ms 80388 KB Output is correct
48 Correct 381 ms 87932 KB Output is correct