QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402740 | #4401. Prize | sichengzhou | Compile Error | / | / | C++14 | 3.0kb | 2024-05-01 11:58:50 | 2024-05-01 11:58:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+6;
int n,K,Q,T,dfn[N];
bool cmp(const int x,const int y)
{
return dfn[x]<dfn[y];
}
struct Tree{
int number;
int p[N],rt;
int fa[N][20];
struct Edge{
int v,nxt;
}e[N];
int h[N],tot1;
void addEdge(int u,int v)
{
tot1++;
e[tot1].v=v;e[tot1].nxt=h[u];
h[u]=tot1;
}
void input()
{
for(int i=1;i<=n;i++)
{
scanf("%d",&p[i]);
if(p[i]>=1)addEdge(p[i],i),fa[i][0]=p[i];
else rt=i,fa[i][0]=0;
}
}
int dfn[N],idx,dep[N],rnk[N];
void dfs(int u)
{
dfn[u]=++idx;rnk[idx]=u;
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].v;dep[v]=dep[u]+1;
dfs(v);
}
}
int a[N];
LL d[N];
int lca(int u,int v)
{
if(dep[u]<dep[v])
{
swap(u,v);
}
for(int j=19;j>=0;j--)
{
if(dep[u]-dep[v]>>j&1)
{
u=fa[u][j];
}
}
if(u==v)
{
return u;
}
for(int j=19;j>=0;j--)
{
if(fa[u][j]!=fa[v][j])
{
u=fa[u][j];
v=fa[v][j];
}
}
return fa[u][0];
}
void init()
{
dfs(rt);
for(int j=1;j<=19;j++)
{
for(int i=1;i<=n;i++)
{
fa[i][j]=fa[fa[i][j-1]][j-1];
}
}
for(int i=1;i<=K;i++)
{
a[i]=i;
}
int tp=0;
for(int i=1;i<=n;i++)
{
if(rnk[i]<=K)
{
a[++tp]=rnk[i];
}
}
for(int i=1;i<K;i++)
{
printf("? %d %d\n",a[i],a[i+1]);
}
}
void work()
{
d[a[1]]=0;
for(int i=1;i<K;i++)
{
LL X,Y,Z,W;
scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W);
int x=lca(a[i],a[i+1]);
if(number==1)
{
d[x]=d[a[i]]-X;
d[a[i+1]]=d[x]+Y;
}else{
d[x]=d[a[i]]-Z;
d[a[i+1]]=d[x]+W;
}
}
cout<<number<<endl;
}
LL query(int u,int v)
{
return d[u]+d[v]-2*d[lca(u,v)];
}
}t1,t2;
int main()
{
int u,v;
scanf("%d%d%d%d",&n,&K,&Q,&T);
t1.number=1;t2.number=2;
t1.input();t2.input();
for(int i=1;i<=K;i++)
{
printf("%d ",i);
}
printf("\n");
fflush(stdout);
t1.init();t2.init();
fflush(stdout);
t1.work();t2.work();
for(int i=1;i<=T;i++)
{
scanf("%d%d",&u[i],&v[i]);
}
for(int i=1;i<=T;i++)
{
printf("%lld %lld\n",t1.query(u[i],v[i]),t2.query(u[i],v[i]));
}
fflush(stdout);
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:140:24: error: invalid types ‘int[int]’ for array subscript 140 | scanf("%d%d",&u[i],&v[i]); | ^ answer.code:140:30: error: invalid types ‘int[int]’ for array subscript 140 | scanf("%d%d",&u[i],&v[i]); | ^ answer.code:144:40: error: invalid types ‘int[int]’ for array subscript 144 | printf("%lld %lld\n",t1.query(u[i],v[i]),t2.query(u[i],v[i])); | ^ answer.code:144:45: error: invalid types ‘int[int]’ for array subscript 144 | printf("%lld %lld\n",t1.query(u[i],v[i]),t2.query(u[i],v[i])); | ^ answer.code:144:60: error: invalid types ‘int[int]’ for array subscript 144 | printf("%lld %lld\n",t1.query(u[i],v[i]),t2.query(u[i],v[i])); | ^ answer.code:144:65: error: invalid types ‘int[int]’ for array subscript 144 | printf("%lld %lld\n",t1.query(u[i],v[i]),t2.query(u[i],v[i])); | ^ answer.code:126:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 126 | scanf("%d%d%d%d",&n,&K,&Q,&T); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ answer.code: In member function ‘void Tree::input()’: answer.code:28:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d",&p[i]); | ~~~~~^~~~~~~~~~~~ answer.code: In member function ‘void Tree::work()’: answer.code:105:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 105 | scanf("%lld%lld%lld%lld",&X,&Y,&Z,&W); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~