QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#331649 | #4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》 | JohnAlfnov | 0 | 32ms | 117256kb | C++14 | 2.4kb | 2024-02-18 16:23:11 | 2024-02-18 16:23:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int>g[1000005];
long long v[1000005];
int fa[1000005],dep[1000005],sz[1000005];
int ffa[1000005],bg[1000005],tot=0;
void dfs1(int x,int la){
sz[x]=1;
for(auto cu:g[x]){
if(cu==la)continue;
dep[cu]=dep[x]+1;
fa[cu]=x;
dfs1(cu,x);
sz[x]+=sz[cu];
}
}
void dfs2(int x,int la){
bg[x]=++tot;
if(sz[x]==1)return;
int ans=0,w=0;
for(auto cu:g[x]){
if(cu==la)continue;
if(ans<sz[cu])ans=sz[cu],w=cu;
}
ffa[w]=ffa[x];dfs2(w,x);
for(auto cu:g[x]){
if(cu==la||cu==w)continue;
ffa[cu]=cu;dfs2(cu,x);
}
}
long long vv[21][1000005];
int wz[21][1000005],lg[1000005];
struct apple{
int l,r,wz;
long long zz;
bool operator<(const apple &other)const{
return zz<other.zz;
}
};
priority_queue<apple>pq;
void jiaq(int l,int r){
if(l>r)return;
int cd=lg[r-l+1];
apple ap;ap.l=l,ap.r=r;
if(vv[cd][l]>vv[cd][r-(1<<cd)+1])ap.wz=wz[cd][l],ap.zz=vv[cd][l];
else ap.wz=wz[cd][r-(1<<cd)+1],ap.zz=vv[cd][r-(1<<cd)+1];
pq.emplace(ap);
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<n;++i){
int u,v;
scanf("%d%d",&u,&v);
g[u].emplace_back(v);
g[v].emplace_back(u);
}
for(int i=1;i<=n;++i)scanf("%lld",&v[i]);
dfs1(1,0);ffa[1]=1;dfs2(1,0);
for(int i=1;i<=n;++i)vv[0][bg[i]]=v[i],wz[0][bg[i]]=bg[i];
for(int i=1;i<=19;++i)for(int j=1;j<=n-(1<<i)+1;++j){
if(vv[i-1][j]>vv[i-1][j+(1<<(i-1))])vv[i][j]=vv[i-1][j],wz[i][j]=wz[i-1][j];
else vv[i][j]=vv[i-1][j+(1<<(i-1))],wz[i][j]=wz[i-1][j+(1<<(i-1))];
}
lg[1]=0;
for(int i=2;i<=n;++i)lg[i]=lg[i>>1]+1;
int q;
long long lastans=0;
scanf("%d",&q);
while(q--){
long long xx,yy;
int k;
scanf("%lld%lld%d",&xx,&yy,&k);
int x=xx^lastans,y=yy^lastans;
int gs=0;
while(pq.size())pq.pop();
while(ffa[x]!=ffa[y]){
if(dep[ffa[x]]<dep[ffa[y]])swap(x,y);
jiaq(bg[ffa[x]],bg[x]);gs+=bg[x]-bg[ffa[x]]+1;
x=fa[ffa[x]];
}
if(dep[x]<dep[y])swap(x,y);
jiaq(bg[y],bg[x]);gs+=bg[x]-bg[y]+1;
if(gs<k){
printf("%lld\n",lastans=0);
continue;
}
int kk=min(gs,62*k-61);
vector<long long>vc;
while(kk--){
auto au=pq.top();pq.pop();
vc.emplace_back(au.zz);
jiaq(au.l,au.wz-1);jiaq(au.wz+1,au.r);
}
lastans=0;
for(int i=61;i>=0;--i){
int gg=0;
for(auto cu:vc)if((cu&lastans)==lastans)
gg+=(cu>>i)&1;
if(gg>=k)lastans|=1ll<<i;
}
printf("%lld\n",lastans);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 78124kb
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:
36028797018963968
result:
wrong answer 1st numbers differ - expected: '1152921504606846976', found: '36028797018963968'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 32ms
memory: 117256kb
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:
32
result:
wrong answer 1st numbers differ - expected: '2050', found: '32'
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
Runtime Error
Test #45:
score: 0
Runtime Error
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:
0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 2 0 0 4100 0 0 0 0 256 0 64 0 0 0 0 0 0 0 2 0 0 0 0 4096 4096 0 0 2 512 2 0 4096 0 0 0 0 512 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 256 0 4 0 0 512 0 0 2 0 32 0 0 0 0 0 0 2 2 0 0 0 0 0 4 512 0 0 64 0 0 0 0 0 0 0 2 8 0 0 0 2 0 4 0 0 2 0 0 0 0 0 0 0 0 8...
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
0%