QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317344#4889. 愚蠢的在线法官JohnAlfnov3 304ms47452kbC++201.1kb2024-01-28 21:17:132024-01-28 21:17:14

Judging History

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

  • [2024-01-28 21:17:14]
  • 评测
  • 测评结果:3
  • 用时:304ms
  • 内存:47452kb
  • [2024-01-28 21:17:13]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int n,k;
int vv[500005],v[500005],a[500005],cnt[500005];
vector<int>g[500005];
int bg[500005],gb[500005],tot=0;
int fa[500005];
void dfs1(int x,int la){
	bg[x]=++tot,gb[bg[x]]=x;
	v[bg[x]]=vv[x];
	for(auto cu:g[x]){
		if(cu==la)continue;
		fa[cu]=x;dfs1(cu,x);
	}
}
int c[500005];
void add(int x,int s){
	while(x<=n){
		c[x]+=s;
		x+=x&-x;
	}
}
int query(int x){
	int ans=0;
	while(x){
		ans+=c[x];
		x-=x&-x;
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%d",&vv[i]);
	for(int i=1;i<=k;++i){
		scanf("%d",&a[i]);++cnt[a[i]];
	}
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	for(int i=1;i<=n;++i)if(cnt[i]>1){
		puts("0");
		return 0;
	}
	dfs1(1,0);
	for(int i=1;i<=k;++i)a[i]=bg[a[i]];
	int gs=1;
	for(int i=k;i>=1;--i){
		if(query(a[i])&1)gs*=-1;
		add(a[i],1);
	}
	for(int i=1;i<=n;++i)gs=1ll*gs*(vv[i]-vv[fa[i]])%mod;
	gs=(gs+mod)%mod;
	printf("%d\n",gs);
	return 0;
}

詳細信息

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 239ms
memory: 39512kb

input:

499999 500000
879485015 176694934 629415436 677018935 33186863 696674214 19586946 878479076 318116264 823399347 140314195 715329843 996129441 446979068 600062488 847953138 978347569 865596472 147980317 199880680 187953368 989585254 457868128 466175307 381871948 369138343 826894839 963935318 36550896...

output:

0

result:

ok 1 number(s): "0"

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 14152kb

input:

10 1
663730929 273617752 74933376 562874267 346105266 779139305 198742356 291012786 227170675 127136999
2
10 8
5 10
1 5
9 8
6 10
4 6
3 1
2 4
7 3

output:

966816158

result:

wrong answer 1st numbers differ - expected: '273617752', found: '966816158'

Subtask #3:

score: 0
Wrong Answer

Test #43:

score: 0
Wrong Answer
time: 261ms
memory: 47408kb

input:

500000 600
375999961 486674339 753591626 263678997 153496902 843204506 294273913 59353025 80121537 938426018 309354784 359915003 480316315 880954496 544396164 478808641 583197144 202111021 277512785 193266475 511298159 750302398 30978705 278891583 701736665 516664158 47658598 456194527 517690925 870...

output:

390107236

result:

wrong answer 1st numbers differ - expected: '739558267', found: '390107236'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 304ms
memory: 47452kb

input:

500000 500000
200910665 704700912 664276 824905098 512233060 623259142 478040808 509760810 756074623 387351466 261683363 140331101 135736712 184881987 425557684 61914673 951508934 787260914 386285199 40458274 175322609 429002885 606957721 742057849 342942076 104844271 656874266 826513447 76400873 55...

output:

226748033

result:

wrong answer 1st numbers differ - expected: '771496320', found: '226748033'

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #3:

0%