# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
889705 |
2023-12-20T05:51:45 Z |
vjudge1 |
Tourism (JOI23_tourism) |
C++17 |
|
1505 ms |
13460 KB |
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=1e5+5;
int mn[N*4],mx[N*4],c[N],d[N];
vector <int> g[N];
void dfs(int v,int p){
for(auto to : g[v]){
if(to!=p){
dfs(to,v);
d[v]+=d[to];
}
}
}
void build(int v,int tl,int tr){
if(tl==tr){
mn[v]=c[tl];
mx[v]=c[tl];
}
else{
int tm=(tl+tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
mn[v]=min(mn[v*2],mn[v*2+1]);
mx[v]=max(mx[v*2],mx[v*2+1]);
}
}
int get_mn(int v,int tl,int tr,int l,int r){
if(r<tl or l>tr)return INT_MAX;
if(l<=tl && tr<=r)return mn[v];
int tm=(tl+tr)/2;
return min(get_mn(v*2,tl,tm,l,r),get_mn(v*2+1,tm+1,tr,l,r));
}
int get_mx(int v,int tl,int tr,int l,int r){
if(r<tl or l>tr)return INT_MIN;
if(l<=tl && tr<=r)return mx[v];
int tm=(tl+tr)/2;
return max(get_mx(v*2,tl,tm,l,r),get_mx(v*2+1,tm+1,tr,l,r));
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);
int n,m,qq;
cin>>n>>m>>qq;
int cnt=0;
for(int i=0;i<n-1;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
for(int i=1;i<=m;i++){
cin>>c[i];
}
if(n<=3000){
while(qq--){
int l,r;
cin>>l>>r;
for(int i=1;i<=n;i++){
d[i]=0;
}
for(int i=l;i<=r;i++){
d[c[i]]=1;
}
dfs(c[l],0);
int ans=0;
for(int i=1;i<=n;i++)if(d[i]!=0)ans++;
cout<<ans<<"\n";
}
}
else{
build(1,1,m);
while(qq--){
int l,r;
cin>>l>>r;
cout<<get_mx(1,1,m,l,r)-get_mn(1,1,m,l,r)+1<<"\n";
}
}
}
Compilation message
tourism.cpp: In function 'int main()':
tourism.cpp:49:9: warning: unused variable 'cnt' [-Wunused-variable]
49 | int cnt=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4744 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
2 ms |
4700 KB |
Output is correct |
17 |
Correct |
2 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
2 ms |
4700 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
2 ms |
4656 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
2 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4744 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
2 ms |
4700 KB |
Output is correct |
17 |
Correct |
2 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
2 ms |
4700 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
2 ms |
4656 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
2 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4696 KB |
Output is correct |
30 |
Correct |
15 ms |
4696 KB |
Output is correct |
31 |
Correct |
19 ms |
4700 KB |
Output is correct |
32 |
Correct |
29 ms |
4852 KB |
Output is correct |
33 |
Correct |
28 ms |
4700 KB |
Output is correct |
34 |
Correct |
28 ms |
4700 KB |
Output is correct |
35 |
Correct |
29 ms |
4696 KB |
Output is correct |
36 |
Correct |
30 ms |
4700 KB |
Output is correct |
37 |
Correct |
29 ms |
4700 KB |
Output is correct |
38 |
Correct |
39 ms |
4696 KB |
Output is correct |
39 |
Correct |
40 ms |
4944 KB |
Output is correct |
40 |
Correct |
40 ms |
4700 KB |
Output is correct |
41 |
Correct |
42 ms |
4696 KB |
Output is correct |
42 |
Correct |
42 ms |
4940 KB |
Output is correct |
43 |
Correct |
40 ms |
4696 KB |
Output is correct |
44 |
Correct |
40 ms |
4868 KB |
Output is correct |
45 |
Correct |
40 ms |
4700 KB |
Output is correct |
46 |
Correct |
40 ms |
4868 KB |
Output is correct |
47 |
Correct |
41 ms |
4844 KB |
Output is correct |
48 |
Correct |
41 ms |
4696 KB |
Output is correct |
49 |
Correct |
41 ms |
4700 KB |
Output is correct |
50 |
Correct |
19 ms |
4696 KB |
Output is correct |
51 |
Correct |
20 ms |
4700 KB |
Output is correct |
52 |
Correct |
20 ms |
4852 KB |
Output is correct |
53 |
Correct |
20 ms |
4696 KB |
Output is correct |
54 |
Correct |
21 ms |
4700 KB |
Output is correct |
55 |
Correct |
20 ms |
4700 KB |
Output is correct |
56 |
Correct |
3 ms |
4696 KB |
Output is correct |
57 |
Correct |
27 ms |
4828 KB |
Output is correct |
58 |
Correct |
27 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4696 KB |
Output is correct |
4 |
Correct |
118 ms |
11604 KB |
Output is correct |
5 |
Correct |
111 ms |
11600 KB |
Output is correct |
6 |
Correct |
110 ms |
12628 KB |
Output is correct |
7 |
Correct |
164 ms |
13244 KB |
Output is correct |
8 |
Correct |
164 ms |
13140 KB |
Output is correct |
9 |
Correct |
169 ms |
13028 KB |
Output is correct |
10 |
Correct |
173 ms |
13460 KB |
Output is correct |
11 |
Correct |
165 ms |
13140 KB |
Output is correct |
12 |
Correct |
154 ms |
13212 KB |
Output is correct |
13 |
Correct |
156 ms |
13136 KB |
Output is correct |
14 |
Correct |
149 ms |
13168 KB |
Output is correct |
15 |
Correct |
69 ms |
9952 KB |
Output is correct |
16 |
Correct |
135 ms |
12628 KB |
Output is correct |
17 |
Correct |
1505 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Incorrect |
37 ms |
10708 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4560 KB |
Output is correct |
4 |
Incorrect |
151 ms |
13224 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
2 ms |
4744 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
2 ms |
4700 KB |
Output is correct |
17 |
Correct |
2 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
2 ms |
4700 KB |
Output is correct |
20 |
Correct |
2 ms |
4700 KB |
Output is correct |
21 |
Correct |
2 ms |
4656 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
2 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4696 KB |
Output is correct |
30 |
Correct |
15 ms |
4696 KB |
Output is correct |
31 |
Correct |
19 ms |
4700 KB |
Output is correct |
32 |
Correct |
29 ms |
4852 KB |
Output is correct |
33 |
Correct |
28 ms |
4700 KB |
Output is correct |
34 |
Correct |
28 ms |
4700 KB |
Output is correct |
35 |
Correct |
29 ms |
4696 KB |
Output is correct |
36 |
Correct |
30 ms |
4700 KB |
Output is correct |
37 |
Correct |
29 ms |
4700 KB |
Output is correct |
38 |
Correct |
39 ms |
4696 KB |
Output is correct |
39 |
Correct |
40 ms |
4944 KB |
Output is correct |
40 |
Correct |
40 ms |
4700 KB |
Output is correct |
41 |
Correct |
42 ms |
4696 KB |
Output is correct |
42 |
Correct |
42 ms |
4940 KB |
Output is correct |
43 |
Correct |
40 ms |
4696 KB |
Output is correct |
44 |
Correct |
40 ms |
4868 KB |
Output is correct |
45 |
Correct |
40 ms |
4700 KB |
Output is correct |
46 |
Correct |
40 ms |
4868 KB |
Output is correct |
47 |
Correct |
41 ms |
4844 KB |
Output is correct |
48 |
Correct |
41 ms |
4696 KB |
Output is correct |
49 |
Correct |
41 ms |
4700 KB |
Output is correct |
50 |
Correct |
19 ms |
4696 KB |
Output is correct |
51 |
Correct |
20 ms |
4700 KB |
Output is correct |
52 |
Correct |
20 ms |
4852 KB |
Output is correct |
53 |
Correct |
20 ms |
4696 KB |
Output is correct |
54 |
Correct |
21 ms |
4700 KB |
Output is correct |
55 |
Correct |
20 ms |
4700 KB |
Output is correct |
56 |
Correct |
3 ms |
4696 KB |
Output is correct |
57 |
Correct |
27 ms |
4828 KB |
Output is correct |
58 |
Correct |
27 ms |
4700 KB |
Output is correct |
59 |
Correct |
1 ms |
4700 KB |
Output is correct |
60 |
Correct |
1 ms |
4700 KB |
Output is correct |
61 |
Correct |
2 ms |
4696 KB |
Output is correct |
62 |
Correct |
118 ms |
11604 KB |
Output is correct |
63 |
Correct |
111 ms |
11600 KB |
Output is correct |
64 |
Correct |
110 ms |
12628 KB |
Output is correct |
65 |
Correct |
164 ms |
13244 KB |
Output is correct |
66 |
Correct |
164 ms |
13140 KB |
Output is correct |
67 |
Correct |
169 ms |
13028 KB |
Output is correct |
68 |
Correct |
173 ms |
13460 KB |
Output is correct |
69 |
Correct |
165 ms |
13140 KB |
Output is correct |
70 |
Correct |
154 ms |
13212 KB |
Output is correct |
71 |
Correct |
156 ms |
13136 KB |
Output is correct |
72 |
Correct |
149 ms |
13168 KB |
Output is correct |
73 |
Correct |
69 ms |
9952 KB |
Output is correct |
74 |
Correct |
135 ms |
12628 KB |
Output is correct |
75 |
Correct |
1505 ms |
4944 KB |
Output is correct |
76 |
Correct |
1 ms |
4700 KB |
Output is correct |
77 |
Incorrect |
37 ms |
10708 KB |
Output isn't correct |
78 |
Halted |
0 ms |
0 KB |
- |