QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572297 | #8222. 投票游戏 | zjy0001 | 0 | 50ms | 42724kb | C++17 | 4.2kb | 2024-09-18 13:32:43 | 2024-09-18 13:32:43 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=2e5+5;
const LL INF=1e16;
int n,q,tim;
vector<int>G[N];
int a[N],b[N];LL sb[N];
int f[N],top[N],sz[N],son[N],dL[N],dR[N],rk[N],rt[N];
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct node{
LL p,l,r;
node(const LL&_p=0,const LL&_l=0,const LL&_r=0):
p(_p),l(_l),r(_r){}
inline LL operator()(const LL&x)const{
return x<p?l:r;
}
inline node operator+(const node&o)const{
return node(o.p,(o.l<p?l:r),(o.r<p?l:r));
}
}A[N],S[N*4];
struct Node{
LL v,a,mn,s;int pri;
inline void init(LL _v,LL _a){
v=_v,a=_a,mn=v,s=a,pri=rng();
}
}T[N];
int Ls[N],Rs[N];
inline void pushup(int p){
T[p].s=T[Ls[p]].s+T[p].a+T[Rs[p]].s;
T[p].mn=min(min(T[Ls[p]].mn,T[Ls[p]].s+T[p].v),T[Ls[p]].s+T[p].a+T[Rs[p]].mn);
}
inline int merge(int x,int y){
if(!x||!y)return x|y;
if(T[x].pri>T[y].pri)return Rs[x]=merge(Rs[x],y),pushup(x),x;
else return Ls[y]=merge(x,Ls[y]),pushup(y),y;
}
inline void split(int x,LL k,int r,int&p,int&q){
if(!x)return p=0,q=0,void();
if(T[x].v>k||(T[x].v==k&&x>r))p=x,split(Rs[x],k,r,Rs[p],q),pushup(p);
else q=x,split(Ls[x],k,r,p,Ls[q]),pushup(q);
}
inline LL qry(int rt,LL x){
if(!rt)return x;
if(x>T[Ls[rt]].mn)return qry(Ls[rt],x);
if(x>T[Ls[rt]].s+T[rt].v)return x-T[Ls[rt]].s;
return qry(Rs[rt],x-T[Ls[rt]].s-T[Ls[rt]].a);
}
inline void ins(int &rt,int x){
int p,q;split(rt,T[x].v,x,p,q);
rt=merge(p,merge(x,q));
}
inline void del(int &rt,int x){
int p,q;split(rt,T[x].v,x,p,q),split(p,T[x].v,x-1,p,rt);
rt=merge(p,q);
}
inline void build(int p,int l,int r){
if(l==r)return S[p]=A[rk[l]],void();
const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
build(ls,l,mid),build(rs,mid+1,r);
S[p]=S[ls]+S[rs];
}
inline void upd(int p,int l,int r,int x){
if(l==r)return S[p]=A[rk[l]],void();
const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
x<=mid?upd(ls,l,mid,x):upd(rs,mid+1,r,x);
S[p]=S[ls]+S[rs];
}
inline node qry(int p,int l,int r,int x){
if(x<=l)return S[p];
const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
return x<=mid?qry(ls,l,mid,x)+qry(rs,mid+1,r,x):qry(rs,mid+1,r,x);
}
inline void dfs1(int u,int fa){
sz[u]=1,son[u]=0,f[u]=fa;
for(auto v:G[u])if(v!=fa)
dfs1(v,u),sz[u]+=sz[v],sb[u]+=b[v],
sz[son[u]]<sz[v]?son[u]=v:0;
for(auto v:G[u])if(v!=son[u])
T[v].init(A[v](0),b[v]),ins(rt[u],v);
if(son[u]){
auto x=qry(rt[u],sb[u]+a[u]);
auto y=qry(rt[u],sb[u]+a[u]-sb[son[u]]);
A[u]=node(x,x,y);
}
else A[u]=node(0,a[u],a[u]);
}
inline void dfs2(int u,int fa,int tp){
dL[u]=++tim;
if(son[u])dfs2(son[u],u,tp);
for(auto v:G[u])if(v!=fa&&v!=son[u])dfs2(v,u,v);
dR[u]=tim;
}
inline void upd(int u){
for(int i=u;;i=f[top[i]]){
if(son[i]){
auto x=qry(rt[i],sb[i]+a[i]);
auto y=qry(rt[i],sb[i]+a[i]-sb[son[i]]);
A[i]=node(x,x,y);
}
else A[i]=node(0,a[i],a[i]);
upd(1,1,n,dL[i]);
if(!f[top[i]])break;
del(rt[f[top[i]]],top[i]);
T[top[i]].init(qry(1,1,n,dL[top[i]])(0),b[top[i]]);
ins(rt[f[top[i]]],top[i]);
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
T[0].init(-INF,0);
cin>>n>>q;
for(int i=2;i<=n;++i)
cin>>f[i],G[f[i]].emplace_back(i);
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=n;++i)cin>>b[i];
dfs1(1,0),dfs2(1,0,1),build(1,1,n);
for(int i=1;i<=q;++i){
int o;cin>>o;
if(o==1){
int u,x,y;cin>>u>>x>>y;
a[u]=x,y-=b[u],b[u]+=y,sb[f[u]]+=y;
upd(u);
if(f[u]){
if(u!=son[f[u]]){
del(rt[f[u]],u);
T[u].init(qry(1,1,n,dL[u])(0),b[u]);
ins(rt[f[u]],u);
}
upd(f[u]);
}
}
else{
int u,v;cin>>u>>v;
cout<<(qry(1,1,n,dL[u])(0)>qry(1,1,n,dL[v])(0))<<'\n';
}
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 0
Memory Limit Exceeded
input:
20 500 1 1 3 1 3 5 6 6 7 3 5 3 9 5 4 7 7 18 2 42129194 82765784 1447057 29726963 82321558 32094641 22474113 49277574 27527633 20746795 47630926 92888389 26787144 80703040 43876864 97991729 12117966 75633318 33577855 93462601 69163546 49621952 45236756 46447931 34085269 55246550 54414402 99593046 103...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #13:
score: 0
Time Limit Exceeded
input:
200 200000 1 2 3 3 5 3 1 6 2 9 11 5 5 2 4 9 17 8 1 4 10 20 18 20 23 13 16 28 15 4 6 27 26 11 30 25 10 2 13 23 25 35 4 8 40 43 36 26 7 27 45 35 14 31 54 45 9 8 9 54 16 32 62 9 29 2 43 39 34 39 27 2 52 56 6 9 48 26 66 28 35 57 79 13 71 61 38 43 80 26 61 26 79 1 24 64 79 15 41 42 56 55 6 24 92 43 89 76...
output:
result:
Subtask #4:
score: 0
Memory Limit Exceeded
Test #18:
score: 0
Memory Limit Exceeded
input:
200 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
result:
Subtask #5:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 50ms
memory: 42724kb
input:
200 200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...
output:
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 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 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 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 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: '1', found: '0'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%