# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
932955 |
2024-02-24T16:09:20 Z |
owoovo |
Passport (JOI23_passport) |
C++14 |
|
798 ms |
235252 KB |
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
using namespace std;
const int maxn=1e17;
vector<pair<int,int>> graph[800010],hparg[800010];
int n,q,cnt,id[200010],on[800010],dis1[800010],dis2[800010];
void build(int l,int r,int now){
if(l==r){
id[l]=now;
return;
}
int m=(l+r)>>1;
graph[now].push_back({now*2,0});
graph[now].push_back({now*2+1,0});
build(l,m,now*2);
build(m+1,r,now*2+1);
return;
}
void pls(int l,int r,int tl,int tr,int nid,int uid){
if(tl==l&&r==tr){
graph[uid].push_back({nid,1});
return;
}
int m=(l+r)>>1;
if(tr<=m)pls(l,m,tl,tr,nid*2,uid);
else if(m+1<=tl)pls(m+1,r,tl,tr,nid*2+1,uid);
else{
pls(l,m,tl,m,nid*2,uid);
pls(m+1,r,m+1,tr,nid*2+1,uid);
}
return;
}
void distra(int s,int* dis,vector<pair<int,int>>* graph){
priority_queue< pair<int,int>,vector<pair<int,int>>, greater<pair<int,int>> > pq;
for(int i=0;i<=800000;i++)*(dis+i)=maxn;
(*(dis+s))=0;
pq.push({0ll,s});
while(!pq.empty()){
auto [d,v]=pq.top();
pq.pop();
if(d>(*(dis+v)))continue;
for(auto &[ne,w]:(*(graph+v))){
if((*(dis+ne))>w+d){
(*(dis+ne))=w+d;
pq.push({w+d,ne});
}
}
}
return;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
build(1,n,1);
for(int i=1;i<=n;i++){
int l,r;
cin>>l>>r;
pls(1,n,l,r,1,id[i]);
}
for(int i=1;i<=800000;i++){
for(auto &[v,w]:graph[i]){
hparg[v].push_back({i,w});
}
}
distra(id[1],dis1,hparg);
distra(id[n],dis2,hparg);
for(int i=1;i<=n;i++)hparg[0].push_back({id[i],max(0ll,dis1[id[i]]-1)+max(0ll,dis2[id[i]]-1)+1});
distra(0,dis1,hparg);
cin>>q;
for(int i=1;i<=q;i++){
int v;
cin>>v;
if(dis1[id[v]]<maxn)cout<<dis1[id[v]]<<"\n";
else cout<<"-1\n";
}
return 0;
}
Compilation message
passport.cpp: In function 'void distra(long long int, long long int*, std::vector<std::pair<long long int, long long int> >*)':
passport.cpp:41:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
41 | auto [d,v]=pq.top();
| ^
passport.cpp:44:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for(auto &[ne,w]:(*(graph+v))){
| ^
passport.cpp: In function 'int main()':
passport.cpp:64:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
64 | for(auto &[v,w]:graph[i]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
54108 KB |
Output is correct |
2 |
Correct |
14 ms |
54208 KB |
Output is correct |
3 |
Correct |
15 ms |
54108 KB |
Output is correct |
4 |
Correct |
787 ms |
206888 KB |
Output is correct |
5 |
Correct |
462 ms |
124604 KB |
Output is correct |
6 |
Correct |
263 ms |
103632 KB |
Output is correct |
7 |
Correct |
216 ms |
94936 KB |
Output is correct |
8 |
Correct |
180 ms |
124240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
54108 KB |
Output is correct |
2 |
Correct |
19 ms |
54108 KB |
Output is correct |
3 |
Correct |
17 ms |
54108 KB |
Output is correct |
4 |
Correct |
16 ms |
54200 KB |
Output is correct |
5 |
Correct |
15 ms |
54108 KB |
Output is correct |
6 |
Correct |
14 ms |
54104 KB |
Output is correct |
7 |
Correct |
16 ms |
54104 KB |
Output is correct |
8 |
Correct |
14 ms |
54108 KB |
Output is correct |
9 |
Correct |
15 ms |
54104 KB |
Output is correct |
10 |
Correct |
17 ms |
54080 KB |
Output is correct |
11 |
Correct |
16 ms |
54332 KB |
Output is correct |
12 |
Correct |
17 ms |
54364 KB |
Output is correct |
13 |
Correct |
15 ms |
54248 KB |
Output is correct |
14 |
Correct |
15 ms |
54220 KB |
Output is correct |
15 |
Correct |
15 ms |
54364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
54108 KB |
Output is correct |
2 |
Correct |
19 ms |
54108 KB |
Output is correct |
3 |
Correct |
17 ms |
54108 KB |
Output is correct |
4 |
Correct |
16 ms |
54200 KB |
Output is correct |
5 |
Correct |
15 ms |
54108 KB |
Output is correct |
6 |
Correct |
14 ms |
54104 KB |
Output is correct |
7 |
Correct |
16 ms |
54104 KB |
Output is correct |
8 |
Correct |
14 ms |
54108 KB |
Output is correct |
9 |
Correct |
15 ms |
54104 KB |
Output is correct |
10 |
Correct |
17 ms |
54080 KB |
Output is correct |
11 |
Correct |
16 ms |
54332 KB |
Output is correct |
12 |
Correct |
17 ms |
54364 KB |
Output is correct |
13 |
Correct |
15 ms |
54248 KB |
Output is correct |
14 |
Correct |
15 ms |
54220 KB |
Output is correct |
15 |
Correct |
15 ms |
54364 KB |
Output is correct |
16 |
Correct |
19 ms |
55388 KB |
Output is correct |
17 |
Correct |
20 ms |
55128 KB |
Output is correct |
18 |
Correct |
22 ms |
55900 KB |
Output is correct |
19 |
Correct |
20 ms |
55900 KB |
Output is correct |
20 |
Correct |
21 ms |
54876 KB |
Output is correct |
21 |
Correct |
18 ms |
55116 KB |
Output is correct |
22 |
Correct |
17 ms |
54620 KB |
Output is correct |
23 |
Correct |
18 ms |
55132 KB |
Output is correct |
24 |
Correct |
17 ms |
55436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
54108 KB |
Output is correct |
2 |
Correct |
19 ms |
54108 KB |
Output is correct |
3 |
Correct |
17 ms |
54108 KB |
Output is correct |
4 |
Correct |
16 ms |
54200 KB |
Output is correct |
5 |
Correct |
15 ms |
54108 KB |
Output is correct |
6 |
Correct |
14 ms |
54104 KB |
Output is correct |
7 |
Correct |
16 ms |
54104 KB |
Output is correct |
8 |
Correct |
14 ms |
54108 KB |
Output is correct |
9 |
Correct |
15 ms |
54104 KB |
Output is correct |
10 |
Correct |
17 ms |
54080 KB |
Output is correct |
11 |
Correct |
16 ms |
54332 KB |
Output is correct |
12 |
Correct |
17 ms |
54364 KB |
Output is correct |
13 |
Correct |
15 ms |
54248 KB |
Output is correct |
14 |
Correct |
15 ms |
54220 KB |
Output is correct |
15 |
Correct |
15 ms |
54364 KB |
Output is correct |
16 |
Correct |
19 ms |
55388 KB |
Output is correct |
17 |
Correct |
20 ms |
55128 KB |
Output is correct |
18 |
Correct |
22 ms |
55900 KB |
Output is correct |
19 |
Correct |
20 ms |
55900 KB |
Output is correct |
20 |
Correct |
21 ms |
54876 KB |
Output is correct |
21 |
Correct |
18 ms |
55116 KB |
Output is correct |
22 |
Correct |
17 ms |
54620 KB |
Output is correct |
23 |
Correct |
18 ms |
55132 KB |
Output is correct |
24 |
Correct |
17 ms |
55436 KB |
Output is correct |
25 |
Correct |
15 ms |
54076 KB |
Output is correct |
26 |
Correct |
14 ms |
54108 KB |
Output is correct |
27 |
Correct |
20 ms |
55384 KB |
Output is correct |
28 |
Correct |
18 ms |
55132 KB |
Output is correct |
29 |
Correct |
19 ms |
54876 KB |
Output is correct |
30 |
Correct |
17 ms |
55132 KB |
Output is correct |
31 |
Correct |
19 ms |
55080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
54108 KB |
Output is correct |
2 |
Correct |
14 ms |
54208 KB |
Output is correct |
3 |
Correct |
15 ms |
54108 KB |
Output is correct |
4 |
Correct |
787 ms |
206888 KB |
Output is correct |
5 |
Correct |
462 ms |
124604 KB |
Output is correct |
6 |
Correct |
263 ms |
103632 KB |
Output is correct |
7 |
Correct |
216 ms |
94936 KB |
Output is correct |
8 |
Correct |
180 ms |
124240 KB |
Output is correct |
9 |
Correct |
15 ms |
54108 KB |
Output is correct |
10 |
Correct |
19 ms |
54108 KB |
Output is correct |
11 |
Correct |
17 ms |
54108 KB |
Output is correct |
12 |
Correct |
16 ms |
54200 KB |
Output is correct |
13 |
Correct |
15 ms |
54108 KB |
Output is correct |
14 |
Correct |
14 ms |
54104 KB |
Output is correct |
15 |
Correct |
16 ms |
54104 KB |
Output is correct |
16 |
Correct |
14 ms |
54108 KB |
Output is correct |
17 |
Correct |
15 ms |
54104 KB |
Output is correct |
18 |
Correct |
17 ms |
54080 KB |
Output is correct |
19 |
Correct |
16 ms |
54332 KB |
Output is correct |
20 |
Correct |
17 ms |
54364 KB |
Output is correct |
21 |
Correct |
15 ms |
54248 KB |
Output is correct |
22 |
Correct |
15 ms |
54220 KB |
Output is correct |
23 |
Correct |
15 ms |
54364 KB |
Output is correct |
24 |
Correct |
19 ms |
55388 KB |
Output is correct |
25 |
Correct |
20 ms |
55128 KB |
Output is correct |
26 |
Correct |
22 ms |
55900 KB |
Output is correct |
27 |
Correct |
20 ms |
55900 KB |
Output is correct |
28 |
Correct |
21 ms |
54876 KB |
Output is correct |
29 |
Correct |
18 ms |
55116 KB |
Output is correct |
30 |
Correct |
17 ms |
54620 KB |
Output is correct |
31 |
Correct |
18 ms |
55132 KB |
Output is correct |
32 |
Correct |
17 ms |
55436 KB |
Output is correct |
33 |
Correct |
15 ms |
54076 KB |
Output is correct |
34 |
Correct |
14 ms |
54108 KB |
Output is correct |
35 |
Correct |
20 ms |
55384 KB |
Output is correct |
36 |
Correct |
18 ms |
55132 KB |
Output is correct |
37 |
Correct |
19 ms |
54876 KB |
Output is correct |
38 |
Correct |
17 ms |
55132 KB |
Output is correct |
39 |
Correct |
19 ms |
55080 KB |
Output is correct |
40 |
Correct |
798 ms |
215376 KB |
Output is correct |
41 |
Correct |
367 ms |
127676 KB |
Output is correct |
42 |
Correct |
553 ms |
235252 KB |
Output is correct |
43 |
Correct |
561 ms |
233332 KB |
Output is correct |
44 |
Correct |
212 ms |
107984 KB |
Output is correct |
45 |
Correct |
281 ms |
131788 KB |
Output is correct |
46 |
Correct |
155 ms |
82424 KB |
Output is correct |
47 |
Correct |
466 ms |
141852 KB |
Output is correct |
48 |
Correct |
356 ms |
170192 KB |
Output is correct |