QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370891 | #4909. 《关于因为与去年互测zjk撞题而不得不改题这回事》 | 2745518585 | 0 | 1504ms | 336004kb | C++20 | 3.3kb | 2024-03-29 18:52:26 | 2024-03-29 18:52:28 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1000001,M=31;
int n,m,tot,e[N];
ll b[N];
vector<int> a[N];
namespace ST
{
int lg[N];
ll a[N][M];
int max(int x,int y)
{
return b[x]>b[y]?x:y;
}
void init()
{
for(int i=1;i<=n;++i) a[i][0]=e[i];
for(int i=0;i<=20;++i)
{
for(int j=(1<<i);j<=min(1<<(i+1)-1,n);++j) lg[j]=i;
}
for(int i=1;i<=20;++i)
{
for(int j=1;j<=n;++j)
{
if(j+(1<<i)-1<=n) a[j][i]=max(a[j][i-1],a[j+(1<<(i-1))][i-1]);
}
}
}
int sum(int x,int y)
{
if(x>y) swap(x,y);
return max(a[x][lg[y-x]],a[y-(1<<lg[y-x])+1][lg[y-x]]);
}
}
struct tree
{
int f,s,d,t,z,b;
}T[N];
struct str
{
int x,y,t;
str() {}
str(int x,int y):x(x),y(y),t(ST::sum(T[x].b,T[y].b)) {}
friend bool operator<(str x,str y)
{
return b[x.t]<b[y.t];
}
};
priority_queue<str> Q1;
priority_queue<int> Q2;
void dfs1(int x)
{
T[x].s=1;
T[x].d=T[T[x].f].d+1;
for(auto i:a[x])
{
if(i==T[x].f) continue;
T[i].f=x;
dfs1(i);
T[x].s+=T[i].s;
if(T[i].s>T[T[x].z].s) T[x].z=i;
}
}
void dfs2(int x,int t)
{
T[x].b=++tot;
T[x].t=t;
if(T[x].z) dfs2(T[x].z,t);
for(auto i:a[x])
{
if(i==T[x].f||i==T[x].z) continue;
dfs2(i,i);
}
}
void add(int x,int y)
{
Q1.push(str(x,y));
Q2.push(b[ST::sum(T[x].b,T[y].b)]);
}
void solve(int x,int y)
{
while(T[x].t!=T[y].t)
{
if(T[T[x].t].d>T[T[y].t].d)
{
add(T[x].t,x);
x=T[T[x].t].f;
}
else
{
add(T[y].t,y);
y=T[T[y].t].f;
}
}
add(x,y);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n-1;++i)
{
int x,y;
scanf("%d%d",&x,&y);
a[x].push_back(y);
a[y].push_back(x);
}
for(int i=1;i<=n;++i)
{
scanf("%lld",&b[i]);
}
dfs1(1);
dfs2(1,1);
for(int i=1;i<=n;++i) e[T[i].b]=i;
ST::init();
scanf("%d",&m);
ll las=0;
for(int i=1;i<=m;++i)
{
int x,y,k;
scanf("%d%d%d",&x,&y,&k);
x=(x^las)%n+1,y=(y^las)%n+1;
while(!Q1.empty()) Q1.pop();
while(!Q2.empty()) Q2.pop();
solve(x,y);
while(!Q1.empty()&&Q2.size()<k*62)
{
auto [x,y,t]=Q1.top();
Q1.pop();
if(T[x].d>T[y].d) swap(x,y);
if(T[x].d<T[t].d) add(x,T[t].f);
if(T[t].d<T[y].d) add(T[t].z,y);
}
while(Q2.size()<k) Q2.push(0);
ll s=0;
for(int i=62;i>=0;--i)
{
static ll z[11];
for(int j=1;j<=k;++j) z[j]=Q2.top(),Q2.pop();
if((z[k]&(1ll<<i))!=0)
{
s|=(1ll<<i);
for(int j=1;j<=k;++j) Q2.push(z[j]);
}
else
{
for(int j=1;j<=k;++j) Q2.push(z[j]&(~(1ll<<i)));
}
}
printf("%lld\n",las=s);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 6180kb
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:
1073741824
result:
wrong answer 1st numbers differ - expected: '1152921504606846976', found: '1073741824'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 45ms
memory: 46444kb
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:
4
result:
wrong answer 1st numbers differ - expected: '2050', found: '4'
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: 1504ms
memory: 336004kb
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 1467th numbers differ - expected: '4294967298', found: '512'
Subtask #8:
score: 0
Skipped
Dependency #1:
0%