QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460781#7408. DeterminationKazemaruAC ✓71ms70800kbC++141.4kb2024-07-02 09:14:302024-07-02 09:14:30

Judging History

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

  • [2024-07-02 09:14:30]
  • 评测
  • 测评结果:AC
  • 用时:71ms
  • 内存:70800kb
  • [2024-07-02 09:14:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
const int N=2e6,mo=1e9+7;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for(;'0'>ch||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
    return x*f;
}
#define rd()(read()+mo-X)%mo
int a[N],b[N],c[N],d[N],f[N][6],t,X;
vector<int>q[N];
#define fd(x) dfs(x);int p=(f[x][0]*a[x]+f[x][1])%mo,q=(f[x][2]*a[x]+f[x][3])%mo
void dfs(int x){
    f[x][0]=1;f(t,1,5)f[x][t]=0;
    for(int y:q[x]){
        fd(y);
        f[x][3]=(f[x][1]*q+f[x][3]*p+f[x][2]*f[y][0]%mo*d[y]+f[x][0]*f[y][2]%mo*d[y]+f[x][4]*f[y][5]+f[x][5]*f[y][4])%mo;
        f[x][4]=(f[x][0]*f[y][4]+f[x][4]*p)%mo;f[x][5]=(f[x][0]*f[y][5]+f[x][5]*p)%mo;
        f[x][1]=(f[x][1]*p+f[x][0]*f[y][0]%mo*d[y])%mo;f[x][2]=(f[x][2]*p+f[x][0]*q)%mo;f[x][0]=f[x][0]*p%mo;
    }
    f[x][3]=(f[x][0]+f[x][3]+f[x][4]+f[x][5])%mo;
    f[x][4]=(f[x][0]+f[x][4])*b[x]%mo;
    f[x][5]=(f[x][0]+f[x][5])*c[x]%mo;
}
inline void doing(){
    cin>>n>>X;
    f(i,1,n)a[i]=mo-rd(),q[i].clear();
    f(i,2,n){
        q[read()].push_back(i);
        b[i]=rd();c[i]=rd();
        d[i]=mo-b[i]*c[i]%mo;
    }
    fd(1);printf("%lld\n",(p-q*X%mo+mo)*(n%2?mo-1:1)%mo);
}
main(){for(cin>>t;t--;)doing();}

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

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 55968kb

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: 52ms
memory: 59568kb

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: 42ms
memory: 59260kb

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: 71ms
memory: 59960kb

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: 70ms
memory: 61204kb

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: 71ms
memory: 64208kb

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: 22ms
memory: 70800kb

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: 17ms
memory: 69040kb

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