QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457867#7408. Determinationkkkgjyismine4AC ✓78ms44796kbC++233.0kb2024-06-29 14:31:162024-06-29 14:31:18

Judging History

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

  • [2024-06-29 14:31:18]
  • 评测
  • 测评结果:AC
  • 用时:78ms
  • 内存:44796kb
  • [2024-06-29 14:31:16]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int mod=1e9+7;
int n,x,a[1000005],b[1000005],d[1000005],p[1000005];
int mul(int x,int y){return 1ll*x*y%mod;}
void add(int &x,const int y){x=((x+y>=mod)?(x+y-mod):(x+y));}
void sub(int &x,const int y){x=((x>=y)?(x-y):(x+mod-y));}
int qpow(int a,int b){int c=1;while(b){if(b&1)c=mul(c,a);a=mul(a,a),b>>=1;}return c;}
int dp0[1000005][2],dp1[1000005][2],dp2[1000005],dp3[1000005];
vector<int>son[1000005];
int pos[1000005],tt,Pre[1000005],Suf[1000005];
int Pre1[1000005],Suf1[1000005],Pre3[1000005],Pre2[1000005];
void dfs(int u){
	for(int v:son[u])dfs(v);
	tt=0;for(int v:son[u])pos[++tt]=v;
	Pre[0]=Suf[tt+1]=1,Pre1[0]=Suf1[tt+1]=Pre3[0]=Pre2[0]=0;
	for(int i=1;i<=tt;++i){
		Pre[i]=mul(Pre[i-1],dp0[pos[i]][0]);
		Pre1[i]=mul(Pre1[i-1],dp0[pos[i]][0]);
		add(Pre1[i],mul(Pre[i-1],dp0[pos[i]][1]));
		Pre2[i]=mul(Pre2[i-1],dp0[pos[i]][0]);
		add(Pre2[i],mul(Pre[i-1],dp2[pos[i]]));
		Pre3[i]=mul(Pre3[i-1],dp0[pos[i]][0]);
		add(Pre3[i],mul(Pre[i-1],dp3[pos[i]]));
	}
	for(int i=tt;i>=1;--i){
		Suf[i]=mul(Suf[i+1],dp0[pos[i]][0]);
		Suf1[i]=mul(Suf1[i+1],dp0[pos[i]][0]);
		add(Suf1[i],mul(Suf[i+1],dp0[pos[i]][1]));
	}
	for(int i=1;i<=tt;++i)sub(dp2[u],mul(mul(Pre[i-1],Suf[i+1]),mul(dp2[pos[i]],a[u])));
	sub(dp2[u],mul(Pre[tt],mul(a[u],x)));
	for(int i=1;i<=tt;++i)sub(dp3[u],mul(mul(Pre[i-1],Suf[i+1]),mul(dp3[pos[i]],b[u])));
	sub(dp3[u],mul(Pre[tt],mul(b[u],mod-1)));
	sub(dp1[u][0],mul(Pre[tt],mul(a[u],b[u])));
	sub(dp1[u][1],mul(Pre1[tt],mul(a[u],b[u])));
	add(dp0[u][0],mul(Pre[tt],d[u]));
	add(dp0[u][1],mul(Pre1[tt],d[u]));
	for(int i=1;i<=tt;++i){
		sub(dp0[u][1],mul(mul(Pre[i-1],Suf[i+1]),mul(dp2[pos[i]],mod-1)));
		sub(dp0[u][1],mul(mul(Pre[i-1],Suf[i+1]),mul(dp3[pos[i]],x)));
		sub(dp0[u][1],mul(mul(Pre2[i-1],Suf[i+1]),dp3[pos[i]]));
		sub(dp0[u][1],mul(mul(Pre3[i-1],Suf[i+1]),dp2[pos[i]]));
		add(dp0[u][0],mul(mul(Pre[i-1],Suf[i+1]),dp1[pos[i]][0]));
		add(dp0[u][1],mul(mul(Pre1[i-1],Suf[i+1]),dp1[pos[i]][0]));
		add(dp0[u][1],mul(mul(Pre[i-1],Suf1[i+1]),dp1[pos[i]][0]));
		add(dp0[u][1],mul(mul(Pre[i-1],Suf[i+1]),dp1[pos[i]][1]));
	}
	sub(dp0[u][1],mul(Pre[tt],mul(x,mod-1)));
}
#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++
static char buf[4999999], *p1 = buf, *p2 = buf;
template <typename item>
inline void read (register item &x) {
    x = 0;
	register char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
}
void Solve(){
	read(n),read(x);
    for(int i=1;i<=n;++i)read(d[i]),son[i].clear(),dp0[i][0]=dp0[i][1]=dp1[i][0]=dp1[i][1]=dp2[i]=dp3[i]=0,sub(d[i],x);
    for(int i=2;i<=n;++i)read(p[i]),son[p[i]].pb(i),read(a[i]),read(b[i]),sub(a[i],x),sub(b[i],x);
    dfs(1);
    int Ans=(dp0[1][0]+dp0[1][1])%mod;
    printf("%d\n",Ans);
}
int main(){
    int T;read(T);
    while(T--)Solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 30500kb

input:

3
1 23333
233
3 1
1 1 1
1 2 3
1 4 5
3 1
2 3 4
1 4 5
2 6 7

output:

233
1000000003
999999923

result:

ok 3 number(s): "233 1000000003 999999923"

Test #2:

score: 0
Accepted
time: 29ms
memory: 36748kb

input:

50000
8 322029253
0 4 1 8 2 4 2 6
1 944501012 390210770
2 901049174 103930626
3 865552309 989846658
4 894181655 586868306
2 819783208 393532481
6 617853941 785991126
2 81883211 919505569
7 896017220
5 2 2 5 7 3 5
1 747310272 809584267
1 964602148 156726243
3 521346132 229656100
4 339712528 807083254...

output:

893730422
483416679
342207915
920873059
524089509
108600148
721905386
693724156
0
656093789
115754096
952068870
4763325
491819045
462132613
583197708
172001791
75064925
801503521
574255413
1
139934658
345655944
1
924917560
893397792
180825552
462095536
834751349
0
155357829
959870186
931007058
74975...

result:

ok 50000 numbers

Test #3:

score: 0
Accepted
time: 33ms
memory: 36616kb

input:

10000
20 417928751
7 20 5 10 9 4 11 5 8 14 20 14 19 9 9 5 2 13 16 16
1 246012051 845046632
2 878206210 172823749
3 596946432 371394289
4 855428639 42242311
5 678116881 216114219
6 535520433 559716942
7 928247714 879420522
3 426313119 41822492
3 196764084 955364345
10 657969071 672811242
11 61608462 ...

output:

959802172
592287010
386441239
297628121
270526170
0
186902841
141185616
344380654
262510553
587371331
923004846
237179330
597985983
940117339
929273059
673033590
786375091
33426817
836134405
523964235
699928451
213769945
765611025
415523272
71961300
521533440
71878121
328532869
452875047
212693270
3...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 63ms
memory: 36612kb

input:

1000
500 116577666
298 40 233 432 134 336 454 132 44 64 306 479 462 12 225 288 469 242 476 301 226 90 472 161 71 233 177 462 28 342 399 74 325 464 416 437 395 180 488 301 332 13 363 191 49 449 27 250 425 266 445 1 417 140 227 15 330 202 186 329 485 1 428 374 273 429 499 117 135 86 48 313 322 487 94 ...

output:

792757685
537648250
411399271
388479732
780329295
231541023
38673017
231993453
92004369
260677552
334929743
45907885
535101207
577641396
534025986
800825347
879304606
285193391
630962050
799345990
474303441
500288833
969665494
511345820
718938177
350411949
270447438
896689392
302934073
748649165
851...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 64ms
memory: 35024kb

input:

100
5000 335485864
4993 3896 1960 4219 4039 2389 848 924 4941 1481 3655 4466 2267 4199 3070 2211 3905 906 4537 3817 1985 1630 3505 3452 3165 3117 1240 2031 4308 2338 3006 46 4157 2874 4571 2015 3612 2614 3009 1956 4006 1791 3749 1676 2078 2148 1430 2646 1422 1076 2434 3340 4740 3415 946 2477 4139 43...

output:

283583649
41376005
384604690
776462611
42116502
362646119
115791389
92532395
65615808
452194100
117478683
894182054
758507547
457170243
476482964
485026600
978457042
254231640
459141728
567893950
828048808
777462292
797903831
23461565
94801356
284378484
912331310
193963994
407990425
88789174
9231791...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 78ms
memory: 41560kb

input:

10
50000 979157048
30831 7235 48062 47019 45185 13985 7914 44966 24970 48772 30513 47847 1239 39613 19510 46926 45005 9590 20725 48679 47686 31929 44334 21972 30471 20521 26585 36084 17690 47558 37747 11795 32788 18341 15732 12264 34156 13744 14865 34025 16205 42075 35086 26188 11905 16377 2930 3789...

output:

919183218
656928200
750733624
279711857
639469284
83130523
850458730
71814732
935197454
916369964

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 16ms
memory: 44796kb

input:

1
100000 858322795
74782 23852 98221 29367 86515 29145 94299 20578 6705 80732 13336 18168 32350 56520 15219 58255 58827 21882 36366 41694 9361 88175 13816 48765 75217 49218 22205 84763 76257 44852 62590 33437 2514 52565 58832 98120 12755 71417 58471 34434 31950 91634 69463 22900 47720 61681 69823 83...

output:

779591986

result:

ok 1 number(s): "779591986"

Test #8:

score: 0
Accepted
time: 7ms
memory: 42956kb

input:

1
100000 950692852
92165 98121 74914 94156 93098 22723 75727 65576 6703 91861 49394 27789 62397 78641 29283 82550 77082 13360 20434 35158 78035 45005 78457 42687 72577 94172 9677 92534 14864 40466 75413 18411 49311 28436 49267 56953 55532 16322 8063 32745 29330 82830 3345 23731 24075 64826 98321 466...

output:

665862715

result:

ok 1 number(s): "665862715"

Extra Test:

score: 0
Extra Test Passed