QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370551#4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》zsq14725836910 831ms285092kbC++173.8kb2024-03-29 10:58:142024-03-29 10:58:15

Judging History

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

  • [2024-03-29 10:58:15]
  • 评测
  • 测评结果:10
  • 用时:831ms
  • 内存:285092kb
  • [2024-03-29 10:58:14]
  • 提交

answer

#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+50;

namespace IO {
#define iL (1 << 20)
char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
#define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
template<class T> inline void read(T &x) {
  x = 0;int f = 0;char ch = gc();
  for (; !isdigit(ch); f |= ch == '-', ch = gc());
  for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
  x = (f == 1 ? ~ x + 1 : x);
}
template<class T, class... Args> inline void read(T &x, Args&... args) { read(x), read(args...); }
template<class T> inline void readch(T &x) { char ch = gc(); for (; !isalpha(ch); ch = gc()); x = ch; }
char Out[iL], *iter = Out;
#define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
template<class T> inline void write(T x, char ch = '\n') {
  T l, c[35];
  if (x < 0) *iter ++ = '-', x = ~ x + 1;
  for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
  for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
  flush();
}
template<class T, class... Args> inline void write(T x, Args... args) { write(x, ' '), write(args...); }
} // IO
using namespace IO;

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

int n,las,cnt,head[N],val[N],top[N],siz[N],son[N],dep[N],fa[N],p[N],cc,dfn[N],st[N>>1][20],q,lg[N],m,t[N];

void dfs1(int x,int f)
{
    fa[x]=f;dep[x]=dep[f]+1;siz[x]=1;
    for(int i=head[x];i;i=e[i].nxt)if(e[i].v!=f)
    {
        int v=e[i].v;
        dfs1(v,x);siz[x]+=siz[v];
        if(siz[v]>siz[son[x]])son[x]=v;
    }
}

void dfs2(int x,int topp)
{
    top[x]=topp;dfn[x]=++cc;p[cc]=x;
    if(!son[x])return;dfs2(son[x],topp);
    for(int i=head[x];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if(v==son[x]||v==fa[x])continue;
        dfs2(v,v);
    }
}

struct poi
{
    int l,r,w,pos;

    friend bool operator<(poi a,poi b)
    {
        return a.w<b.w;
    }
};

int chk(int a,int b)
{
    return val[p[a]]>val[p[b]]?a:b;
}

poi find(int l,int r)
{
    int k=lg[r-l+1]-1,u=chk(st[l][k],st[r-(1<<k)+1][k]);
    return (poi){l,r,val[p[u]],u};
}

priority_queue<poi>w;

void spl(poi x)
{
    if(x.pos>x.l)w.push(find(x.l,x.pos-1));
    if(x.pos<x.r)w.push(find(x.pos+1,x.r));
}

int fdw()
{
    if(w.empty())return 0;
    poi now=w.top();w.pop();spl(now);
    return now.w;
}

int cmp(int a,int b)
{
    return a>b;
}

void solve(int u,int v)
{
    int num=62*m,nd=0;
    while(top[u]!=top[v])
    {
        if(dep[top[u]]<dep[top[v]])swap(u,v);
        w.push((poi){find(dfn[top[u]],dfn[u])});
        u=fa[top[u]];
    }
    if(dep[u]<dep[v])swap(u,v);w.push((poi){find(dfn[v],dfn[u])});
    int ty=0;
    for(int i=62;i>=0;i--)
    {
        int f=0,cc=0;
        for(int j=1;j<=m;j++)
        {
            if(!ty)t[j]=fdw();
            if(!(t[j]&(1ll<<i)))
            {
                for(int k=1;k<=j;k++)w.push((poi){1,1,t[k]-(1ll<<i)*(k<j),1});
                f=2;break;
            }
            if((t[j]^nd)&nd){f=1;break;}
        }
        if(f==1)break;
        if(f==2)continue;
        nd|=(1ll<<i),ty=1;
    }
    write(las=nd);
    while(!w.empty())w.pop();
}

main()
{
    read(n);
    for(int i=1;i<n;i++)
    {
        int u,v;read(u,v);
        e[++cnt]=(node){u,v,head[u]};head[u]=cnt;
        e[++cnt]=(node){v,u,head[v]};head[v]=cnt;
    }
    for(int i=1;i<=n;i++)read(val[i]),lg[i]=lg[i>>1]+1;
    dfs1(1,1);dfs2(1,1);
    for(int i=1;i<=n;i++)st[i][0]=i;
    for(int i=1;i<20;i++)
    for(int j=1;j+(1<<i)-1<=n;j++)
    st[j][i]=chk(st[j][i-1],st[j+(1<<i-1)][i-1]);
    read(q);
    while(q--)
    {
        int u,v;read(u,v,m);
        u=((u^las)%n)+1;v=((v^las)%n)+1;
        solve(u,v);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 4020kb

input:

931
184 700
485 184
419 485
386 419
308 386
114 308
301 114
598 301
120 598
144 120
595 144
812 595
236 812
7 236
543 7
327 543
858 327
68 858
177 68
398 177
899 398
408 899
848 408
202 848
269 202
304 269
540 304
647 540
672 647
314 672
157 314
241 157
745 241
300 745
343 300
92 343
117 92
30 117
2...

output:

1152921504606846976

result:

ok 1 number(s): "1152921504606846976"

Test #2:

score: -5
Wrong Answer
time: 1ms
memory: 3992kb

input:

915
911 748
514 911
805 514
729 805
753 729
40 753
671 40
664 671
94 664
61 94
726 61
690 726
597 690
216 597
644 216
533 644
605 533
22 605
307 22
455 307
377 455
114 377
660 114
589 660
569 589
409 569
408 409
821 408
736 821
599 736
60 599
475 60
57 475
412 57
85 412
524 85
846 524
595 846
262 59...

output:

288230376151711744

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 16ms
memory: 37012kb

input:

99115
98506 98914
1961 98506
45808 1961
23027 45808
16655 23027
66393 16655
77250 66393
68284 77250
53684 68284
21189 53684
84955 21189
73464 84955
47574 73464
40651 47574
21101 40651
6589 21101
59680 6589
6185 59680
25529 6185
207 25529
33286 207
98459 33286
92565 98459
85446 92565
97388 85446
1630...

output:

2050

result:

ok 1 number(s): "2050"

Test #18:

score: 0
Accepted
time: 21ms
memory: 38176kb

input:

99546
79711 12863
50539 79711
13393 50539
27933 13393
13465 27933
79157 13465
53742 79157
51081 53742
32220 51081
21079 32220
85595 21079
50222 85595
14565 50222
4589 14565
13763 4589
58913 13763
93835 58913
34953 93835
2185 34953
10246 2185
64420 10246
44274 64420
63093 44274
8007 63093
85947 8007
...

output:

512

result:

ok 1 number(s): "512"

Test #19:

score: 0
Accepted
time: 25ms
memory: 38388kb

input:

99762
90013 76047
42293 90013
7801 42293
75274 7801
59320 75274
60896 59320
10435 60896
5384 10435
34648 5384
15596 34648
92041 15596
67457 92041
20760 67457
65611 20760
81462 65611
38984 81462
17583 38984
83787 17583
59980 83787
71477 59980
31143 71477
92168 31143
71205 92168
69348 71205
6111 69348...

output:

16386

result:

ok 1 number(s): "16386"

Test #20:

score: 0
Accepted
time: 20ms
memory: 35860kb

input:

99132
46469 40521
51811 46469
47968 51811
10584 47968
73 10584
27351 73
16693 27351
12495 16693
53425 12495
95973 53425
24901 95973
82771 24901
49155 82771
35995 49155
50432 35995
91209 50432
5781 91209
83457 5781
41361 83457
37973 41361
48829 37973
62896 48829
77593 62896
21307 77593
86547 21307
61...

output:

8194

result:

ok 1 number(s): "8194"

Test #21:

score: 0
Accepted
time: 29ms
memory: 37804kb

input:

99403
81802 91324
60321 81802
76749 60321
70097 76749
16085 70097
8301 16085
61886 8301
72994 61886
23906 72994
18815 23906
6781 18815
7774 6781
18318 7774
54769 18318
39330 54769
55677 39330
46758 55677
36164 46758
10159 36164
24678 10159
29603 24678
14941 29603
7966 14941
42934 7966
35909 42934
24...

output:

32770

result:

ok 1 number(s): "32770"

Test #22:

score: 0
Accepted
time: 18ms
memory: 37812kb

input:

99468
33859 68644
12306 33859
44304 12306
18200 44304
27325 18200
35907 27325
88149 35907
71599 88149
86384 71599
83793 86384
19513 83793
4843 19513
3007 4843
52878 3007
83019 52878
5275 83019
61517 5275
21453 61517
55993 21453
50710 55993
16211 50710
76061 16211
12048 76061
41970 12048
86181 41970
...

output:

514

result:

ok 1 number(s): "514"

Test #23:

score: 0
Accepted
time: 16ms
memory: 35780kb

input:

99179
45430 91876
8718 45430
75718 8718
15306 75718
21806 15306
78221 21806
74287 78221
66218 74287
66830 66218
64948 66830
16118 64948
33879 16118
81821 33879
69640 81821
27802 69640
25979 27802
6393 25979
63447 6393
48459 63447
53612 48459
27525 53612
52654 27525
80810 52654
767 80810
23808 767
82...

output:

32768

result:

ok 1 number(s): "32768"

Test #24:

score: 0
Accepted
time: 20ms
memory: 36044kb

input:

99240
8561 98467
49571 8561
13264 49571
94195 13264
85879 94195
53012 85879
29828 53012
25813 29828
57793 25813
10678 57793
88525 10678
70070 88525
54163 70070
51466 54163
3857 51466
77958 3857
29023 77958
154 29023
5173 154
4349 5173
24310 4349
21821 24310
36125 21821
75498 36125
7147 75498
22336 7...

output:

32770

result:

ok 1 number(s): "32770"

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Wrong Answer

Test #45:

score: 0
Wrong Answer
time: 831ms
memory: 285092kb

input:

996678
2 1
3 1
4 1
5 1
6 3
7 5
8 5
9 5
10 7
11 8
12 9
13 1
14 2
15 7
16 4
17 5
18 17
19 16
20 2
21 1
22 1
23 9
24 17
25 19
26 10
27 9
28 7
29 25
30 25
31 4
32 11
33 31
34 21
35 13
36 19
37 25
38 10
39 11
40 20
41 35
42 1
43 19
44 20
45 41
46 1
47 19
48 5
49 28
50 21
51 33
52 7
53 14
54 21
55 20
56 1...

output:

4
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
8
0
0
0
0
16
0
0
4096
0
0
0
0
4096
0
0
0
0
2
0
0
0
0
4
0
0
0
0
32
64
0
0
0
512
64
4
4096
0
2
0
0
131072
0
0
0
0
0
0
0
0
2
0
0
0
2
0
4096
2
0
0
0
0
0
512
2
8
0
0
4096
64
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
512
0
0
36
0
0
0
0
0
0
0
64
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

wrong answer 16449th numbers differ - expected: '4102', found: '4096'

Subtask #8:

score: 0
Skipped

Dependency #1:

0%