QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#333944 | #4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》 | fangzichang | 10 | 58ms | 79688kb | C++17 | 3.2kb | 2024-02-20 20:43:57 | 2024-02-20 20:43:58 |
Judging History
answer
#include<bits/extc++.h>
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
//本代码含有小众情感元素,建议满 18 周岁后观看
#ifdef __unix__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#else
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif
#define debug fprintf(stderr,"Tomoyo after ~It's a wonderful life!~\n")
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define Inf (int)INFINITY
#define inf 0x3f3f3f3f
#define int long long
#define pb push_back
#define ll long long
#define endl '\n'
#define y second
#define x first
using namespace std;
const int N=1e6+10,T=200;
void read(){};
template<class T1,class ...T2>
inline void read(T1& ret,T2&... rest){
ret=0;char c=getchar();bool f=false;
while(c<'0'||c>'9')f=c=='-',c=getchar();
while(c>='0'&&c<='9')ret=ret*10+c-'0',c=getchar();
f&&(ret=-ret),read(rest...);
}
#define cin(...) read(__VA_ARGS__)
template<class T>
inline void print(T x){
static int s[35],t=0;
bool f=x<0;if(f)x=-x;
do s[t++]=x%10,x/=10;while(x);
f&&putchar('-');while(t)putchar(s[--t]+'0');
}
vector<int>nxt[N];
int n,q,cnt,a[N],tmp[N],dep[N],dfn[N],top[N],fa[N],hvy[N],sz[N];
void dfs1(int u){sz[u]=1;for(int v:nxt[u])if(v^fa[u])dep[v]=dep[fa[v]=u]+1,dfs1(v),sz[u]+=sz[v],(sz[v]>sz[hvy[u]]&&(hvy[u]=v));}
void dfs2(int u,int tp){top[u]=tp,dfn[u]=++cnt,(hvy[u]&&(dfs2(hvy[u],tp),1));for(int v:nxt[u])if(v!=fa[u]&&v!=hvy[u])dfs2(v,v);}
template<int N>
struct ST{
#define k lg[r-l+1]
int st[N][__lg(N)+1],idx[N][__lg(N)+1],lg[N];
void init(int*a,int n){
lg[0]=-1;
for(int i=1;i<=n;i++)lg[i]=lg[i/2]+1;
for(int i=1;i<=n;i++)st[i][0]=a[idx[i][0]=i];
for(int j=1;j<=lg[n];j++)
for(int i=1;i+(1<<j)-1<=n;i++){
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
idx[i][j]=(st[i][j]==st[i][j-1]?idx[i][j-1]:idx[i+(1<<(j-1))][j-1]);
}
}
int ask(int l,int r){return max(st[l][k],st[r-(1<<k)+1][k]);}
int askid(int l,int r){return st[l][k]>st[r-(1<<k)+1][k]?idx[l][k]:idx[r-(1<<k)+1][k];}
#undef k
};ST<N>st;
struct Node{int l,r,i;bool operator<(const Node&n)const{return tmp[i]<tmp[n.i];}};
signed main(){
cin(n);for(int i=1,u,v;i<n;i++)cin(u,v),nxt[u].pb(v),nxt[v].pb(u);
dfs1(1),dfs2(1,1);for(int i=1;i<=n;i++)cin(a[i]),tmp[dfn[i]]=a[i];
st.init(tmp,n),cin(q);
for(int u,v,m,res=0;q;q--){
cin(u,v,m),u=(u^res)%n+1,v=(v^res)%n+1,res=0;
priority_queue<Node>pq;vector<int>val,t;
for(;top[u]^top[v];u=fa[top[u]]){
if(dep[top[u]]<dep[top[v]])swap(u,v);
pq.push({dfn[top[u]],dfn[u],st.askid(dfn[top[u]],dfn[u])});
}
if(dep[u]<dep[v])swap(u,v);
pq.push({dfn[v],dfn[u],st.askid(dfn[v],dfn[u])});
for(Node p;!pq.empty()&&(int)val.size()<T;){
val.pb(tmp[(p=pq.top()).i]),pq.pop();
if(p.l<p.i)pq.push({p.l,p.i-1,st.askid(p.l,p.i-1)});
if(p.i<p.r)pq.push({p.i+1,p.r,st.askid(p.i+1,p.r)});
}
// for(int v:val)cerr<<v<<" ";
// cerr<<endl;
if((int)val.size()<m){puts("0");continue;}
for(int i=61;~i;i--,t.clear()){
for(int v:val)if((v>>i)&1)t.pb(v);else break;
if((int)t.size()>=m)res|=(1<<i),val=t;
for(int&v:val)if((v>>i)&1)v-=(1<<i);
sort(all(val),greater<int>());
}
print(res),putchar(endl);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 27540kb
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:
-1
result:
wrong answer 1st numbers differ - expected: '1152921504606846976', found: '-1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 10
Accepted
Test #17:
score: 10
Accepted
time: 58ms
memory: 77168kb
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: 44ms
memory: 79412kb
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: 43ms
memory: 79688kb
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: 43ms
memory: 74776kb
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: 43ms
memory: 78672kb
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: 41ms
memory: 78676kb
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: 47ms
memory: 74504kb
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: 39ms
memory: 74744kb
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
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:
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 0 0 0 0 0 8 2 0 0 0 32 64 0 0 0 512 152556 2 4096 0 4 0 0 131072 0 0 0 0 0 0 0 0 2 0 0 0 0 0 4096 0 0 0 0 0 0 512 2 8 0 0 0 32 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 ...
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
0%