QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371604#4891. 树上的孤独zsq1472583690 1537ms227028kbC++173.8kb2024-03-30 14:21:472024-03-30 14:21:48

Judging History

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

  • [2024-03-30 14:21:48]
  • 评测
  • 测评结果:0
  • 用时:1537ms
  • 内存:227028kb
  • [2024-03-30 14:21:47]
  • 提交

answer

#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+50,Q=2e6,M=21,inf=1e9+7,T=1e7;

int n,m,q,c[M],val[N];
vector<int>s[M],g[N];

struct edge
{
    int u,v,nxt;
}e[N];

int head[N],cnt,dp[M];

void add()
{
    int u,v;cin>>u>>v;
    e[++cnt]=(edge){u,v,head[u]};head[u]=cnt;
    e[++cnt]=(edge){v,u,head[v]};head[v]=cnt;
}

void Aadd()
{
    int u,v;cin>>u>>v;
    g[u].push_back(v);
    g[v].push_back(u);
}

void init(int x,int fa)
{
    s[x].push_back(x);dp[x]=dp[fa]+1;
    for(auto v:g[x])if(v!=fa)
    {
        init(v,x);
        for(auto t:s[v])s[x].push_back(t);
    }
}

vector<int>ask[N];
int cc[N],ty[Q],d1[Q],d2[Q],p1[Q],p2[Q],siz[N],son[N],d[N];

void dfs(int x,int f)
{
    siz[x]=1;d[x]=d[f]+1;
    for(int i=head[x];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if(v==f)continue;
        dfs(v,x);siz[x]+=siz[v];
        if(siz[v]>siz[son[x]])son[x]=v;
    }
}

vector<int>p[M];
int mindep[M][N],vis[M][N],typ[M];

int sum[T],tot,tl[T],tr[T],ro[N];

#define mid ((l+r)>>1)

void merge(int&a,int b,int l,int r)
{
    if(!a||!b){a=a+b;return;}
    ++tot;sum[tot]=sum[a]+sum[b];tl[tot]=tl[a];tr[tot]=tr[a];a=tot;
    if(l!=r)merge(tl[a],tl[b],l,mid),merge(tr[a],tr[b],mid+1,r);
}

void insert(int&x,int l,int r,int d,int w)
{
    ++tot;sum[tot]=sum[x]+w;tl[tot]=tl[x];tr[tot]=tr[x];x=tot;
    if(l==r)return;
    if(d<=mid)insert(tl[x],l,mid,d,w);else insert(tr[x],mid+1,r,d,w);
}

int find(int x,int l,int r,int L,int R)
{
    if(L<=l&&R>=r)return sum[x];
    if(!x)return 0;
    int ans=0;
    if(L<=mid)ans+=find(tl[x],l,mid,L,R);
    if(R>mid)ans+=find(tr[x],mid+1,r,L,R);
    return ans;
}

void up(int dep,int w,int d,int x)
{
    if(vis[dep][w]!=typ[dep])
    {
        vis[dep][w]=typ[dep];
        mindep[dep][w]=d;
        insert(ro[x],1,m,d,1);
        // cout<<"insert "<<d<<' '<<1<<'\n';
        p[dep].push_back(w);
    }
    else if(mindep[dep][w]>d)
    {
        insert(ro[x],1,m,mindep[dep][w],-1);
        insert(ro[x],1,m,d,1);
        // cout<<"insert "<<d<<' '<<1<<'\n';
        // cout<<"insert "<<mindep[dep][w]<<' '<<-1<<'\n';
        mindep[dep][w]=d;
    }
}

void merge(int u,int v,int x)
{
    for(auto w:p[v])up(u,w,mindep[v][w],x);
}

void solve(int x,int fa,int dep)
{
    if(son[x])solve(son[x],x,dep),ro[x]=ro[son[x]];
    up(dep,val[x],d[x],x);
    // cout<<x<<":\n";
    // for(auto t:p[dep])cout<<t<<' '<<mindep[dep][t]<<'\n';
    for(int i=head[x];i;i=e[i].nxt)
    {
        int v=e[i].v;if(v==fa||v==son[x])continue;
        p[dep+1].clear();++typ[dep+1];
        solve(v,x,dep+1);merge(dep,dep+1,x);
    }
    for(auto&t:ask[x])t=vis[dep][t]!=typ[dep]?inf:mindep[dep][t];
}

main()
{
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    cin>>n>>m>>q;
    for(int i=1;i<n;i++)Aadd();
    for(int i=1;i<m;i++)add();
    for(int i=1;i<=n;i++)cin>>c[i];
    for(int i=1;i<=m;i++)cin>>val[i];
    for(int i=1;i<=20;i++)typ[i]=1;
    init(1,0);
    for(int i=1,u,v;i<=q;i++)
    {
        cin>>ty[i];
        if(ty[i]==1)
        {
            cin>>p1[i]>>p2[i]>>d1[i]>>d2[i];
            for(auto x:s[p1[i]])ask[p2[i]].push_back(c[x]);
        }
        else cin>>u>>v,c[u]=v;
    }
    dfs(1,1);solve(1,1,1);
    // for(int i=1;i<=m;i++)cout<<dp[i]<<' '<<d[i]<<'\n';
    for(int i=1,las=0;i<=q;i++)if(ty[i]==1)
    {
        d1[i]^=las;d2[i]^=las;
        las=find(ro[p2[i]],1,m,d[p2[i]],min(m,d[p2[i]]+d2[i]));
        // cout<<"query "<<p2[i]<<' '<<d[p2[i]]<<' '<<min(m,d[p2[i]]+d2[i])<<' '<<las<<'\n';
        for(auto x:s[p1[i]])
        {
            if(dp[x]-dp[p1[i]]<=d1[i])las+=(ask[p2[i]][cc[p2[i]]]>d2[i]);
            ++cc[p2[i]];
        }
        cout<<las<<'\n';
    }
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 28168kb

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:

106
91
2
45
19
55
196
26
69
21
22
200
83
95
137
34
73
72
61
45
22
8
24
85
62
101
27
200
42
77
105
21
87
37
197
77
28
49
11
20
55
62
24
5
110
158
25
23
15
113
25
118
28
83
164
83
32
147
145
9
137
33
112
142
120
69
36
71
20
50
60
53
56
14
37
149
113
143
144
200
22
81
89
49
73
27
31
39
179
57
63
52
99
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 924ms
memory: 181448kb

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:

2
17595
3899
3423
16
518
5138
11355
21
7340
21
18327
15807
6638
514
1184
6111
1884
6241
662
16738
13230
1597
5446
6074
2388
6266
2
21
282
3511
1807
1236
1038
17805
4658
5536
4633
4547
21
244
2703
2
4610
8578
3970
21
13498
5648
2054
3489
4869
5828
802
2072
1482
13232
2593
938
16769
2
17623
353
5
21
7...

result:

wrong answer 3rd numbers differ - expected: '3898', found: '3899'

Subtask #3:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 208ms
memory: 91952kb

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:

2568
612
8348
8985
3568
9200
673
301
2479
7310
2688
1047
1403
1270
8227
4407
109
2699
640
4486
3166
9202
21
8997
2092
9950
8009
9945
21
5043
89
2041
1881
19
1295
2185
336
1106
9386
3477
7726
1957
2742
1262
2335
715
21
545
21
448
699
2337
499
18
38
1424
2325
693
2465
21
2320
716
10000
8
196
1366
8952...

result:

wrong answer 3rd numbers differ - expected: '8337', found: '8348'

Subtask #4:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 752ms
memory: 157456kb

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
19394
1952
2
5499
2
2859
3369
7393
5131
5706
2
6001
19866
2
5124
2
12550
1497
4837
7770
16334
18175
5926
17983
19707
3821
17710
17093
4226
3822
576
5638
3660
4988
15688
2
18774
29
5068
16606
2276
16601
4545
598
845
19976
7055
882
164
2744
1683
6747
5091
1632
5137
2931
2778
1...

result:

wrong answer 9th numbers differ - expected: '5498', found: '5499'

Subtask #5:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 1537ms
memory: 227028kb

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:

459
5821
10129
7656
4885
19482
3579
16026
2835
7538
1131
9925
18500
498
11890
2117
9859
7579
7286
111
1854
7399
3350
6104
19508
16470
6208
1725
5926
5597
3823
1919
718
3322
2717
19891
5606
636
753
1301
16010
2973
1674
14673
5224
2622
118
1896
3266
1937
14605
4578
7219
5910
11044
4392
7462
9760
19632...

result:

wrong answer 2nd numbers differ - expected: '5817', found: '5821'