QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#873995#7578. Salty FishCarroT1212WA 819ms106488kbC++141.6kb2025-01-27 11:13:042025-01-27 11:13:04

Judging History

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

  • [2025-01-27 11:13:04]
  • 评测
  • 测评结果:WA
  • 用时:819ms
  • 内存:106488kb
  • [2025-01-27 11:13:04]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=3e5+7;
ll n,m,fa[N],a[N],sum,ans;
ll hl[N],ls[N],dep[N];
map<ll,ll> mp[N];
vector<ll> e[N];
vector<pll> qv[N];
void dfs(ll p,ll f) {
	hl[p]=ls[p]=0,dep[p]=dep[f]+1;
	for (ll i:e[p]) if (i!=f) {
		dfs(i,p);
		if (!ls[p]||hl[i]>hl[ls[p]]) ls[p]=i,hl[p]=hl[i]+1;
	}
}
void dfs1(ll p,ll f) {
	if (ls[p]) {
		dfs1(ls[p],p);
		mp[p].swap(mp[ls[p]]);
		for (ll i:e[p]) if (i!=f&&i!=ls[p]) {
			dfs1(i,p);
			for (pll j:mp[i]) mp[p][j.fi]+=j.se;
		}
		mp[p][dep[p]]+=a[p];
		for (pll o:qv[p]) {
			ll k=o.fi,w=o.se; auto it=mp[p].begin();
			while (it=mp[p].upper_bound(dep[p]+k),it!=mp[p].begin()) {
				it--;
				ll x=it->fi,y=it->se,z=min(y,w);
				y-=z,w-=z,ans+=z,mp[p][x]-=z;
				if (!y) mp[p].erase(x);
				if (!w) break;
			}
		}
	}
	else mp[p][dep[p]]=a[p];
//	printf("%lld\n",p);
//	for (pll i:mp[p]) printf("%lld %lld | ",i.fi,i.se); printf("\n");
}
void mian() {
	scanf("%lld%lld",&n,&m),sum=ans=0;
	for (ll i=1;i<=n;i++) e[i].clear(),qv[i].clear(),mp[i].clear();
	for (ll i=2;i<=n;i++) scanf("%lld",&fa[i]),e[fa[i]].pb(i);
	for (ll i=1;i<=n;i++) scanf("%lld",&a[i]),sum+=a[i];
	for (ll i=1,x,k,c;i<=m;i++) scanf("%lld%lld%lld",&x,&k,&c),qv[x].pb({k,c});
	dfs(1,0),dfs1(1,0);
	cout<<sum-ans<<"\n"; 
}
bool ORY; int main() {
	// while (1)
	 int t; for (scanf("%d",&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 42064kb

input:

1
6 3
1 1 2 2 3
2 5 4 3 3 2
2 1 3
3 1 7
1 2 4

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: -100
Wrong Answer
time: 819ms
memory: 106488kb

input:

1003
100 100
1 2 3 4 5 6 7 8 9 10 6 1 2 4 1 11 17 14 17 2 13 8 8 5 11 7 18 6 2 10 23 11 13 3 9 1 33 20 3 9 32 35 11 41 42 29 33 45 21 35 9 36 12 54 19 24 57 31 32 5 3 10 46 15 46 48 20 44 5 41 67 7 18 30 27 6 29 69 57 75 62 74 18 64 17 21 38 60 79 69 54 90 83 83 31 96 31 93 53
152 498 653 559 287 38...

output:

27738
25802
22176
29988
26224
28254
32852
28914
29304
23834
27985
33221
22342
18539
30687
29976
29981
26380
34783
24995
37641
25562
32021
29930
24750
30948
28215
31867
27569
34780
24455
31129
32929
25911
22580
26284
31975
33709
21462
18723
25414
17346
24817
36146
30191
29339
24837
35491
33041
28376
...

result:

wrong answer 1st numbers differ - expected: '20180', found: '27738'