QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142836#4564. Digital CircuitUNos_maricones#4 962ms30720kbC++143.3kb2023-08-20 00:14:362024-07-04 01:49:19

Judging History

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

  • [2024-07-04 01:49:19]
  • 评测
  • 测评结果:4
  • 用时:962ms
  • 内存:30720kb
  • [2023-08-20 00:14:36]
  • 提交

answer

#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

#define ff   first
#define ss   second
#define pb   push_back

typedef pair<int,int>   ii;

const int MXN = 4e5+5;
const int mod = 1000002022;

int v[MXN];
int pot[MXN];
vector <int> g[MXN];
int sum0[4*MXN], sum1[4*MXN], lazy[4*MXN];
int subtree[MXN];
int n;
int m;
int a[MXN];

void build (int node, int l, int r) { 
  if (l == r) { 
    if (a[l] == 0) sum0[node] = v[l + n];
    else sum1[node] = v[l + n];
    return;
  }
  int m = (l + r) / 2;
  build (node * 2, l, m);
  build (node * 2 + 1, m + 1, r);
  sum0[node] = (sum0[node * 2] + sum0[node * 2 + 1])%mod;
  sum1[node] = (sum1[node * 2] + sum1[node * 2 + 1])%mod;
 // cout << "in build " << l << ' ' << r << ' ' << sum1[node] << '\n';
}

void propagate (int node) { 
  if (lazy[node]) { 
    swap(sum0[node], sum1[node]);
    lazy[node * 2] ^= 1;
    lazy[node * 2 + 1] ^= 1;
  }
  lazy[node] = 0;
}

void update (int node, int l, int r, int a, int b) {
  propagate(node);
  if (b < l || a > r) return;
  if (a <= l && r <= b) {
    lazy[node] = 1;
    propagate(node);
    return;
  }
  int m = (l + r) / 2;
  update(node * 2, l, m, a, b);
  update(node * 2 + 1, m + 1, r, a, b);
  sum0[node] = (sum0[node * 2] + sum0[node * 2 + 1])%mod;
  sum1[node] = (sum1[node * 2] + sum1[node * 2 + 1])%mod;
}

void dfs (int u) { 
  if (g[u].size()) subtree[u]++;
  for (auto &v : g[u]) { 
    dfs(v);
    subtree[u] += subtree[v];    
  }
}

void init(int N, int M, vector<int> P, vector<int> A) {
  n=N; m=M;
  pot[0]=1;
  for (int i = 1; i < MXN; ++i) pot[i] = (1ll * pot[i - 1] * 2) % mod;
  for (int i = 1; i < N + M; ++i) g[P[i]].pb(i);
  for (int i = 0; i < M; ++i) a[i] = A[i];
  dfs(0);
  v[0]=1;
  for (int i = 1; i < N + M; ++i) { 
    int ot = (g[P[i]][0] == i ? g[P[i]][1] : g[P[i]][0]);
    v[i] = (1ll * v[P[i]] * pot[subtree[ot]]) % mod;
    //cout << i << ' ' << v[i] << '\n';
  }
  build (1, 0, M-1);
}

int count_ways(int L, int R) {
  update(1, 0, m-1, L-n, R-n);
  if (n + m <= 10000) { 
    vector <ii> dp(n + m);
    for (int i = L-n; i <= R-n; ++i) a[i] ^= 1;
    for (int i = n; i < n + m; ++i) dp[i] = {a[i - n],1};
    for (int i = n-1; i >= 0; --i) {
        dp[i].ff = dp[i].ss = 1;
        for (auto &e : g[i]) { 
            ii nw;
            nw.ff = (1ll * dp[i].ff * pot[subtree[e]] + 1ll * dp[i].ss * dp[e].ff) % mod;
            nw.ss = (1ll * dp[i].ss * pot[subtree[e]] + 1ll * dp[i].ff * dp[e].ff) % mod;
            dp[i] = nw;
        }
    }
    return dp[0].ff;
  }
  /*
  vector <int> dp(n + m);
  for (int i = L-n; i <= R-n; ++i) a[i] ^= 1;
  for (int i = n; i < n + m; ++i) dp[i] = a[i - n];
  for (int i = n-1; i >= 0; --i) dp[i] = (1ll * dp[g[i][0]] * pot[subtree[g[i][1]]] + 1ll * dp[g[i][1]] * pot[subtree[g[i][0]]]) % mod;
  cout << dp[0] << '\n';
  cout << sum1[1] << '\n';
  */
  return sum1[1];
}
/*
int main() {
    int N=8,M=9;
    vector <int> P={-1, 0, 0, 1,2,2,3,3,1,6,6,7,7,4,4,5,5};
    vector <int> A={0,0,1,0,0,0,0,0,1};
    init(N,M,P,A);
    count_ways(10,10);
    count_ways(10,10);
    count_ways(9, 14);
    count_ways(13, 16);
    count_ways(8, 12);
    count_ways(9, 14);
    count_ways(9, 11);
    count_ways(10, 12);
    count_ways(9, 14);
    count_ways(9, 14);
    
}
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 20100kb

input:

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

output:

2
4
1
2
2

result:

wrong answer 3rd lines differ - expected: '1', found: '2'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 3ms
memory: 20420kb

input:

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

output:

2
4
1
2
2

result:

wrong answer 3rd lines differ - expected: '1', found: '2'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 4
Accepted

Test #43:

score: 4
Accepted
time: 41ms
memory: 24092kb

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: 60ms
memory: 30720kb

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: 66ms
memory: 24424kb

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: 63ms
memory: 24380kb

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: 0
Wrong Answer

Dependency #4:

100%
Accepted

Test #47:

score: 12
Accepted
time: 68ms
memory: 23884kb

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: 78ms
memory: 25924kb

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: 95ms
memory: 26956kb

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: 79ms
memory: 23916kb

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: 0
Wrong Answer
time: 962ms
memory: 20360kb

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:

776530298
271262568
347114326
835521072
26350042
830029052
38723224
812402156
197199550
262568654
792419662
940563202
483329122
253225900
862508460
404562858
598960474
545211432
629125328
77295726
770503290
96745780
515256720
151008948
567302546
199471840
553318688
89359976
589385200
803511356
84770...

result:

wrong answer 3rd lines differ - expected: '134861748', found: '776530298'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%