QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369727 | #4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》 | dengtingyu | 0 | 1160ms | 469340kb | C++14 | 2.4kb | 2024-03-28 17:06:40 | 2024-03-28 17:06:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1000100
ll n,q;vector<ll>e[N];ll a[N];
ll dfn[N],siz[N],son[N],top[N],dep[N],fa[N];ll dfncnt=0;
inline void dfs(ll x,ll faa){
fa[x]=faa;dep[x]=dep[faa]+1;siz[x]=1;
for(auto o:e[x]){
if(o==faa)continue;
dfs(o,x);siz[x]+=siz[o];
if(siz[o]>siz[son[x]])son[x]=o;
}return ;
}
inline void dfs1(ll x,ll tp){
dfn[x]=++dfncnt;top[x]=tp;
if(son[x]){
dfs1(son[x],tp);
}for(auto o:e[x]){
if(!dfn[o])dfs1(o,o);
}return ;
}
#define V 21000100
ll fir[N<<2],nxt[V],val[V];ll cnt=0;
inline void add(ll x,ll y){val[++cnt]=y;nxt[cnt]=fir[x];fir[x]=cnt;return ;}
inline void upd(ll o,ll l,ll r,ll x,ll y){
add(o,y);if(l==r)return ;
ll mid=(l+r)>>1;
if(mid>=x)upd(o<<1,l,mid,x,y);
else upd(o<<1|1,mid+1,r,x,y);
return ;
}
ll p[N];inline bool cmp(ll x,ll y){return a[x]>a[y];}
vector<ll>hs,rc;
inline void ask(ll o,ll l,ll r,ll x,ll y){
if(x<=l&&r<=y){hs.emplace_back(fir[o]);return ;}
ll mid=(l+r)>>1;
if(mid>=x)ask(o<<1,l,mid,x,y);
if(mid<y)ask(o<<1|1,mid+1,r,x,y);
return ;
}
inline ll ask(ll x,ll y,ll z){
hs.clear();rc.clear();while(top[x]!=top[y]){
if(dep[top[x]]<dep[top[y]])swap(x,y);
ask(1,1,n,dfn[top[x]],dfn[x]);x=fa[top[x]];
}if(dep[x]>dep[y])swap(x,y);ask(1,1,n,dfn[x],dfn[y]);
ll an=0;for(int i=62;i>=0;i--){
ll cn=0;for(auto o:hs){
while(((val[o]&an)==an)&&((val[o]>>i)&1)>0){cn++;if(cn>=z)break;o=nxt[o];}if(cn>=z)break;
}for(auto o:rc){if(((val[o]&an)==an)&&((val[o]>>i)&1)>0)cn++;if(cn>=z)break;}
if(cn>=z){an+=(1ll<<i);continue;}
for(auto &o:hs){while(((val[o]&an)==an)&&((val[o]>>i)&1)>0)rc.emplace_back(o),o=nxt[o];}
}return an;
}
int main(){
// freopen("test1.in","r",stdin);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;for(int i=1;i<n;i++){
ll u,v;cin>>u>>v;e[u].push_back(v);e[v].push_back(u);
}for(int i=1;i<=n;i++)cin>>a[i];
dfs(1,0);dfs1(1,1);
for(int i=1;i<=n;i++)p[i]=i;sort(p+1,p+n+1,cmp);
for(int i=1;i<=n;i++)upd(1,1,n,dfn[p[i]],a[p[i]]);
cin>>q;ll las=0;for(int i=1;i<=q;i++){
ll x,y,z;cin>>x>>y>>z;x=(x^las)%n+1;y=(y^las)%n+1;
cout<<(las=ask(x,y,z))<<'\n';
}return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 28356kb
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:
0
result:
wrong answer 1st numbers differ - expected: '1152921504606846976', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 43ms
memory: 73868kb
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:
0
result:
wrong answer 1st numbers differ - expected: '2050', found: '0'
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: 1160ms
memory: 469340kb
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 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 64 0 0 0 0 64 0 0 0 0 0 0 0 0 0 4 0 0 0 0 32 64 0 0 0 512 0 0 64 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 4 0 0 0 0 0 0 512 2 0 0 0 512 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 64 0 0 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '4', found: '0'
Subtask #8:
score: 0
Skipped
Dependency #1:
0%