QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#845748 | #9905. 哈夫曼树 | nullptr_qwq | 0 | 0ms | 16004kb | C++14 | 2.4kb | 2025-01-06 18:53:58 | 2025-01-06 18:54:00 |
Judging History
answer
// 私は猫です
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,NR=500005,V=80;
int minn[NR][90],maxn[NR][90];
int n,q;
int a[NR];
int son[NR][2];
int rt;
int v[NR];
int dep[NR];
int father[NR];
int ans;
int vis[NR];
inline void change(int x){
if(x<=n){minn[x][dep[x]]=maxn[x][dep[x]]=v[x];return;}
int s1,s2;s1=son[x][0],s2=son[x][1];
ans-=vis[x];vis[x]=0;
if(v[s1]>v[s2]) swap(s1,s2);
int fl=0;
F(i,dep[x]+1,V){
int v1=maxn[s1][i],v2=minn[s2][i];
if(v1>v2) fl=1;
maxn[x][i]=max(maxn[s1][i],maxn[s2][i]);
minn[x][i]=min(minn[s1][i],minn[s2][i]);
}
vis[x]=fl;ans+=vis[x];
v[x]=v[s1]+v[s2];maxn[x][dep[x]]=minn[x][dep[x]]=v[x];
}
inline void dfs(int x,int fa){
dep[x]=dep[fa]+1;father[x]=fa;
F(i,0,1) if(son[x][i]) dfs(son[x][i],x);
}
inline void out(){
if(ans) puts("NO");
else {
F(i,1,V-1) if(minn[rt][i]<maxn[rt][i+1]) {puts("NO");return;}
puts("YES");
}
}
void solve(){
cin>>n>>q;
F(i,1,n)cin>>a[i],v[i]=a[i];
F(i,n+1,2*n-1)cin>>son[i][0]>>son[i][1];
rt=2*n-1,dfs(rt,0);
int Max=0;
F(i,1,2*n-1) Max=max(Max,dep[i]);
if(Max>=75){
F(i,1,q) puts("NO");
return;
}
F(i,1,2*n-1) F(j,0,V) maxn[i][j]=0,minn[i][j]=inf;
F(i,1,2*n-1) change(i);
out();
--q;
while(q--){
int x,k; cin>>x>>k;
v[x]=k;
while(1){
change(x);
if(x==rt) break;
x=father[x];
}
out();
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int zsy=1;
F(____,1,zsy)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 30
Accepted
time: 0ms
memory: 15948kb
input:
3 4 1 1 1 2 3 1 4 2 2 1 2 3 3
output:
YES NO YES NO
result:
ok 4 token(s): yes count is 2, no count is 2
Test #2:
score: 30
Accepted
time: 0ms
memory: 16004kb
input:
8 5 5 3 4 2 2 6 5 5 1 8 4 5 10 3 11 9 7 2 6 13 14 12 7 3 6 8 4 2 2 5
output:
NO YES YES YES NO
result:
ok 5 token(s): yes count is 3, no count is 2
Test #3:
score: 0
Runtime Error
input:
5 1000 193989534544158 57483670601746 183281373434588 92196008024549 197513473286508 1 5 4 2 7 3 8 6 2 65545142774024 4 67957472319495 5 131478473459166 2 102185858570152 3 191441353035940 5 186000528093501 2 63201184033501 2 77481806092413 3 159789430863849 4 92773786021894 1 194598667478593 3 1458...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #16:
score: 0
Runtime Error
input:
10000 10000 85117964119 41472951000 61693640396 66409648221 91978532661 62922448518 92497200794 43837348258 45577855926 38256001396 79446271832 95289903258 62510175551 97599809584 56162244722 87617641117 64010325734 56604859803 58544571483 40687963085 38627694508 64665875035 62273927372 73014847094 ...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #20:
score: 0
Runtime Error
input:
50000 50000 16394396247 17456058492 11358090355 13208121167 8612535629 2853817504 18100755237 18603321637 1618810635 7615832530 13631222424 7817630977 10963098997 19654927084 645638016 9352759139 17939720223 15106346489 14475376391 2122412099 15482023637 11224675857 15931143509 4240408932 1270948838...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #24:
score: 0
Runtime Error
input:
70 100000 66748 126 1 91045172 3605661959574 274077743637349 147314183 8209537 740253 6920630855 25494 1377240316614 15756 6 108000 18118446805 169389361127761 29316262755 48 2643445763 5834083602536 3 9439745562111 29 3719 10 47434709561 11197815949 6018 325122336074 851181326345 1633739329 1527382...