QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864914#9905. 哈夫曼树Mathew_Miao0 360ms9424kbC++202.0kb2025-01-21 11:09:342025-01-21 11:09:35

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 11:09:35]
  • 评测
  • 测评结果:0
  • 用时:360ms
  • 内存:9424kb
  • [2025-01-21 11:09:34]
  • 提交

answer

#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<numeric>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5+10;
const int N=1e5;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
int n,q;
long long a[MAXN<<1];
int f[MAXN<<1];
int ls[MAXN<<1],rs[MAXN<<1];
#define pii pair<long long,long long>
multiset <pii> s;
long long cnt=0;
#define calc(x,y) ((y).first<=(x).second)
inline void add(pii x){
	auto it=s.insert(x);
	if(it!=s.begin()){
		cnt+=calc(*prev(it),x);
	}
	if(next(it)!=s.end()){
		cnt+=calc(x,*next(it));
	}
	if(it!=s.begin()&&next(it)!=s.end()){
		cnt-=calc(*prev(it),*next(it));
	}
}
inline void del(pii x){
	auto it=s.find(x);
	if(it!=s.begin()){
		cnt-=calc(*prev(it),x);
	}
	if(next(it)!=s.end()){
		cnt-=calc(x,*next(it));
	}
	if(it!=s.begin()&&next(it)!=s.end()){
		cnt+=calc(*prev(it),*next(it));
	}
	s.erase(it);
}
inline void mdf(int p,int v){
	for(int x=f[p];x;x=f[x])
	{
		long long l=a[ls[x]],r=a[rs[x]];
		if(l>r){
			swap(l,r);
		}
		del(pii(l,r-1));
	}
	a[p]=v;
	for(int x=f[p];x;x=f[x])
	{
		long long l=a[ls[x]],r=a[rs[x]];
		a[x]=l+r;
		if(l>r){
			swap(l,r);
		}
		add(pii(l,r-1));
	}
}
inline void solve(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=n+1;i<=n+n-1;i++)
	{
		scanf("%d%d",&ls[i],&rs[i]);
		f[ls[i]]=i;
		f[rs[i]]=i;
	}
	for(int i=n+1;i<=n+n-1;i++)
	{
		long long l=a[ls[i]],r=a[rs[i]];
		a[i]=l+r;
		if(l>r){
			swap(l,r);
		}
		add(pii(l,r-1));
	}
	puts(!cnt?"YES":"NO");
	while(--q)
	{
		int p,v;
		scanf("%d%d",&p,&v);
		mdf(p,v);
		puts(!cnt?"YES":"NO");
	}
}
signed main(){
	#ifdef LOCAL
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	atexit([](){fprintf(stderr,"%.3lfs\n",(double)clock()/CLOCKS_PER_SEC);});
	#endif
	solve();
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 30
Accepted
time: 1ms
memory: 5912kb

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: 3840kb

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
Wrong Answer
time: 0ms
memory: 5972kb

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:

YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

wrong answer expected YES, found NO [2nd token]

Subtask #2:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 37ms
memory: 6604kb

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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

wrong answer expected YES, found NO [97th token]

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 30
Accepted
time: 242ms
memory: 9424kb

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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 50000 token(s): yes count is 6146, no count is 43854

Test #21:

score: 0
Wrong Answer
time: 360ms
memory: 9384kb

input:

50000 50000
16115874901 16018205653 14928961193 15204162048 13699373395 16820637318 16493035276 12317462119 12335280079 14846384661 17397129601 13936553564 14115670390 10273255127 15120549487 18610914980 11122287472 11331160875 18972429908 12783865866 14407025341 18691310891 11400735942 15689404271 ...

output:

YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

wrong answer expected YES, found NO [49643rd token]

Subtask #4:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 314ms
memory: 5968kb

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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

wrong answer expected YES, found NO [6th token]