QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554217 | #8222. 投票游戏 | 275307894a | 0 | 547ms | 118024kb | C++14 | 4.4kb | 2024-09-09 08:41:53 | 2024-09-09 08:41:53 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*60+5,K=1e7+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=3e13+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,q,fa[N],A[N],B[N];
vector<int> S[N];
int d[N],tp[N],ed[N],siz[N],son[N],id[N],ih;
void dfs1(int x,int La){
d[x]=d[La]+1;siz[x]=1;
for(int i:S[x]) dfs1(i,x),siz[x]+=siz[i],siz[i]>siz[son[x]]&&(son[x]=i);
}
void dfs2(int x,int La){
tp[x]=La;id[x]=++ih;ed[tp[x]]=ih;if(son[x]) dfs2(son[x],La);
for(int i:S[x]) if(i^son[x]) dfs2(i,i);
}
namespace DS1{
int cnt,L[M],R[M];
ll sum[M],mi[M];
int rt[N],st[M],sh;
void up(int v,ll l,ll r){
ll m=l+r>>1;
sum[v]=(L[v]?sum[L[v]]:-(m-l+1))+(R[v]?sum[R[v]]:-(r-m));
mi[v]=min((L[v]?mi[L[v]]:-(m-l+1))+(R[v]?sum[R[v]]:-(r-m)),R[v]?mi[R[v]]:-(r-m));
}
void clr(int &v){
L[v]=R[v]=sum[v]=mi[v]=0;
st[++sh]=v;v=0;
}
void modify(ll x,ll y,int &v,ll l=-1,ll r=INF){
if(!v) v=(sh?st[sh--]:++cnt),sum[v]=mi[v]=-(r-l+1);
if(l==r){
sum[v]+=y;mi[v]+=y;
return;
}
ll m=l+r>>1;x<=m?modify(x,y,L[v],l,m):modify(x,y,R[v],m+1,r);up(v,l,r);
if(sum[v]==r-l+1&&l>=0) clr(v);
}
void add(int p,ll x,ll y){
modify(x,y,rt[p]);
}
ll find(ll x,int v,ll l=-1,ll r=INF){
if(l==r) return l;
if(!v) return r-x+1;
ll m=l+r>>1;
return x+(R[v]?mi[R[v]]:-(r-m))>0?find(x+(R[v]?sum[R[v]]:-(r-m)),L[v],l,m):find(x,R[v],m+1,r);
}
ll qry(int p,ll x){
return find(INF-x,rt[p]);
}
}
struct node{
ll x,A,B;
ll calc(ll y)const{return y<x?A:B;}
};
node operator +(const node &A,const node &B){
return (node){A.x,B.calc(A.A),B.calc(A.B)};
}
namespace DS2{
#define ls v<<1
#define rs v<<1|1
node f[M];
void up(int v){f[v]=f[rs]+f[ls];}
void modify(int x,node y,int l=1,int r=n,int v=1){
if(l==r){f[v]=y;return;}int m=l+r>>1;
x<=m?modify(x,y,l,m,ls):modify(x,y,m+1,r,rs);up(v);
}
node qry(int x,int y,int l=1,int r=n,int v=1){
if(x<=l&&r<=y) return f[v];int m=l+r>>1;
if(y<=m) return qry(x,y,l,m,ls);
if(x>m) return qry(x,y,m+1,r,rs);
return qry(x,y,m+1,r,rs)+qry(x,y,l,m,ls);
}
#undef ls
#undef rs
}
ll dp[N],sum[N];
ll qry(int x){
return DS2::qry(id[x],ed[tp[x]]).A;
}
void remake(int x){
ll w=DS1::qry(x,sum[x]);
if(!son[x]){
DS2::modify(id[x],(node){INF,w,0});
}else{
DS1::add(x,w,B[son[x]]);
DS2::modify(id[x],(node){w,w,DS1::qry(x,sum[x])});
DS1::add(x,w,-B[son[x]]);
}
}
void make(int x,int La){
DS1::add(x,-1,0);sum[x]=A[x];
for(int i:S[x]){
make(i,x);
if(i^son[x]) DS1::add(x,dp[i],B[i]);
sum[x]+=B[i];
}
remake(x);
dp[x]=qry(x);
gdb(x,dp[x]);
}
void modify(int p,int x,int y){
sum[p]-=A[p];A[p]=x;sum[p]+=A[p];
remake(p);
if(p^1){
sum[fa[p]]-=B[p];
if(tp[p]==p){
DS1::add(fa[p],dp[p],-B[p]);
}
}
B[p]=y;
dp[p]=qry(p);
if(p^1){
sum[fa[p]]+=B[p];
if(tp[p]==p){
DS1::add(fa[p],dp[p],B[p]);
}
}
if(p==1) return;
p=fa[p];remake(p);
while(p){
p=tp[p];
if(p^1) DS1::add(fa[p],dp[p],-B[p]);
dp[p]=qry(p);
if(p^1) DS1::add(fa[p],dp[p],B[p]),remake(fa[p]);
p=fa[p];
}
}
void Solve(){
scanf("%d%d",&n,&q);
for(int i=2;i<=n;i++) scanf("%d",&fa[i]),S[fa[i]].push_back(i);
dfs1(1,0);
dfs2(1,1);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
for(int i=1;i<=n;i++) scanf("%d",&B[i]);
make(1,0);
while(q--){
int op,p,x,y;
scanf("%d",&op);
if(op==1) scanf("%d%d%d",&p,&x,&y),modify(p,x,y);
else{
scanf("%d%d",&x,&y);
printf("%d\n",make_pair(qry(x),x)<make_pair(qry(y),y));
}
}
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 20644kb
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:
0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 1 ...
result:
ok 238 numbers
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 18416kb
input:
20 500 1 1 3 1 3 5 3 4 2 4 3 12 6 7 12 6 4 11 10 2 0 2 1 1 1 2 0 2 2 1 0 0 2 1 0 1 0 1 1 0 0 2 0 0 0 1 2 2 2 0 2 2 2 1 0 1 0 1 1 2 5 2 1 6 1 0 1 7 1 1 2 5 11 2 18 16 2 13 7 2 4 3 1 6 0 0 1 5 0 2 2 16 12 2 5 18 2 8 16 1 4 0 0 2 5 2 1 19 2 2 1 10 0 0 1 15 2 2 2 12 14 1 12 1 1 1 13 1 2 1 3 2 2 1 6 2 2 ...
output:
0 1 0 1 1 1 1 1 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 0 1 0 1 0 1 ...
result:
wrong answer 80th numbers differ - expected: '0', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 499ms
memory: 20576kb
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:
0 0 0 0 1 1 1 1 1 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 0 1 1 1 1 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 0 1 0 0 ...
result:
wrong answer 87th numbers differ - expected: '1', found: '0'
Subtask #4:
score: 0
Runtime Error
Test #18:
score: 25
Accepted
time: 270ms
memory: 16452kb
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 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1 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 1 0 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 0 ...
result:
ok 99886 numbers
Test #22:
score: 0
Runtime Error
input:
200000 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 ...
output:
1 1 0 1 1 0 1 0 0 0 0 1 0 1 1 1 1 1 0 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 1 0 1 0 ...
result:
Subtask #5:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 284ms
memory: 16568kb
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:
1 0 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 0 0 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 ...
result:
wrong answer 13th numbers differ - expected: '0', found: '1'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%