QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#305342 | #4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》 | fireince | 0 | 962ms | 330724kb | C++14 | 4.6kb | 2024-01-15 07:22:58 | 2024-01-15 07:22:59 |
Judging History
answer
#include<iostream>
#include<cassert>
#include<queue>
#include<array>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
const int N=1e6+10,K=63;
int n;
vector<int> G[N];
ll val[N];
typedef vector<ll> Dat;
namespace IO{
#define BUF_SIZE (1<<16)
#define OUT_SIZE (1<<16)
bool IOerror=0;
inline char nc(){static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;if(p1==pend){p1=buf;pend=buf+fread(buf,1,BUF_SIZE,stdin);if(pend==p1)return IOerror=1,-1;}return *p1++;}
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline void read(int &x){bool sign=0;char ch=nc();x=0;for(;blank(ch);ch=nc());if(IOerror)return;if(ch=='-')sign=1,ch=nc();for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';if(sign)x=-x;}
inline void read(ll &x){bool sign=0;char ch=nc();x=0;for(;blank(ch);ch=nc());if(IOerror)return;if(ch=='-')sign=1,ch=nc();for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';if(sign)x=-x;}
struct Ostream_fwrite{
char *buf,*p1,*pend;
Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;}
inline void out(char ch){if(p1==pend){fwrite(buf,1,BUF_SIZE,stdout);p1=buf;}*p1++=ch;}
inline void print(ll x){static char s[25],*s1;s1=s;if(!x)*s1++='0';if(x<0)out('-'),x=-x;while(x)*s1++=x%10+'0',x/=10;while(s1--!=s)out(*s1);}
inline void println(ll x){print(x);out('\n');}
inline void flush(){if(p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}}
~Ostream_fwrite(){flush();}
}Ostream;
inline void print(ll x){Ostream.print(x);}
inline void println(ll x){Ostream.println(x);}
inline void println(){Ostream.out('\n');}
inline void flush(){Ostream.flush();}
#undef OUT_SIZE
#undef BUF_SIZE
}using namespace IO;
const int H=20
;
ll f[H][N];
int fp[H][N];
struct DS{
void build(int n,ll* a){
for(int i=1;i<=n;i++)f[0][i]=a[i],fp[0][i]=i;
for(int i=1;i<H;i++)
for(int j=1;j+(1<<i)-1<=n;j++)
f[i][j]=max(f[i-1][j],f[i-1][j+(1<<i-1)]),
fp[i][j]=f[i-1][j]>f[i-1][j+(1<<i-1)]?fp[i-1][j]:fp[i-1][j+(1<<i-1)];
}
pii query(int l,int r){
if(l>r)return {0,0};
int len=r-l+1,h=__lg(len);
ll v=max(f[h][l],f[h][r-(1<<h)+1]);
int p=v==f[h][l]?fp[h][l]:fp[h][r];
return {v,p};
}
} ds;
int dfn[N],top[N],dcnt,siz[N],son[N],fa[N],dep[N];
ll arr[N];
void dfs1(int u,int f){
fa[u]=f,dep[u]=dep[f]+1,siz[u]=1;
for(int v:G[u]){
if(v==f)continue;
dfs1(v,u);
siz[u]+=siz[v];
if(siz[son[u]]<siz[v])son[u]=v;
}
}
void dfs2(int u,int tp){
top[u]=tp,dfn[u]=++dcnt,arr[dfn[u]]=val[u];
if(son[u])dfs2(son[u],tp);
for(int v:G[u]){
if(v==son[u]||v==fa[u])continue;
dfs2(v,v);
}
}
typedef array<ll,4> rg;
struct cmp{
bool operator()(const rg& a,const rg& b) const{
return a[0]<b[0];
}
};
typedef priority_queue<rg,vector<rg>,cmp> pqt;
void insertRange(int l,int r,pqt& pq){
auto res=ds.query(l,r);
pq.push({res.first,res.second,l,r});
};
Dat queryPoints(int u,int v,int m){
Dat res;
pqt pq;
while(top[u]!=top[v]){
if(dep[top[u]]<dep[top[v]])swap(u,v);
insertRange(dfn[top[u]],dfn[u],pq);
u=fa[top[u]];
}
if(dep[u]<dep[v])swap(u,v);
insertRange(dfn[v],dfn[u],pq);
while(pq.size()&&res.size()<m){
auto a=pq.top();
pq.pop();
res.push_back(a[0]);
if(a[1]!=a[2])insertRange(a[2],a[1]-1,pq);
if(a[1]!=a[3])insertRange(a[1]+1,a[3],pq);
}
return res;
}
ll queryVal(Dat& dt,int m){
ll ans=0;
for(int i=K;i>=0;i--){
int cnt=0;
Dat ndt;
for(ll j:dt)if(j>>i&1)cnt++,ndt.push_back(j);
if(cnt>=m){
ans|=(1ll<<i);
dt=ndt;
}
}
return ans;
}
signed main(){
read(n);
for(int i=1;i<n;i++){
int u,v;
read(u),read(v);
G[u].push_back(v);
G[v].push_back(u);
}
for(int i=1;i<=n;i++)read(val[i]);
dfs1(1,0);
dfs2(1,1);
ds.build(n,arr);
int q;
read(q);
ll lastans=0;
for(int i=1;i<=q;i++){
int u,v,m;
read(u),read(v),read(m);
u=(u^lastans)%n+1,v=(v^lastans)%n+1;
Dat dt=queryPoints(u,v,K*min(3,m-1));
if(dt.size()<m){
lastans=0;
}else lastans=queryVal(dt,m);
println(lastans);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 79320kb
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:
1152921504609206292
result:
wrong answer 1st numbers differ - expected: '1152921504606846976', found: '1152921504609206292'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #17:
score: 10
Accepted
time: 21ms
memory: 139940kb
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: 23ms
memory: 139288kb
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: 19ms
memory: 144236kb
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: 27ms
memory: 138376kb
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: 36ms
memory: 140884kb
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: -10
Wrong Answer
time: 12ms
memory: 140772kb
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:
1026
result:
wrong answer 1st numbers differ - expected: '514', found: '1026'
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: 962ms
memory: 330724kb
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 64 0 2560 256 0 0 1125899906842880 2048 0 16 2 32 4096 0 10 0 0 16 0 0 1152921504606912516 0 20 0 4 64 2048 0 0 2 0 1032 1152921504606846976 0 0 4 0 128 20 256 512 256 0 0 0 512 1152921504606846976 64 4096 0 256 0 10 4096 16 0 2048 0 0 0 2 16 8 0 0 0 66 0 4096 1152921504678150272 5764607...
result:
wrong answer 7th numbers differ - expected: '0', found: '64'
Subtask #8:
score: 0
Skipped
Dependency #1:
0%