QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#821129 | #9905. 哈夫曼树 | jryggs | 0 | 395ms | 207156kb | C++14 | 3.2kb | 2024-12-19 13:37:15 | 2024-12-19 13:37:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const long long inf=1e18;
inline long long read(){
long long x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
bool qwqa;
int n,m,son[N][2],deg[N],rt,mxdep,d[N],fa[N],cp[N],tot,tim[N];
long long a[N];
struct node{
long long w1,w2;
int l,r;
inline bool operator<(node b){
if(w1^b.w1)return w1>b.w1;
return w2>b.w2;
}
};
vector<node>v;
inline void dfs(int x){
mxdep=max(mxdep,d[x]);
if(son[x][0])d[son[x][0]]=d[x]+1,fa[son[x][0]]=x,cp[son[x][0]]=son[x][1],dfs(son[x][0]),a[x]+=a[son[x][0]];
if(son[x][1])d[son[x][1]]=d[x]+1,fa[son[x][1]]=x,cp[son[x][1]]=son[x][0],dfs(son[x][1]),a[x]+=a[son[x][1]];
}
struct tree{
int l,r,vis;
long long minn,tag;
}t[N<<2];
#define mid (t[p].l+t[p].r>>1)
inline void build(int p,int l,int r){
t[p].l=l,t[p].r=r;t[p].vis=1;t[p].minn=inf;t[p].tag=inf;
if(l==r)return;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
}
inline void up(int p){
t[p].minn=min(t[p<<1].minn,t[p<<1|1].minn);
t[p].vis=t[p<<1].vis|t[p<<1|1].vis;
}
inline void cg(int p,long long v){
if(t[p].vis){
t[p].tag=v;t[p].minn=v;
}
}
inline void spread(int p){
if(t[p].tag<inf){
cg(p<<1,t[p].tag);cg(p<<1|1,t[p].tag);
t[p].tag=inf;
}
}
inline void change(int p,int l,int r,long long v){
if(l<=t[p].l&&t[p].r<=r){
cg(p,v);
return;
}
spread(p);
if(l<=mid)change(p<<1,l,r,v);
if(r>mid)change(p<<1|1,l,r,v);
up(p);
}
inline void qqq(int p,int l,int r,long long v){
if(t[p].minn>=v)return;
if(t[p].l==t[p].r){
t[p].vis=0;
t[p].minn=t[p].tag=inf;
return;
}
spread(p);
if(l<=mid)qqq(p<<1,l,r,v);
if(r>mid)qqq(p<<1|1,l,r,v);
up(p);
}
inline void tdfs(int p){
if(t[p].l==t[p].r){
if(t[p].vis)printf("YES\n");
else printf("NO\n");
return;
}
tdfs(p<<1),tdfs(p<<1|1);
}
bool qwqb;
int main(){
// cerr<<(&qwqa-&qwqb)/1024/1024;
n=read(),m=read();
for(int i = 1;i<=n;i++)a[i]=read();
for(int i = n+1;i<2*n;i++){
son[i][0]=read(),son[i][1]=read();
deg[son[i][0]]++,deg[son[i][1]]++;
}
for(int i = 1;i<2*n;i++)if(!deg[i])rt=i;
dfs(rt);
if(mxdep>75){
for(int i = 1;i<=m;i++)printf("NO\n");
return 0;
}
for(int i = 1;i<2*n;i++)tim[i]=1;
for(int i = 2;i<=m;i++){
int w=read(),now=w;
long long val=read()-a[w];
if(val==0)continue;
while(now!=rt){
v.push_back({a[now],a[cp[now]],tim[now],i-1});
v.push_back({a[cp[now]],a[now],tim[cp[now]],i-1});
tim[now]=tim[cp[now]]=i;
a[now]+=val;
now=fa[now];
}
}
for(int i = 1;i<2*n;i++){
if(rt!=i)v.push_back({a[i],a[cp[i]],tim[i],m});
}
sort(v.begin(),v.end());
build(1,1,m);
// for(auto[w1,w2,l,r]:v){
// qqq(1,l,r,w1);
// change(1,l,r,w2);
// // if(l==1)cerr<<"!"<<w1<<' '<<w2<<endl;
// }
tdfs(1);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9816kb
input:
3 4 1 1 1 2 3 1 4 2 2 1 2 3 3
output:
YES YES YES YES
result:
wrong answer expected NO, found YES [2nd token]
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 56ms
memory: 33096kb
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:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
wrong answer expected NO, found YES [5th token]
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 335ms
memory: 110288kb
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:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
wrong answer expected NO, found YES [2nd token]
Subtask #4:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 395ms
memory: 207156kb
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...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES ...
result:
wrong answer expected NO, found YES [154th token]