QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#225807#7408. DeterminationCrysflyAC ✓62ms63764kbC++174.1kb2023-10-25 09:30:492023-10-25 09:30:49

Judging History

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

  • [2023-10-25 09:30:49]
  • 评测
  • 测评结果:AC
  • 用时:62ms
  • 内存:63764kb
  • [2023-10-25 09:30:49]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define mod 1000000007
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 1000005
#define inf 0x3f3f3f3f

//boring tree dp.
//f[u][0]:已处理完u子树内的边,u子树内无X路径,u需要选与父亲相连的那条双向边(即两条单向边都选上)
//f[u][1]:已处理完u子树内的边,u子树内无X路径,u不能选与父亲相连的那条双向边
//f[u][2]:已处理完u子树内的边,u子树包含完整的X路径,u需要选与父亲相连的那条双向边
//f[u][3]:已处理完u子树内的边,u子树包含完整的X路径,u不能选与父亲相连的那条双向边
//f[u][4]:已处理完u子树内的边,X路径的终点在u子树内,起点在u子树外
//f[u][5]:已处理完u子树内的边,X路径的起点在u子树内,终点在u子树外

int n;
modint x,b[maxn],c[maxn],d[maxn];
vi e[maxn];
modint f[maxn][6],g[6];

void work()
{
	n=read(),x=read();
	For(i,1,n)d[i]=read(),d[i]-=x,e[i].clear();
	For(i,2,n){
		int f=read();
		b[i]=read(),b[i]-=x;
		c[i]=read(),c[i]-=x;
		e[f].pb(i);
	}
	Rep(u,n,1){
		memset(f[u],0,sizeof f[u]);
		f[u][0]=f[u][4]=f[u][5]=1;
		f[u][1]=d[u];
		for(int v:e[u]){
			memset(g,0,sizeof g);
			g[0]=f[u][0]*f[v][1];
			g[1]=f[u][1]*f[v][1]-f[u][0]*f[v][0]*b[v]*c[v];
			g[2]=f[u][2]*f[v][1]+f[u][0]*f[v][3];
			g[3]=f[u][3]*f[v][1]+f[u][1]*f[v][3];
			g[3]-=b[v]*c[v]*(f[u][0]*f[v][2]+f[u][2]*f[v][0]);
			g[3]-=x*b[v]*f[u][5]*f[v][4];
			g[3]-=x*c[v]*f[u][4]*f[v][5];
			g[4]=f[u][4]*f[v][1]-f[u][0]*f[v][4]*b[v];
			g[5]=f[u][5]*f[v][1]-f[u][0]*f[v][5]*c[v];
			memcpy(f[u],g,sizeof f[u]);
//			cout<<"F:\n";
//			For(j,0,5)cout<<f[u][j].x<<" "; cout<<"\n";
		}
		f[u][3]+=f[u][0]*x;
	//	cout<<"u: "<<u<<"\n";
	//	For(j,0,5)cout<<f[u][j].x<<" "; cout<<"\n";
	}
	modint res=f[1][1]+f[1][3];
	cout<<res.x<<"\n";
}

signed main()
{
	int T=read();
	while(T--)work();
    return 0;
}
/*

*/

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 34ms
memory: 61972kb

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: 34ms
memory: 62020kb

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: 62ms
memory: 62172kb

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: 59ms
memory: 62320kb

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: 50ms
memory: 63744kb

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: 19ms
memory: 63764kb

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: 6ms
memory: 62272kb

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