Submission #729020

# Submission time Handle Problem Language Result Execution time Memory
729020 2023-04-23T11:54:57 Z MilosMilutinovic Tourism (JOI23_tourism) C++14
100 / 100
875 ms 24912 KB
#include <bits/stdc++.h>
using namespace std;

int n,m,q,c[100005],sz[100005],dep[100005];
vector<int> g[100005];
vector<pair<int,int>> qs[100005];
int son[100005],head[100005],pos[100005],pv,pr[100005];
int ans[100005];

void dfs(int x,int fa)
{
    sz[x]=1;pr[x]=fa;
    dep[x]=dep[fa]+1;
    int mx=0;
    for(int y:g[x])
    {
        if(y==fa) continue;
        dfs(y,x);sz[x]+=sz[y];
        if(sz[y]>mx)mx=sz[y],son[x]=y;
    }
}
void build(int x,int fa,int c)
{
    head[x]=c;pos[x]=++pv;
    if(son[x])build(son[x],x,c);
    for(int y:g[x])
        if(y!=fa&&y!=son[x])
            build(y,x,y);
}

int fenw[100005];
void update(int x,int f)
{
    for(int i=x;i<=100000;i+=i&-i)fenw[i]+=f;
}
int query(int x)
{
    int f=0;
    for(int i=x;i>0;i-=i&-i)f+=fenw[i];
    return f;
}

set<tuple<int,int,int>> st;
void change(int a,int b,int c)
{
    if(a>b)swap(a,b);
    while(true)
    {
        auto it=st.lower_bound({a,-1,-1});
        if(it==st.end()||get<1>(*it)>b||get<0>(*it)<a) break;
        st.erase(it);
        int l=get<1>(*it),r=get<0>(*it),v=get<2>(*it);
        int len=min(r,b)-max(l,a)+1;
        update(v,-len);
        if(l<a) st.emplace(a-1,l,v);
        if(b<r) st.emplace(r,b+1,v);
    }
    st.emplace(b,a,c);
    update(c,b-a+1);
}
void update(int a,int b,int c)
{
    for(;head[a]!=head[b];b=pr[head[b]])
    {
        if(dep[head[a]]>dep[head[b]]) swap(a,b);
        change(pos[head[b]],pos[b],c);
    }
    change(pos[a],pos[b],c);
}

signed main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<n;i++)
    {
        int a,b;scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1,1);
    build(1,1,1);
    for(int i=1;i<=m;i++) scanf("%d",&c[i]);
    for(int i=1;i<=q;i++)
    {
        int l,r;scanf("%d%d",&l,&r);
        qs[r].push_back({l,i});
    }
    for(int i=1;i<=m;i++)
    {
        if(i>1) update(c[i-1],c[i],i-1);
        for(auto&p:qs[i]) ans[p.second]=query(100000)-query(p.first-1);
    }
    for(int i=1;i<=q;i++) printf("%d\n",max(1,ans[i]));
}

Compilation message

tourism.cpp: In function 'int main()':
tourism.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
tourism.cpp:76:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         int a,b;scanf("%d%d",&a,&b);
      |                 ~~~~~^~~~~~~~~~~~~~
tourism.cpp:82:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     for(int i=1;i<=m;i++) scanf("%d",&c[i]);
      |                           ~~~~~^~~~~~~~~~~~
tourism.cpp:85:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         int l,r;scanf("%d%d",&l,&r);
      |                 ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 5 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 5 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 7 ms 5144 KB Output is correct
31 Correct 7 ms 5272 KB Output is correct
32 Correct 8 ms 5300 KB Output is correct
33 Correct 8 ms 5332 KB Output is correct
34 Correct 8 ms 5332 KB Output is correct
35 Correct 8 ms 5300 KB Output is correct
36 Correct 10 ms 5300 KB Output is correct
37 Correct 9 ms 5304 KB Output is correct
38 Correct 7 ms 5308 KB Output is correct
39 Correct 6 ms 5372 KB Output is correct
40 Correct 6 ms 5332 KB Output is correct
41 Correct 6 ms 5332 KB Output is correct
42 Correct 5 ms 5332 KB Output is correct
43 Correct 6 ms 5288 KB Output is correct
44 Correct 6 ms 5332 KB Output is correct
45 Correct 6 ms 5204 KB Output is correct
46 Correct 6 ms 5332 KB Output is correct
47 Correct 6 ms 5204 KB Output is correct
48 Correct 8 ms 5204 KB Output is correct
49 Correct 6 ms 5204 KB Output is correct
50 Correct 6 ms 5308 KB Output is correct
51 Correct 7 ms 5332 KB Output is correct
52 Correct 6 ms 5332 KB Output is correct
53 Correct 8 ms 5332 KB Output is correct
54 Correct 7 ms 5300 KB Output is correct
55 Correct 7 ms 5312 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 8 ms 5324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 92 ms 15952 KB Output is correct
5 Correct 79 ms 20040 KB Output is correct
6 Correct 93 ms 20632 KB Output is correct
7 Correct 127 ms 24652 KB Output is correct
8 Correct 124 ms 24284 KB Output is correct
9 Correct 126 ms 24780 KB Output is correct
10 Correct 129 ms 24912 KB Output is correct
11 Correct 124 ms 24520 KB Output is correct
12 Correct 113 ms 22732 KB Output is correct
13 Correct 111 ms 24336 KB Output is correct
14 Correct 112 ms 24364 KB Output is correct
15 Correct 57 ms 21180 KB Output is correct
16 Correct 121 ms 24628 KB Output is correct
17 Correct 58 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 220 ms 11324 KB Output is correct
3 Correct 339 ms 11752 KB Output is correct
4 Correct 286 ms 11980 KB Output is correct
5 Correct 456 ms 15804 KB Output is correct
6 Correct 433 ms 15200 KB Output is correct
7 Correct 467 ms 15692 KB Output is correct
8 Correct 480 ms 15164 KB Output is correct
9 Correct 449 ms 15216 KB Output is correct
10 Correct 483 ms 15736 KB Output is correct
11 Correct 465 ms 16008 KB Output is correct
12 Correct 512 ms 15588 KB Output is correct
13 Correct 446 ms 16872 KB Output is correct
14 Correct 447 ms 16652 KB Output is correct
15 Correct 480 ms 19768 KB Output is correct
16 Correct 432 ms 15060 KB Output is correct
17 Correct 441 ms 15244 KB Output is correct
18 Correct 443 ms 15224 KB Output is correct
19 Correct 273 ms 12852 KB Output is correct
20 Correct 274 ms 11852 KB Output is correct
21 Correct 286 ms 11808 KB Output is correct
22 Correct 272 ms 12744 KB Output is correct
23 Correct 263 ms 13228 KB Output is correct
24 Correct 271 ms 11840 KB Output is correct
25 Correct 273 ms 11888 KB Output is correct
26 Correct 295 ms 11904 KB Output is correct
27 Correct 289 ms 12508 KB Output is correct
28 Correct 282 ms 13356 KB Output is correct
29 Correct 319 ms 12104 KB Output is correct
30 Correct 298 ms 12452 KB Output is correct
31 Correct 303 ms 13244 KB Output is correct
32 Correct 306 ms 13092 KB Output is correct
33 Correct 328 ms 14668 KB Output is correct
34 Correct 339 ms 15924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 5 ms 5076 KB Output is correct
4 Correct 645 ms 15588 KB Output is correct
5 Correct 642 ms 15300 KB Output is correct
6 Correct 821 ms 18452 KB Output is correct
7 Correct 863 ms 20504 KB Output is correct
8 Correct 809 ms 20000 KB Output is correct
9 Correct 875 ms 19812 KB Output is correct
10 Correct 781 ms 20640 KB Output is correct
11 Correct 787 ms 20704 KB Output is correct
12 Correct 756 ms 20024 KB Output is correct
13 Correct 738 ms 20364 KB Output is correct
14 Correct 56 ms 9456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 5 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 7 ms 5144 KB Output is correct
31 Correct 7 ms 5272 KB Output is correct
32 Correct 8 ms 5300 KB Output is correct
33 Correct 8 ms 5332 KB Output is correct
34 Correct 8 ms 5332 KB Output is correct
35 Correct 8 ms 5300 KB Output is correct
36 Correct 10 ms 5300 KB Output is correct
37 Correct 9 ms 5304 KB Output is correct
38 Correct 7 ms 5308 KB Output is correct
39 Correct 6 ms 5372 KB Output is correct
40 Correct 6 ms 5332 KB Output is correct
41 Correct 6 ms 5332 KB Output is correct
42 Correct 5 ms 5332 KB Output is correct
43 Correct 6 ms 5288 KB Output is correct
44 Correct 6 ms 5332 KB Output is correct
45 Correct 6 ms 5204 KB Output is correct
46 Correct 6 ms 5332 KB Output is correct
47 Correct 6 ms 5204 KB Output is correct
48 Correct 8 ms 5204 KB Output is correct
49 Correct 6 ms 5204 KB Output is correct
50 Correct 6 ms 5308 KB Output is correct
51 Correct 7 ms 5332 KB Output is correct
52 Correct 6 ms 5332 KB Output is correct
53 Correct 8 ms 5332 KB Output is correct
54 Correct 7 ms 5300 KB Output is correct
55 Correct 7 ms 5312 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 8 ms 5324 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 92 ms 15952 KB Output is correct
63 Correct 79 ms 20040 KB Output is correct
64 Correct 93 ms 20632 KB Output is correct
65 Correct 127 ms 24652 KB Output is correct
66 Correct 124 ms 24284 KB Output is correct
67 Correct 126 ms 24780 KB Output is correct
68 Correct 129 ms 24912 KB Output is correct
69 Correct 124 ms 24520 KB Output is correct
70 Correct 113 ms 22732 KB Output is correct
71 Correct 111 ms 24336 KB Output is correct
72 Correct 112 ms 24364 KB Output is correct
73 Correct 57 ms 21180 KB Output is correct
74 Correct 121 ms 24628 KB Output is correct
75 Correct 58 ms 8652 KB Output is correct
76 Correct 3 ms 5068 KB Output is correct
77 Correct 220 ms 11324 KB Output is correct
78 Correct 339 ms 11752 KB Output is correct
79 Correct 286 ms 11980 KB Output is correct
80 Correct 456 ms 15804 KB Output is correct
81 Correct 433 ms 15200 KB Output is correct
82 Correct 467 ms 15692 KB Output is correct
83 Correct 480 ms 15164 KB Output is correct
84 Correct 449 ms 15216 KB Output is correct
85 Correct 483 ms 15736 KB Output is correct
86 Correct 465 ms 16008 KB Output is correct
87 Correct 512 ms 15588 KB Output is correct
88 Correct 446 ms 16872 KB Output is correct
89 Correct 447 ms 16652 KB Output is correct
90 Correct 480 ms 19768 KB Output is correct
91 Correct 432 ms 15060 KB Output is correct
92 Correct 441 ms 15244 KB Output is correct
93 Correct 443 ms 15224 KB Output is correct
94 Correct 273 ms 12852 KB Output is correct
95 Correct 274 ms 11852 KB Output is correct
96 Correct 286 ms 11808 KB Output is correct
97 Correct 272 ms 12744 KB Output is correct
98 Correct 263 ms 13228 KB Output is correct
99 Correct 271 ms 11840 KB Output is correct
100 Correct 273 ms 11888 KB Output is correct
101 Correct 295 ms 11904 KB Output is correct
102 Correct 289 ms 12508 KB Output is correct
103 Correct 282 ms 13356 KB Output is correct
104 Correct 319 ms 12104 KB Output is correct
105 Correct 298 ms 12452 KB Output is correct
106 Correct 303 ms 13244 KB Output is correct
107 Correct 306 ms 13092 KB Output is correct
108 Correct 328 ms 14668 KB Output is correct
109 Correct 339 ms 15924 KB Output is correct
110 Correct 3 ms 4948 KB Output is correct
111 Correct 3 ms 5076 KB Output is correct
112 Correct 5 ms 5076 KB Output is correct
113 Correct 645 ms 15588 KB Output is correct
114 Correct 642 ms 15300 KB Output is correct
115 Correct 821 ms 18452 KB Output is correct
116 Correct 863 ms 20504 KB Output is correct
117 Correct 809 ms 20000 KB Output is correct
118 Correct 875 ms 19812 KB Output is correct
119 Correct 781 ms 20640 KB Output is correct
120 Correct 787 ms 20704 KB Output is correct
121 Correct 756 ms 20024 KB Output is correct
122 Correct 738 ms 20364 KB Output is correct
123 Correct 56 ms 9456 KB Output is correct
124 Correct 424 ms 19944 KB Output is correct
125 Correct 314 ms 17464 KB Output is correct
126 Correct 487 ms 20604 KB Output is correct
127 Correct 488 ms 20460 KB Output is correct
128 Correct 520 ms 19960 KB Output is correct
129 Correct 492 ms 20516 KB Output is correct
130 Correct 493 ms 20484 KB Output is correct
131 Correct 129 ms 23732 KB Output is correct
132 Correct 133 ms 24736 KB Output is correct
133 Correct 141 ms 21084 KB Output is correct
134 Correct 313 ms 17464 KB Output is correct
135 Correct 314 ms 17248 KB Output is correct
136 Correct 307 ms 17440 KB Output is correct
137 Correct 189 ms 20928 KB Output is correct
138 Correct 189 ms 21132 KB Output is correct
139 Correct 190 ms 21060 KB Output is correct
140 Correct 193 ms 21352 KB Output is correct
141 Correct 204 ms 21388 KB Output is correct
142 Correct 221 ms 21360 KB Output is correct
143 Correct 67 ms 13544 KB Output is correct
144 Correct 507 ms 20368 KB Output is correct