QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370553#4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》zsq1472583690 836ms285032kbC++173.8kb2024-03-29 10:59:042024-03-29 10:59:04

Judging History

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

  • [2024-03-29 10:59:04]
  • 评测
  • 测评结果:0
  • 用时:836ms
  • 内存:285032kb
  • [2024-03-29 10:59:04]
  • 提交

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;
        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;ty=0;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: 4012kb

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: 3932kb

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: 0
Wrong Answer

Test #17:

score: 10
Accepted
time: 21ms
memory: 37000kb

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: 22ms
memory: 38272kb

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: -10
Wrong Answer
time: 21ms
memory: 38436kb

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:

16384

result:

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

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: 836ms
memory: 285032kb

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 411th numbers differ - expected: '16386', found: '16384'

Subtask #8:

score: 0
Skipped

Dependency #1:

0%