QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537671#4564. Digital CircuitYahia_Emara#16 261ms18856kbC++202.6kb2024-08-30 17:22:042024-08-30 17:22:05

Judging History

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

  • [2024-08-30 17:22:05]
  • 评测
  • 测评结果:16
  • 用时:261ms
  • 内存:18856kb
  • [2024-08-30 17:22:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define dbg(x) cout << (#x) << " : " << x << endl
#define pb push_back
#define all(x) x.begin(),x.end()
#define LOOP(n) for(int rp=0;rp<n;rp++)
#define sq(x) ((x)*(x))
typedef long long ll;
typedef long double dl;
const int SZ=5e5+7;
const ll INF=1e18+7;
const dl eps=1e-9;
int MOD=1e9+2022;
mt19937_64 rng(time(0));
int rnd(int l,int r){
    return uniform_int_distribution<int>(l,r)(rng);
}
ll trig(ll x){
    return x*(x+1)/2;
}
int getN(){
    int n;cin >> n;
    return n;
}
#define cmbntrcs fact[0]=1;for(int i=1;i<SZ;i++)fact[i]=mul(fact[i-1],i);finv[SZ-1]=inv(fact[SZ-1]);for(int i=SZ-2;i>0;i--)finv[i]=mul(finv[i+1],i+1);
int fact[SZ],finv[SZ];
int add(int x,int y,int MOD=MOD){
    x+=y;if(x>=MOD)x-=MOD;
    return x;
}
int sub(int x,int y,int MOD=MOD){
    x-=y;if(x<0)x+=MOD;
    return x;
}
int mul(int x,int y,int MOD=MOD){
    return(x*1ll*y)%MOD;
}
int pwr(int x,ll b,int MOD=MOD){
    int rt=1;
    while(b>0){
        if(b&1)rt=mul(rt,x,MOD);
        x=mul(x,x,MOD),b>>=1;
    }
    return rt;
}
int inv(int x,int MOD=MOD){
    return pwr(x,MOD-2,MOD);
}
#include "circuit.h"
//#include "stub.cpp"
int n,m,p[SZ],a[SZ],c[SZ],I[SZ];
vector<int>g[SZ],v;
int dp[1007][1007],N;
int solve(int i,int P){
    if(i==N)return(P?0:1);
    if(dp[i][P]!=-1)return dp[i][P];
    return dp[i][P]=add(mul(solve(i+1,P),sub(c[v[i]],a[v[i]])),mul(solve(i+1,(P?P-1:0)),a[v[i]]));
}
void calc(int i){
    v=g[i],N=sz(v);
    for(int i=0;i<=N;i++)for(int j=0;j<=N;j++)dp[i][j]=-1;
    a[i]=0;
    for(int P=1;P<=N;P++)a[i]=add(a[i],solve(0,P));
}
void init(int N,int M,vector<int>P,vector<int>A){
    n=N,m=M;
    for(int i=0;i<n+m;i++)p[i]=P[i],I[i]=0;
    for(int i=1;i<n+m;i++)g[p[i]].pb(i);
    for(int i=0;i<m;i++)a[i+n]=A[i],c[i+n]=1;
    for(int i=n-1;i>=0;i--){
        c[i]=sz(g[i]);
        for(auto&j:g[i])c[i]=mul(c[i],c[j]);
        calc(i);
    }
}
void prp(int i){
    for(int ch=i*2+1;ch<=i*2+2;ch++){
        if(I[i])a[ch]=sub(c[ch],a[ch]);
        I[ch]^=I[i];
    }
    I[i]=0;
}
void upd(int l,int r,int i=0,int lx=n,int rx=n+m-1){
    if(r<lx||rx<l)return;
    if(lx>=l&&rx<=r){
        I[i]^=1,a[i]=sub(c[i],a[i]);
        return;
    }
    prp(i);
    int md=(lx+rx)>>1;
    upd(l,r,i*2+1,lx,md),upd(l,r,i*2+2,md+1,rx);
    calc(i);
}
int count_ways(int l,int r){
    upd(l,r);
    return a[0];
}
/*int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    //cout << fixed << setprecision(12);
    int tt=1;
    //cin >> tt;
    LOOP(tt){
        //code
    }
    return 0;
}
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 2
Accepted
time: 0ms
memory: 16220kb

input:

1 2
-1 0 0
0 0
1 1
2 2
1 2
2 2
1 2
-1 -1
-2 -2

output:

1
2
0
1
1

result:

ok 7 lines

Test #2:

score: 2
Accepted
time: 2ms
memory: 12324kb

input:

1 1
-1 0
0
1 1
1 1
1 1
1 1
-1 -1
-2 -2

output:

1
0
1
0

result:

ok 6 lines

Test #3:

score: 0
Wrong Answer
time: 84ms
memory: 18100kb

input:

1 972
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

495
492
487
485
477

result:

wrong answer 3rd lines differ - expected: '509', found: '495'

Subtask #2:

score: 0
Wrong Answer

Test #9:

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

input:

1 2
-1 0 0
0 0
1 1
2 2
1 2
2 2
1 2
-1 -1
-2 -2

output:

1
2
0
1
1

result:

ok 7 lines

Test #10:

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

input:

255 256
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 ...

output:

52130940
785285606
585825652

result:

ok 5 lines

Test #11:

score: 7
Accepted
time: 2ms
memory: 14212kb

input:

511 512
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 ...

output:

655368480
979089518
133738288
486298234
70832346

result:

ok 7 lines

Test #12:

score: 7
Accepted
time: 2ms
memory: 14416kb

input:

511 512
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 ...

output:

640949026
225483138
810019272
225483138
640949026

result:

ok 7 lines

Test #13:

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

input:

511 512
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 ...

output:

655368480
457459326
408972838
872925214
486298234

result:

ok 7 lines

Test #14:

score: 0
Wrong Answer
time: 2ms
memory: 12052kb

input:

726 727
-1 0 0 2 1 1 2 3 5 7 9 4 9 7 6 6 11 8 16 12 17 19 3 14 18 16 15 25 10 10 8 27 26 24 20 30 14 18 33 32 4 40 12 25 30 22 43 45 39 46 13 33 23 13 35 26 31 15 57 47 38 22 37 28 41 55 39 43 23 29 64 17 49 67 24 36 55 5 59 62 63 59 48 28 70 11 71 74 76 56 84 66 88 88 56 58 77 27 79 38 74 98 95 44 ...

output:

445274432
445274432

result:

wrong answer 3rd lines differ - expected: '706880838', found: '445274432'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 4
Accepted

Test #43:

score: 4
Accepted
time: 118ms
memory: 16080kb

input:

32767 32768
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

431985922
394586018
431985922
469385826
506785730
469385826
431985922
469385826
431985922
469385826
506785730
469385826
431985922
394586018
357186114
319786210
357186114
394586018
431985922
394586018
357186114
394586018
431985922
469385826
506785730
469385826
431985922
394586018
357186114
319786210
...

result:

ok 71356 lines

Test #44:

score: 4
Accepted
time: 170ms
memory: 18720kb

input:

65535 65536
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

913758140
928668562
913758140
898847718
883937296
869026874
883937296
898847718
913758140
928668562
913758140
898847718
883937296
898847718
913758140
928668562
913758140
898847718
913758140
928668562
943578984
928668562
913758140
928668562
913758140
898847718
883937296
869026874
883937296
898847718
...

result:

ok 100002 lines

Test #45:

score: 4
Accepted
time: 185ms
memory: 18856kb

input:

65535 65536
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

152530276
137619854
122709432
107799010
92888588
77978166
63067744
48157322
33246900
18336478
3426056
988517656
973607234
958696812
943786390
928875968
913965546
899055124
884144702
869234280
854323858
839413436
824503014
809592592
794682170
779771748
764861326
749950904
735040482
720130060
70521963...

result:

ok 100002 lines

Test #46:

score: 4
Accepted
time: 187ms
memory: 18832kb

input:

65535 65536
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

14910422
29820844
44731266
59641688
74552110
89462532
104372954
119283376
134193798
149104220
164014642
178925064
193835486
208745908
223656330
238566752
253477174
268387596
283298018
298208440
313118862
328029284
342939706
357850128
372760550
387670972
402581394
417491816
432402238
447312660
462223...

result:

ok 100002 lines

Subtask #5:

score: 12
Accepted

Dependency #4:

100%
Accepted

Test #47:

score: 12
Accepted
time: 186ms
memory: 14040kb

input:

32767 32768
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

105182172
904826008
249436868
17023698
882566410
487194958
692003610
262795534
589599284
280604666
916403034
926198420
674194478
705362276
937775446
700017356
700017356
485413318
981407456
376776886
750775926
498771984
502335264
158609568
953802938
851398612
916403034
392804378
552199380
996206
7765...

result:

ok 80874 lines

Test #48:

score: 12
Accepted
time: 261ms
memory: 18720kb

input:

65535 65536
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

987306502
479348406
404796296
600639278
987306502
690101810
599635530
420710466
657269722
880926052
746732254
345154608
59849094
238774158
419706718
237770410
882933548
596624286
852108956
551893020
193039144
641355552
924653570
551893020
87662442
115475790
803362698
86658694
968381088
28020754
3888...

result:

ok 100002 lines

Test #49:

score: 12
Accepted
time: 250ms
memory: 18664kb

input:

65535 65536
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

583721360
598631782
568810938
553900516
538990094
538990094
568810938
598631782
538990094
524079672
524079672
613542204
598631782
613542204
628452626
583721360
568810938
583721360
583721360
598631782
628452626
568810938
524079672
643363048
583721360
568810938
568810938
643363048
524079672
583721360
...

result:

ok 100002 lines

Test #50:

score: 12
Accepted
time: 204ms
memory: 18636kb

input:

65535 65536
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

106587856
60852842
91677434
105584108
61856590
150315374
17125324
150315374
61856590
60852842
2214902
45942420
91677434
105584108
76767012
75763264
76767012
90673686
76767012
165225796
32035746
150315374
46946168
150315374
136408700
120494530
46946168
75763264
91677434
105584108
46946168
90673686
76...

result:

ok 100002 lines

Test #51:

score: 12
Accepted
time: 74ms
memory: 12228kb

input:

2047 2048
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...

output:

134861748
303006848
798573570
283689758
183944440
847656262
381855142
500917550
807442148
728593854
936953068
441386346
490469038
570897266
262792734
966718670
362538052
996484272
15799340
362538052
45564942
500917550
866973352
600662868
828339172
858104774
907187466
817890660
590214356
303006848
27...

result:

ok 50568 lines

Test #52:

score: 12
Accepted
time: 185ms
memory: 12384kb

input:

4095 4096
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...

output:

603631736
197613152
784946490
375602856
512420184
601415036
507986784
195396452
789379890
650345862
560242660
421208632
283282954
830552266
192071402
325563680
282174604
917330418
237677178
967369594
558025960
466814408
12973348
829443916
604740086
192071402
737124014
284391304
422316982
832768966
7...

result:

ok 100002 lines

Test #53:

score: 12
Accepted
time: 167ms
memory: 14704kb

input:

4095 4096
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...

output:

148682326
148682326
784946490
466814408
148682326
784946490
784946490
148682326
148682326
512420184
739340714
57470774
57470774
57470774
421208632
830552266
148682326
194288102
512420184
830552266
512420184
512420184
239893878
921763818
876158042
558025960
148682326
876158042
194288102
512420184
421...

result:

ok 100002 lines

Test #54:

score: 12
Accepted
time: 146ms
memory: 14708kb

input:

4095 4096
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...

output:

783838140
786054840
101968200
467922758
465706058
740449064
56362424
104184900
101968200
467922758
465706058
104184900
783838140
467922758
147573976
831660616
511311834
786054840
101968200
831660616
465706058
149790676
829443916
831660616
147573976
467922758
465706058
149790676
465706058
149790676
1...

result:

ok 100002 lines

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%