QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#360592#4891. 树上的孤独dengtingyu0 1802ms833324kbC++144.8kb2024-03-21 22:20:252024-03-21 22:20:26

Judging History

你现在查看的是最新测评结果

  • [2024-03-21 22:20:26]
  • 评测
  • 测评结果:0
  • 用时:1802ms
  • 内存:833324kb
  • [2024-03-21 22:20:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200010
#define Q 1001000
ll n,m,q;
vector<ll>g[N],e[N];
ll d1[N],c1[N],df1[N],s1[N];ll dc1=0;
inline bool pd1(ll x,ll y){return df1[x]<=df1[y]&&df1[y]<=df1[x]+s1[x]-1;}
inline void dfs(ll x,ll fa){
    d1[x]=d1[fa]+1;df1[x]=++dc1;s1[x]=1;
    for(auto o:g[x])if(o!=fa)dfs(o,x),s1[x]+=s1[o];
    return ;
}
ll dep[N],col[N];
ll siz[N],son[N],top[N],fa[N];
ll dfn[N],dfncnt=0;
inline bool pd(ll x,ll y){return dfn[x]<=dfn[y]&dfn[y]<=dfn[x]+siz[x]-1;}
inline void dfs1(ll x,ll faa){
    fa[x]=faa;siz[x]=1;dep[x]=dep[faa]+1;
    for(auto o:e[x]){
        if(o==faa)continue;
        dfs1(o,x);siz[x]+=siz[o];
        if(siz[o]>siz[son[x]])son[x]=o;
    }return ;
}
ll dui[N];
inline void dfs2(ll x,ll tp){
    top[x]=tp;dfn[x]=++dfncnt;dui[dfncnt]=x;
    if(son[x]){
        dfs2(son[x],tp);
    }for(auto o:e[x]){
        if(!dfn[o])dfs2(o,o);
    }return ;
}
inline ll lca(ll x,ll y){
    while(top[x]!=top[y]){
        if(dep[top[x]]<dep[top[y]])swap(x,y);
        x=fa[top[x]];
    }if(dep[x]<dep[y])swap(x,y);
    return y;
}
ll rt[N],lc[N*40],rc[N*40],val[N*40];ll gg=0;
inline void pushup(ll o){val[o]=val[lc[o]]+val[rc[o]];return ;}
inline void update(ll &o,ll l,ll r,ll x,ll y){
    if(!o)o=++gg;if(l==r){val[o]+=y;return ;}
    ll mid=(l+r)>>1;
    if(mid>=x)update(lc[o],l,mid,x,y);
    else update(rc[o],mid+1,r,x,y);
    pushup(o);return ;
}
inline ll merge(ll o,ll p,ll l,ll r){
    if(!o||!p)return o+p;
    if(l==r){val[o]+=val[p];return o;}
    ll mid=(l+r)>>1;
    lc[o]=merge(lc[o],lc[p],l,mid);
    rc[o]=merge(rc[o],rc[p],mid+1,r);
    pushup(o);return o;
}
inline ll ask(ll o,ll l,ll r,ll x,ll y){
    if(!o)return 0;if(x<=l&&r<=y)return val[o];
    ll an=0,mid=(l+r)>>1;
    if(mid>=x)an+=ask(lc[o],l,mid,x,y);
    if(mid<y)an+=ask(rc[o],mid+1,r,x,y);
    return an;
}
ll tem[N];ll cn=0;ll mi[N];
vector<ll>ex[N],wc[N];
inline bool cmp(ll x,ll y){return dfn[x]<dfn[y];}
ll vv[N];
inline void build(){
    sort(tem+1,tem+cn+1,cmp);cn=unique(tem+1,tem+cn+1)-tem-1;for(int i=1;i<=cn;i++)vv[tem[i]]=1;
    ll pre=cn;for(int i=1;i<pre;i++)tem[++cn]=lca(tem[i],tem[i+1]);
    sort(tem+1,tem+cn+1,cmp);cn=unique(tem+1,tem+cn+1)-tem-1;
    for(int i=2;i<=cn;i++)ex[lca(tem[i-1],tem[i])].push_back(tem[i]);
    return ;
}
inline void gt(ll x){
    if(vv[x])mi[x]=dep[x];
    for(auto o:ex[x]){
        gt(o);update(rt[x],1,n,mi[o],-1);
        mi[x]=min(mi[x],mi[o]);
    }update(rt[x],1,n,mi[x],1);
    return ;
}
vector<ll>hs[N],dd[N],ji[N],xw[N];
inline void clear(ll tp){
    // if(tp==3)cout<<tem[1]<<' '<<mi[tem[1]]<<' '<<dd[tem[1]].size()<<'\n';
    for(int i=1;i<=cn;i++)hs[tem[i]].push_back(tp),dd[tem[i]].push_back(mi[tem[i]]),ex[tem[i]].clear(),mi[tem[i]]=n+1;cn=0;
    return ;
}
inline void idfs(ll x,ll fa){
    for(auto o:e[x]){
        if(o==fa)continue;
        idfs(o,x);rt[x]=merge(rt[x],rt[o],1,n);
    }return ;
}
#define V 20001000
ll x[V],y[V],ans[V];ll cnt=0;
ll fir[Q],p1[Q],p2[Q],p3[Q],p4[Q];ll gs=0;
ll vis[N];
int main(){
    //freopen("test1.in","r",stdin);
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>m>>n>>q;for(int i=1,u,v;i<m;i++)cin>>u>>v,g[u].push_back(v),g[v].push_back(u);for(int i=1,u,v;i<n;i++)cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
    for(int i=1;i<=m;i++)cin>>c1[i];for(int i=1;i<=n;i++)cin>>col[i],wc[col[i]].push_back(i);
    dfs(1,0);dfs1(1,0);dfs2(1,1);
    for(int i=1;i<=n;i++)mi[i]=n+1;
    for(int i=1;i<=n;i++){
        for(auto o:wc[i])tem[++cn]=o;if(!cn)continue;
        build();gt(tem[1]);
        clear(i);
    }idfs(1,0);
    for(int i=1;i<=q;i++){
        ll op;cin>>op;if(op==1){
            ++gs;cin>>p1[gs]>>p2[gs]>>p3[gs]>>p4[gs];
            fir[gs]=cnt;for(int i=1;i<=m;i++){
                x[++cnt]=p2[gs];y[cnt]=c1[i];xw[p2[gs]].push_back(cnt);
            }
        }else{
            ll x,y;cin>>x>>y;c1[x]=y;
        }
    }for(int t=1;t<=n;t++){
        ll i=dui[t];for(auto o:xw[i])ji[y[o]].push_back(o);
        ll nw=0;for(auto o:hs[i]){
            ll val=dd[i][nw++];
            for(auto p:ji[o]){
                if(pd(x[p],i))ans[p]=val;
                else ans[p]=n+1;
            }ji[o].clear();
        }
    }for(int i=1;i<=n;i++)for(auto o:ji[i])ans[o]=n+1;
    // cout<<val[rt[1]]<<'\n';
    // cout<<ask(rt[1],1,n,1,3)<<'\n';return 0;
    // cout<<cnt<<'\n';for(int i=1;i<=cnt;i++)cout<<ans[i]<<'\n';
    ll las=0;for(int i=1;i<=gs;i++){
        p3[i]^=las;p4[i]^=las;ll lim=min(dep[p2[i]]+p4[i],n);
        las=ask(rt[p2[i]],1,n,1,lim);
        for(int j=1;j<=m;j++){
            if(!pd(p1[i],j)||dep[j]>d1[p1[i]]+p3[i]||ans[fir[i]+j]<=lim||vis[y[fir[i]+j]])continue;
            las++;vis[y[fir[i]+j]]=1;
        }for(int j=fir[i]+1;j<=fir[i]+m;j++)vis[y[j]]=0;
        cout<<las<<'\n';
    }return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 63956kb

input:

20 2000 2000
8 15
8 13
14 8
14 7
12 14
12 1
9 13
9 4
5 9
5 10
2 5
2 19
6 19
6 16
11 7
11 20
18 2
18 17
3 6
1395 1783
1395 1735
1735 457
457 739
739 438
438 101
101 441
441 1879
1879 1238
1238 501
501 1732
1732 1910
1910 2000
2000 834
834 917
917 111
111 780
780 1966
1966 1604
1604 623
623 1748
1748 ...

output:

103
83
1
41
1
37
194
17
67
5
4
200
86
79
135
26
54
7
71
30
10
6
11
57
53
100
27
200
24
118
88
20
75
22
200
104
15
48
10
19
57
48
23
2
108
157
15
4
14
94
45
99
15
35
56
21
117
141
182
8
136
24
97
135
113
60
22
53
2
10
41
35
42
13
33
184
102
127
141
200
8
71
62
110
72
9
12
23
173
44
61
46
98
12
53
58
...

result:

wrong answer 1st numbers differ - expected: '105', found: '103'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 1218ms
memory: 597348kb

input:

20 200000 500000
8 18
8 4
2 4
2 14
13 4
13 16
6 4
6 3
1 4
1 17
15 6
15 19
7 17
7 11
5 14
5 10
20 7
12 15
9 8
165302 77239
165302 198189
165302 180850
165302 192738
165302 173589
165302 194087
165302 191990
165302 167370
165302 101092
165302 92553
165302 163654
165302 122381
165302 152105
165302 1919...

output:

1
17595
3901
3419
1
517
5136
11355
16
7339
12
18327
16007
6628
513
1179
6110
1877
6230
661
16736
13230
1597
5445
6064
2389
6265
2
2
277
3498
1806
1235
1036
17801
4657
5526
4632
4546
8
243
2685
1
4609
8562
4030
8
13497
5636
2052
3486
4879
5829
791
2054
1508
13231
2590
923
16904
12
17623
353
1
2
714
1...

result:

wrong answer 1st numbers differ - expected: '2', found: '1'

Subtask #3:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 290ms
memory: 204828kb

input:

20 100000 100000
16 12
16 20
6 12
6 18
2 16
2 8
5 20
5 13
3 6
3 11
19 11
19 17
9 12
9 15
4 15
4 7
10 5
14 15
14 1
85812 94626
85812 91172
91172 93788
93788 96567
96567 75524
75524 23275
23275 98340
98340 81608
81608 91480
91480 75108
75108 56605
56605 93317
93317 41617
41617 77160
77160 727
727 7559...

output:

2566
605
9210
8983
3551
9180
637
283
2464
7307
2670
1169
1385
1252
8991
4396
91
2680
623
5274
3153
9182
5
9409
2091
9977
9325
2455
3
5037
71
2022
1881
1
1276
2179
335
1075
9386
3463
7723
1957
2740
1242
2317
699
3
544
3
429
698
2319
463
3
8
1422
2307
675
2439
3
2318
698
9999
1
177
1365
8932
8257
7664...

result:

wrong answer 1st numbers differ - expected: '2568', found: '2566'

Subtask #4:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 716ms
memory: 251024kb

input:

1 200000 500000
189127 137023
189127 199761
199761 160701
160701 130639
130639 190908
190908 176819
176819 193363
193363 188021
188021 182446
182446 186028
186028 198828
198828 190792
190792 155378
155378 189428
189428 177276
177276 146159
146159 175923
175923 188073
188073 182206
182206 131072
1310...

output:

3782
1773
771
7328
18160
19791
1952
2
5498
2
2859
3368
7393
5131
5706
2
10560
19991
2
5123
2
12880
1497
4837
7770
16333
18175
5926
17983
19867
3821
17709
17124
4226
3822
576
5637
3660
7061
16945
2
19416
29
5068
16662
2276
16601
4544
598
845
19983
7054
882
164
2744
1683
9558
5091
1632
7251
2931
2778
...

result:

wrong answer 6th numbers differ - expected: '19394', found: '19791'

Subtask #5:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 1802ms
memory: 833324kb

input:

20 200000 1000000
13 10
13 5
19 5
19 20
15 10
15 6
12 6
12 3
8 10
8 2
1 20
1 11
14 10
14 16
18 3
18 7
4 3
9 10
9 17
194055 154514
194055 148156
148156 115271
115271 198116
198116 179433
179433 171975
171975 196600
196600 167194
167194 185078
185078 191409
191409 163496
163496 178243
178243 154093
15...

output:

453
5802
10112
7654
5834
19789
3563
16844
2833
7536
1118
9912
18673
484
11873
2117
9841
7574
7600
98
1835
7381
3344
13925
19841
17423
6206
1724
5911
5590
3806
1913
699
3303
2699
19890
5604
624
751
1299
15990
2968
1655
14634
5209
5923
103
1895
3249
1874
14889
4577
7218
5895
11019
4392
7459
9746
19647...

result:

wrong answer 1st numbers differ - expected: '459', found: '453'