# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
793711 | 2023-07-26T05:48:01 Z | vjudge1 | Tourism (JOI23_tourism) | C++17 | 94 ms | 42084 KB |
// Author : حسن #include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 3e5 + 9 , mod = 1e9 + 7; ll c[N] = {} , d[N] = {} , a[N] = {}, b[N] = {} , us[N] , us1[N] , st[20][N][2] , dp[N] = {}; vector<int>v[N]; void dfs(int n,int p = 0){ d[n] = d[p] + 1; for(auto to : v[n]) if(to != p) dfs(to , n); } ll ans; void dfs1(int n,int p = 0){ for(auto to : v[n]) if(to != p) dfs1(to , n); ll s = 0; for(auto to : v[n]) if(b[to] != 0) if(to != p) s++, b[n] = b[to]; if(s != 0){ if(s == 1 && us[n] == 0){ }else { ans++; for(auto to : v[n]) if(to != p && b[to] != 0){ ans += d[b[to]] - d[n] - 1; } b[n] = n; } }else if(us[n] == 1){ ans++; b[n] = n; } } pair<ll,ll> get(int x , int y){ ll i = dp[y - x + 1]; ll minimum = min(st[i][x][1], st[i][y - (1 << i) + 1][1]); ll maximum = max(st[i][x][0], st[i][y - (1 << i) + 1][0]); //cout<<i<<" "<<minimum<<" "<<maximum<<" "; return {maximum , minimum}; } void get1(){ ll x ,y , i; x = 0; y = 1; dp[0] = 0; for(i = 1; i <= 2e5; i++){ if(2 * y <= i) x++, y *= 2; dp[i] = x; } } void solve(){ ll q , i , j , m , n , z , s = 0, f, l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n>>m>>q; for(i = 1; i < n; i++){ cin>>l>>r; v[l].pb(r); v[r].pb(l); if(!(l == i && r == i + 1)) s++; } for(i = 1; i <= m; i++) cin>>a[i]; dfs(1); get1(); for(i = 1; i <= m; i++) st[0][i][0] = st[0][i][1] = d[a[i]]; for (int i = 1; i < 18; i++) for (int j = 1; j + (1 << i) <= (m + 2); j++){ st[i][j][0] = max(st[i - 1][j][0], st[i - 1][j + (1 << (i - 1))][0]); st[i][j][1] = min(st[i - 1][j][1], st[i - 1][j + (1 << (i - 1))][1]); } if(s && n <= 2000 && m <= 2000 && q <= 2000){ while(q--){ cin>>l>>r; for(i = 1; i <= n; i++){ us[i] = b[i] = c[i] = 0; } for(i = l; i <= r; i++) us[a[i]] = 1; ans = 0; dfs1(1); cout<<ans<<"\n"; } }else if(s == 0){ while(q--){ cin>>l>>r; cout<<get(l , r).fi - get(l , r).se + 1<<"\n"; } } } int main(){ TL; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8916 KB | Output is correct |
2 | Correct | 4 ms | 8916 KB | Output is correct |
3 | Correct | 4 ms | 8916 KB | Output is correct |
4 | Correct | 5 ms | 9056 KB | Output is correct |
5 | Correct | 5 ms | 8984 KB | Output is correct |
6 | Correct | 5 ms | 9044 KB | Output is correct |
7 | Correct | 5 ms | 9040 KB | Output is correct |
8 | Correct | 5 ms | 9064 KB | Output is correct |
9 | Correct | 5 ms | 9044 KB | Output is correct |
10 | Correct | 5 ms | 9092 KB | Output is correct |
11 | Correct | 5 ms | 9044 KB | Output is correct |
12 | Correct | 5 ms | 9032 KB | Output is correct |
13 | Correct | 5 ms | 9044 KB | Output is correct |
14 | Correct | 6 ms | 9044 KB | Output is correct |
15 | Correct | 5 ms | 9044 KB | Output is correct |
16 | Correct | 5 ms | 9044 KB | Output is correct |
17 | Correct | 7 ms | 9044 KB | Output is correct |
18 | Correct | 6 ms | 9092 KB | Output is correct |
19 | Correct | 5 ms | 9044 KB | Output is correct |
20 | Correct | 5 ms | 9044 KB | Output is correct |
21 | Correct | 5 ms | 9044 KB | Output is correct |
22 | Correct | 6 ms | 9044 KB | Output is correct |
23 | Correct | 6 ms | 9044 KB | Output is correct |
24 | Correct | 6 ms | 9044 KB | Output is correct |
25 | Correct | 5 ms | 9044 KB | Output is correct |
26 | Correct | 5 ms | 9096 KB | Output is correct |
27 | Correct | 4 ms | 9044 KB | Output is correct |
28 | Correct | 6 ms | 9000 KB | Output is correct |
29 | Correct | 5 ms | 9044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8916 KB | Output is correct |
2 | Correct | 4 ms | 8916 KB | Output is correct |
3 | Correct | 4 ms | 8916 KB | Output is correct |
4 | Correct | 5 ms | 9056 KB | Output is correct |
5 | Correct | 5 ms | 8984 KB | Output is correct |
6 | Correct | 5 ms | 9044 KB | Output is correct |
7 | Correct | 5 ms | 9040 KB | Output is correct |
8 | Correct | 5 ms | 9064 KB | Output is correct |
9 | Correct | 5 ms | 9044 KB | Output is correct |
10 | Correct | 5 ms | 9092 KB | Output is correct |
11 | Correct | 5 ms | 9044 KB | Output is correct |
12 | Correct | 5 ms | 9032 KB | Output is correct |
13 | Correct | 5 ms | 9044 KB | Output is correct |
14 | Correct | 6 ms | 9044 KB | Output is correct |
15 | Correct | 5 ms | 9044 KB | Output is correct |
16 | Correct | 5 ms | 9044 KB | Output is correct |
17 | Correct | 7 ms | 9044 KB | Output is correct |
18 | Correct | 6 ms | 9092 KB | Output is correct |
19 | Correct | 5 ms | 9044 KB | Output is correct |
20 | Correct | 5 ms | 9044 KB | Output is correct |
21 | Correct | 5 ms | 9044 KB | Output is correct |
22 | Correct | 6 ms | 9044 KB | Output is correct |
23 | Correct | 6 ms | 9044 KB | Output is correct |
24 | Correct | 6 ms | 9044 KB | Output is correct |
25 | Correct | 5 ms | 9044 KB | Output is correct |
26 | Correct | 5 ms | 9096 KB | Output is correct |
27 | Correct | 4 ms | 9044 KB | Output is correct |
28 | Correct | 6 ms | 9000 KB | Output is correct |
29 | Correct | 5 ms | 9044 KB | Output is correct |
30 | Correct | 52 ms | 9376 KB | Output is correct |
31 | Correct | 54 ms | 9300 KB | Output is correct |
32 | Correct | 87 ms | 9520 KB | Output is correct |
33 | Correct | 85 ms | 9520 KB | Output is correct |
34 | Correct | 94 ms | 9520 KB | Output is correct |
35 | Correct | 55 ms | 9516 KB | Output is correct |
36 | Correct | 56 ms | 9516 KB | Output is correct |
37 | Correct | 55 ms | 9428 KB | Output is correct |
38 | Correct | 63 ms | 9600 KB | Output is correct |
39 | Correct | 62 ms | 9592 KB | Output is correct |
40 | Correct | 68 ms | 9616 KB | Output is correct |
41 | Correct | 74 ms | 9628 KB | Output is correct |
42 | Correct | 73 ms | 9632 KB | Output is correct |
43 | Correct | 65 ms | 9572 KB | Output is correct |
44 | Correct | 61 ms | 9560 KB | Output is correct |
45 | Correct | 61 ms | 9428 KB | Output is correct |
46 | Correct | 63 ms | 9568 KB | Output is correct |
47 | Correct | 63 ms | 9556 KB | Output is correct |
48 | Correct | 62 ms | 9532 KB | Output is correct |
49 | Correct | 61 ms | 9556 KB | Output is correct |
50 | Correct | 63 ms | 9528 KB | Output is correct |
51 | Correct | 64 ms | 9528 KB | Output is correct |
52 | Correct | 62 ms | 9512 KB | Output is correct |
53 | Correct | 64 ms | 9512 KB | Output is correct |
54 | Correct | 62 ms | 9492 KB | Output is correct |
55 | Correct | 62 ms | 9528 KB | Output is correct |
56 | Correct | 5 ms | 9300 KB | Output is correct |
57 | Correct | 45 ms | 9044 KB | Output is correct |
58 | Correct | 43 ms | 9500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8916 KB | Output is correct |
2 | Correct | 4 ms | 9044 KB | Output is correct |
3 | Correct | 5 ms | 9300 KB | Output is correct |
4 | Correct | 45 ms | 35544 KB | Output is correct |
5 | Correct | 43 ms | 28616 KB | Output is correct |
6 | Correct | 52 ms | 36184 KB | Output is correct |
7 | Correct | 65 ms | 41936 KB | Output is correct |
8 | Correct | 61 ms | 42052 KB | Output is correct |
9 | Correct | 63 ms | 41992 KB | Output is correct |
10 | Correct | 61 ms | 42084 KB | Output is correct |
11 | Correct | 64 ms | 42020 KB | Output is correct |
12 | Correct | 62 ms | 42016 KB | Output is correct |
13 | Correct | 56 ms | 41936 KB | Output is correct |
14 | Correct | 57 ms | 41972 KB | Output is correct |
15 | Correct | 37 ms | 16076 KB | Output is correct |
16 | Correct | 76 ms | 41572 KB | Output is correct |
17 | Correct | 42 ms | 34580 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8916 KB | Output is correct |
2 | Incorrect | 38 ms | 24336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8916 KB | Output is correct |
2 | Correct | 5 ms | 9044 KB | Output is correct |
3 | Correct | 5 ms | 9296 KB | Output is correct |
4 | Incorrect | 32 ms | 33740 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8916 KB | Output is correct |
2 | Correct | 4 ms | 8916 KB | Output is correct |
3 | Correct | 4 ms | 8916 KB | Output is correct |
4 | Correct | 5 ms | 9056 KB | Output is correct |
5 | Correct | 5 ms | 8984 KB | Output is correct |
6 | Correct | 5 ms | 9044 KB | Output is correct |
7 | Correct | 5 ms | 9040 KB | Output is correct |
8 | Correct | 5 ms | 9064 KB | Output is correct |
9 | Correct | 5 ms | 9044 KB | Output is correct |
10 | Correct | 5 ms | 9092 KB | Output is correct |
11 | Correct | 5 ms | 9044 KB | Output is correct |
12 | Correct | 5 ms | 9032 KB | Output is correct |
13 | Correct | 5 ms | 9044 KB | Output is correct |
14 | Correct | 6 ms | 9044 KB | Output is correct |
15 | Correct | 5 ms | 9044 KB | Output is correct |
16 | Correct | 5 ms | 9044 KB | Output is correct |
17 | Correct | 7 ms | 9044 KB | Output is correct |
18 | Correct | 6 ms | 9092 KB | Output is correct |
19 | Correct | 5 ms | 9044 KB | Output is correct |
20 | Correct | 5 ms | 9044 KB | Output is correct |
21 | Correct | 5 ms | 9044 KB | Output is correct |
22 | Correct | 6 ms | 9044 KB | Output is correct |
23 | Correct | 6 ms | 9044 KB | Output is correct |
24 | Correct | 6 ms | 9044 KB | Output is correct |
25 | Correct | 5 ms | 9044 KB | Output is correct |
26 | Correct | 5 ms | 9096 KB | Output is correct |
27 | Correct | 4 ms | 9044 KB | Output is correct |
28 | Correct | 6 ms | 9000 KB | Output is correct |
29 | Correct | 5 ms | 9044 KB | Output is correct |
30 | Correct | 52 ms | 9376 KB | Output is correct |
31 | Correct | 54 ms | 9300 KB | Output is correct |
32 | Correct | 87 ms | 9520 KB | Output is correct |
33 | Correct | 85 ms | 9520 KB | Output is correct |
34 | Correct | 94 ms | 9520 KB | Output is correct |
35 | Correct | 55 ms | 9516 KB | Output is correct |
36 | Correct | 56 ms | 9516 KB | Output is correct |
37 | Correct | 55 ms | 9428 KB | Output is correct |
38 | Correct | 63 ms | 9600 KB | Output is correct |
39 | Correct | 62 ms | 9592 KB | Output is correct |
40 | Correct | 68 ms | 9616 KB | Output is correct |
41 | Correct | 74 ms | 9628 KB | Output is correct |
42 | Correct | 73 ms | 9632 KB | Output is correct |
43 | Correct | 65 ms | 9572 KB | Output is correct |
44 | Correct | 61 ms | 9560 KB | Output is correct |
45 | Correct | 61 ms | 9428 KB | Output is correct |
46 | Correct | 63 ms | 9568 KB | Output is correct |
47 | Correct | 63 ms | 9556 KB | Output is correct |
48 | Correct | 62 ms | 9532 KB | Output is correct |
49 | Correct | 61 ms | 9556 KB | Output is correct |
50 | Correct | 63 ms | 9528 KB | Output is correct |
51 | Correct | 64 ms | 9528 KB | Output is correct |
52 | Correct | 62 ms | 9512 KB | Output is correct |
53 | Correct | 64 ms | 9512 KB | Output is correct |
54 | Correct | 62 ms | 9492 KB | Output is correct |
55 | Correct | 62 ms | 9528 KB | Output is correct |
56 | Correct | 5 ms | 9300 KB | Output is correct |
57 | Correct | 45 ms | 9044 KB | Output is correct |
58 | Correct | 43 ms | 9500 KB | Output is correct |
59 | Correct | 4 ms | 8916 KB | Output is correct |
60 | Correct | 4 ms | 9044 KB | Output is correct |
61 | Correct | 5 ms | 9300 KB | Output is correct |
62 | Correct | 45 ms | 35544 KB | Output is correct |
63 | Correct | 43 ms | 28616 KB | Output is correct |
64 | Correct | 52 ms | 36184 KB | Output is correct |
65 | Correct | 65 ms | 41936 KB | Output is correct |
66 | Correct | 61 ms | 42052 KB | Output is correct |
67 | Correct | 63 ms | 41992 KB | Output is correct |
68 | Correct | 61 ms | 42084 KB | Output is correct |
69 | Correct | 64 ms | 42020 KB | Output is correct |
70 | Correct | 62 ms | 42016 KB | Output is correct |
71 | Correct | 56 ms | 41936 KB | Output is correct |
72 | Correct | 57 ms | 41972 KB | Output is correct |
73 | Correct | 37 ms | 16076 KB | Output is correct |
74 | Correct | 76 ms | 41572 KB | Output is correct |
75 | Correct | 42 ms | 34580 KB | Output is correct |
76 | Correct | 4 ms | 8916 KB | Output is correct |
77 | Incorrect | 38 ms | 24336 KB | Output isn't correct |
78 | Halted | 0 ms | 0 KB | - |