QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376046#4891. 树上的孤独27455185850 1388ms482040kbC++204.5kb2024-04-03 19:58:532024-04-03 19:58:53

Judging History

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

  • [2024-04-03 19:58:53]
  • 评测
  • 测评结果:0
  • 用时:1388ms
  • 内存:482040kb
  • [2024-04-03 19:58:53]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1000001,M=21;
int n1,n,m,q,b1[N],b[N],f[N],g[N][M],rt[N];
bool h[N];
vector<int> a1[N],a[N],e[N],v[N];
vector<pair<int,pair<int,int>>> d[N];
struct
{
    int x1,x2,d1,d2;
}c[N];
namespace sgt
{
    int tot;
    struct tree
    {
        int l,r,s;
    }T[N<<4];
    void pushup(int x)
    {
        T[x].s=T[T[x].l].s+T[T[x].r].s;
    }
    void add(int &x,int ls,int rs,int q,int k)
    {
        T[++tot]=T[x],x=tot;
        if(ls==rs)
        {
            T[x].s+=k;
            return;
        }
        int z=ls+rs>>1;
        if(q<=z) add(T[x].l,ls,z,q,k);
        else add(T[x].r,z+1,rs,q,k);
        pushup(x);
    }
    int sum(int x,int ls,int rs,int l,int r)
    {
        if(ls>=l&&rs<=r) return T[x].s;
        int z=ls+rs>>1,s=0;
        if(l<=z) s+=sum(T[x].l,ls,z,l,r);
        if(r>z) s+=sum(T[x].r,z+1,rs,l,r);
        return s;
    }
    int merge(int &x1,int &x2,int ls,int rs)
    {
        if(x1) T[++tot]=T[x1],x1=tot;
        if(x2) T[++tot]=T[x2],x2=tot;
        if(x1==0||x2==0) return x1|x2;
        if(ls==rs)
        {
            T[x1].s+=T[x2].s;
            return x1;
        }
        int z=ls+rs>>1;
        T[x1].l=merge(T[x1].l,T[x2].l,ls,z);
        T[x1].r=merge(T[x1].r,T[x2].r,z+1,rs);
        pushup(x1);
        return x1;
    }
}
struct tree
{
    int f,s,d,z;
}T1[N],T[N];
void dfs0(int x)
{
    T1[x].d=T1[T1[x].f].d+1;
    for(auto i:a1[x])
    {
        if(i==T1[x].f) continue;
        T1[i].f=x;
        dfs0(i);
    }
}
void dfs1(int x)
{
    T[x].s=1;
    T[x].d=T[T[x].f].d+1;
    for(auto i:a[x])
    {
        if(i==T[x].f) continue;
        T[i].f=x;
        dfs1(i);
        T[x].s+=T[i].s;
        if(T[i].s>T[T[x].z].s) T[x].z=i;
    }
}
void dfs2(int x,int p,int t)
{
    d[p].push_back(make_pair(b1[x],make_pair(x,t)));
    v[t].push_back(x);
    for(auto i:a1[x])
    {
        if(i==T1[x].f) continue;
        dfs2(i,p,t);
    }
}
void dfs(int x)
{
    vector<pair<int,int>> p;
    for(auto i:a[x])
    {
        if(i==T[x].f||i==T[x].z) continue;
        dfs(i);
        for(auto j:e[i])
        {
            p.push_back(make_pair(j,f[j]));
            f[j]=n+1;
        }
    }
    if(T[x].z)
    {
        dfs(T[x].z);
        swap(e[x],e[T[x].z]);
        rt[x]=rt[T[x].z];
    }
    for(auto i:a[x])
    {
        if(i==T[x].f||i==T[x].z) continue;
        rt[x]=sgt::merge(rt[x],rt[i],1,n);
    }
    sgt::add(rt[x],1,n,T[x].d,1);
    auto add=[&](int x,int d)
    {
        if(f[x]==n+1)
        {
            e[x].push_back(x);
            f[x]=d;
        }
        else
        {
            if(d<f[x])
            {
                sgt::add(rt[x],1,n,f[x],-1);
                f[x]=d;
            }
            else sgt::add(rt[x],1,n,d,-1);
        }
    };
    add(b[x],T[x].d);
    for(auto i:p) add(i.first,i.second);
    for(auto i:d[x])
    {
        g[i.second.second][i.second.first]=f[i.first];
    }
    // printf("%d:\n",x);
    // for(int i=1;i<=n;++i) printf("%d ",f[i]);printf("\n");
}
int main()
{
    scanf("%d%d%d",&n1,&n,&q);
    for(int i=1;i<=n1-1;++i)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a1[x].push_back(y);
        a1[y].push_back(x);
    }
    for(int i=1;i<=n-1;++i)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    for(int i=1;i<=n1;++i)
    {
        scanf("%d",&b1[i]);
    }
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&b[i]);
    }
    dfs0(1);
    dfs1(1);
    for(int i=1;i<=q;++i)
    {
        int z;
        scanf("%d",&z);
        if(z==1)
        {
            ++m;
            scanf("%d%d%d%d",&c[m].x1,&c[m].x2,&c[m].d1,&c[m].d2);
            dfs2(c[m].x1,c[m].x2,m);
        }
        else if(z==2)
        {
            int x,k;
            scanf("%d%d",&x,&k);
            b1[x]=k;
        }
    }
    for(int i=1;i<=n;++i) f[i]=n+1;
    dfs(1);
    int las=0;
    for(int i=1;i<=m;++i)
    {
        c[i].d1^=las,c[i].d2^=las;
        int s=sgt::sum(rt[c[i].x2],1,n,T[c[i].x2].d,T[c[i].x2].d+c[i].d2);
        // printf("%d\n",s);
        for(auto j:v[i])
        {
            if(h[b1[j]]==false&&T1[j].d<=T1[c[i].x1].d+c[i].d1&&g[i][j]>T[c[i].x2].d)
            {
                h[b1[j]]=true;
                ++s;
            }
        }
        for(auto j:v[i]) h[b1[j]]=false;
        printf("%d\n",las=s);
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 15536kb

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:

144
161
1
46
1
43
547
6
79
9
16
1383
351
95
231
41
59
15
74
24
11
7
14
80
60
139
26
1521
26
179
101
20
101
38
967
335
15
55
12
19
71
56
26
2
166
59
14
3
16
107
32
143
15
48
12
52
269
96
903
8
219
16
147
235
174
62
23
66
1
12
48
37
60
13
38
256
157
175
221
786
11
98
17
139
79
9
17
25
386
42
74
55
121...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 980ms
memory: 357420kb

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
41910
4333
3741
7
524
5919
16883
1
9093
14
50178
46047
8036
521
1214
7282
1959
7451
672
35651
21304
1658
6422
7166
2536
7521
2
1
279
3862
1896
1258
1065
43756
5301
6522
5279
5138
19
245
2872
2
5266
12836
6839
11
22055
5061
2148
3875
5943
6870
818
2172
1642
21332
2780
956
36919
2
42150
340
1
1
729
...

result:

wrong answer 2nd numbers differ - expected: '17595', found: '41910'

Subtask #3:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 194ms
memory: 120704kb

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:

2958
630
16890
818
193
21124
1861
287
2842
12444
3133
642
1504
1350
13234
5799
99
3102
646
4990
3789
21128
4
19525
2353
48741
92705
46267
4
6981
71
2248
503
4
1359
2465
343
1140
27804
4249
314
3231
3216
783
2689
739
4
559
4
437
722
2687
684
3
9
1541
2673
696
1995
3
2688
718
76672
1
184
1477
22280
48...

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 646ms
memory: 213324kb

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:

4213
1851
787
9071
47393
172614
2052
1
6386
1
3100
3674
9337
3832
6741
1
7124
87358
1
5864
1
19454
1572
5537
9163
33672
2455
7112
45509
160346
4271
42529
44963
4750
4757
583
6653
4021
5769
32475
1
54782
28
5831
36632
2418
34629
5152
607
851
134633
8683
906
164
2960
1755
7908
5932
1703
6121
3190
2986...

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 1388ms
memory: 482040kb

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:

458
6875
14079
9549
18367
3627
3963
34502
3060
9459
760
13807
67710
486
18009
2649
13559
9409
19184
92
1909
9236
3698
9260
93287
71789
7376
1821
6959
6615
4200
2006
717
3605
2902
101545
9248
2296
772
1351
32232
3211
1725
26181
6056
1141
99
1979
3561
1790
25288
5169
8928
6980
16153
4965
9319
5632
884...

result:

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