Submission #819061

# Submission time Handle Problem Language Result Execution time Memory
819061 2023-08-10T07:49:02 Z andrei_boaca Digital Circuit (IOI22_circuit) C++17
100 / 100
988 ms 43008 KB
#include "circuit.h"

#include <vector>
#include <bits/stdc++.h>
//#include "stub.cpp"
using namespace std;
typedef long long ll;
const ll mod=1e9+2022;
ll n,m,par[200005];
vector<ll> muchii[200005];
ll val[200005];
ll sub[200005],coef[200005];
void dfs(int nod)
{
    sub[nod]=1;
    if(muchii[nod].empty())
        return;
    sub[nod]*=(ll)muchii[nod].size();
    sub[nod]%=mod;
    for(int i:muchii[nod])
    {
        dfs(i);
        sub[nod]=(sub[nod]*sub[i])%mod;
    }
}
void calc(int nod,ll c)
{
    if(muchii[nod].empty())
    {
        coef[nod-n+1]=c;
        return;
    }
    vector<ll> pref;
    vector<ll> suf;
    ll prod=1;
    for(int i=0;i<muchii[nod].size();i++)
    {
        prod=(prod*sub[muchii[nod][i]])%mod;
        pref.push_back(prod);
    }
    prod=1;
    for(int i=(int)muchii[nod].size()-1;i>=0;i--)
    {
        prod=(prod*sub[muchii[nod][i]])%mod;
        suf.push_back(prod);
    }
    reverse(suf.begin(),suf.end());
    for(int i=0;i<muchii[nod].size();i++)
    {
        ll val=1;
        if(i>0)
            val=(val*pref[i-1])%mod;
        if(i+1<muchii[nod].size())
            val=(val*suf[i+1])%mod;
        val=(val*c)%mod;
        calc(muchii[nod][i],val);
    }
}
ll arb[2][8*100005],toprop[8*100005];
void build(int nod,int st,int dr)
{
    if(st==dr)
    {
        arb[0][nod]=(val[st]==0)*coef[st];
        arb[1][nod]=(val[st]==1)*coef[st];
        return;
    }
    ll mij=(st+dr)/2;
    build(nod*2,st,mij);
    build(nod*2+1,mij+1,dr);
    arb[0][nod]=(arb[0][nod*2]+arb[0][nod*2+1])%mod;
    arb[1][nod]=(arb[1][nod*2]+arb[1][nod*2+1])%mod;
}
void prop(int nod)
{
    toprop[nod*2]^=1;
    toprop[nod*2+1]^=1;
    swap(arb[0][nod*2],arb[1][nod*2]);
    swap(arb[0][nod*2+1],arb[1][nod*2+1]);
}
void update(int nod,int st,int dr,int a,int b)
{
    if(st!=dr&&toprop[nod])
        prop(nod);
    toprop[nod]=0;
    if(st>=a&&dr<=b)
    {
        swap(arb[0][nod],arb[1][nod]);
        toprop[nod]=1;
        return;
    }
    int mij=(st+dr)/2;
    if(a<=mij)
        update(nod*2,st,mij,a,b);
    if(b>mij)
        update(nod*2+1,mij+1,dr,a,b);
    arb[0][nod]=(arb[0][nod*2]+arb[0][nod*2+1])%mod;
    arb[1][nod]=(arb[1][nod*2]+arb[1][nod*2+1])%mod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n=N;
    m=M;
    for(int i=0;i<P.size();i++)
    {
        muchii[P[i]].push_back(i);
        par[i]=P[i];
    }
    for(int i=0;i<A.size();i++)
        val[i+1]=A[i];
    dfs(0);
    calc(0,1);
    build(1,1,m);
}

int count_ways(int L, int R) {
    L-=n;
    R-=n;
    L++;
    R++;
    update(1,1,m,L,R);
    return arb[1][1];
}

Compilation message

circuit.cpp: In function 'void calc(int, ll)':
circuit.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<muchii[nod].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~
circuit.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<muchii[nod].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~
circuit.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         if(i+1<muchii[nod].size())
      |            ~~~^~~~~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:103:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |     for(int i=0;i<P.size();i++)
      |                 ~^~~~~~~~~
circuit.cpp:108:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i=0;i<A.size();i++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 5072 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 5112 KB Output is correct
5 Correct 2 ms 5108 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5124 KB Output is correct
9 Correct 3 ms 5088 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 5072 KB Output is correct
11 Correct 2 ms 5008 KB Output is correct
12 Correct 3 ms 5112 KB Output is correct
13 Correct 2 ms 5108 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5124 KB Output is correct
17 Correct 3 ms 5088 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 2 ms 5072 KB Output is correct
22 Correct 3 ms 5136 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5136 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 3 ms 5080 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 2 ms 5056 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 489 ms 9528 KB Output is correct
2 Correct 756 ms 14016 KB Output is correct
3 Correct 804 ms 14072 KB Output is correct
4 Correct 767 ms 14012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 489 ms 9528 KB Output is correct
2 Correct 756 ms 14016 KB Output is correct
3 Correct 804 ms 14072 KB Output is correct
4 Correct 767 ms 14012 KB Output is correct
5 Correct 598 ms 9544 KB Output is correct
6 Correct 912 ms 14088 KB Output is correct
7 Correct 894 ms 14148 KB Output is correct
8 Correct 840 ms 13696 KB Output is correct
9 Correct 420 ms 5328 KB Output is correct
10 Correct 803 ms 5640 KB Output is correct
11 Correct 839 ms 5584 KB Output is correct
12 Correct 640 ms 5584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 5072 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 3 ms 5112 KB Output is correct
5 Correct 2 ms 5108 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5124 KB Output is correct
9 Correct 3 ms 5088 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 489 ms 9528 KB Output is correct
14 Correct 756 ms 14016 KB Output is correct
15 Correct 804 ms 14072 KB Output is correct
16 Correct 767 ms 14012 KB Output is correct
17 Correct 598 ms 9544 KB Output is correct
18 Correct 912 ms 14088 KB Output is correct
19 Correct 894 ms 14148 KB Output is correct
20 Correct 840 ms 13696 KB Output is correct
21 Correct 420 ms 5328 KB Output is correct
22 Correct 803 ms 5640 KB Output is correct
23 Correct 839 ms 5584 KB Output is correct
24 Correct 640 ms 5584 KB Output is correct
25 Correct 817 ms 20028 KB Output is correct
26 Correct 817 ms 20188 KB Output is correct
27 Correct 788 ms 20188 KB Output is correct
28 Correct 482 ms 19228 KB Output is correct
29 Correct 918 ms 42084 KB Output is correct
30 Correct 832 ms 41092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 5072 KB Output is correct
11 Correct 2 ms 5008 KB Output is correct
12 Correct 3 ms 5112 KB Output is correct
13 Correct 2 ms 5108 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5124 KB Output is correct
17 Correct 3 ms 5088 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 2 ms 5072 KB Output is correct
22 Correct 3 ms 5136 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5136 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 3 ms 5080 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 2 ms 5056 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 477 ms 5416 KB Output is correct
44 Correct 570 ms 5456 KB Output is correct
45 Correct 627 ms 5456 KB Output is correct
46 Correct 522 ms 5896 KB Output is correct
47 Correct 518 ms 5968 KB Output is correct
48 Correct 726 ms 5968 KB Output is correct
49 Correct 683 ms 5896 KB Output is correct
50 Correct 742 ms 5828 KB Output is correct
51 Correct 703 ms 5724 KB Output is correct
52 Correct 716 ms 5828 KB Output is correct
53 Correct 479 ms 6408 KB Output is correct
54 Correct 689 ms 5896 KB Output is correct
55 Correct 882 ms 5840 KB Output is correct
56 Correct 724 ms 5668 KB Output is correct
57 Correct 557 ms 5648 KB Output is correct
58 Correct 682 ms 6944 KB Output is correct
59 Correct 650 ms 7128 KB Output is correct
60 Correct 747 ms 7008 KB Output is correct
61 Correct 684 ms 5712 KB Output is correct
62 Correct 778 ms 5528 KB Output is correct
63 Correct 738 ms 5512 KB Output is correct
64 Correct 735 ms 5712 KB Output is correct
65 Correct 237 ms 5328 KB Output is correct
66 Correct 597 ms 5584 KB Output is correct
67 Correct 523 ms 5584 KB Output is correct
68 Correct 693 ms 5508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 5072 KB Output is correct
11 Correct 2 ms 5008 KB Output is correct
12 Correct 3 ms 5112 KB Output is correct
13 Correct 2 ms 5108 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5124 KB Output is correct
17 Correct 3 ms 5088 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 2 ms 5072 KB Output is correct
22 Correct 3 ms 5136 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5136 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 3 ms 5080 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 2 ms 5056 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 489 ms 9528 KB Output is correct
44 Correct 756 ms 14016 KB Output is correct
45 Correct 804 ms 14072 KB Output is correct
46 Correct 767 ms 14012 KB Output is correct
47 Correct 598 ms 9544 KB Output is correct
48 Correct 912 ms 14088 KB Output is correct
49 Correct 894 ms 14148 KB Output is correct
50 Correct 840 ms 13696 KB Output is correct
51 Correct 420 ms 5328 KB Output is correct
52 Correct 803 ms 5640 KB Output is correct
53 Correct 839 ms 5584 KB Output is correct
54 Correct 640 ms 5584 KB Output is correct
55 Correct 817 ms 20028 KB Output is correct
56 Correct 817 ms 20188 KB Output is correct
57 Correct 788 ms 20188 KB Output is correct
58 Correct 482 ms 19228 KB Output is correct
59 Correct 918 ms 42084 KB Output is correct
60 Correct 832 ms 41092 KB Output is correct
61 Correct 477 ms 5416 KB Output is correct
62 Correct 570 ms 5456 KB Output is correct
63 Correct 627 ms 5456 KB Output is correct
64 Correct 522 ms 5896 KB Output is correct
65 Correct 518 ms 5968 KB Output is correct
66 Correct 726 ms 5968 KB Output is correct
67 Correct 683 ms 5896 KB Output is correct
68 Correct 742 ms 5828 KB Output is correct
69 Correct 703 ms 5724 KB Output is correct
70 Correct 716 ms 5828 KB Output is correct
71 Correct 479 ms 6408 KB Output is correct
72 Correct 689 ms 5896 KB Output is correct
73 Correct 882 ms 5840 KB Output is correct
74 Correct 724 ms 5668 KB Output is correct
75 Correct 557 ms 5648 KB Output is correct
76 Correct 682 ms 6944 KB Output is correct
77 Correct 650 ms 7128 KB Output is correct
78 Correct 747 ms 7008 KB Output is correct
79 Correct 684 ms 5712 KB Output is correct
80 Correct 778 ms 5528 KB Output is correct
81 Correct 738 ms 5512 KB Output is correct
82 Correct 735 ms 5712 KB Output is correct
83 Correct 237 ms 5328 KB Output is correct
84 Correct 597 ms 5584 KB Output is correct
85 Correct 523 ms 5584 KB Output is correct
86 Correct 693 ms 5508 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 504 ms 19664 KB Output is correct
89 Correct 726 ms 14044 KB Output is correct
90 Correct 678 ms 14112 KB Output is correct
91 Correct 790 ms 20800 KB Output is correct
92 Correct 782 ms 20908 KB Output is correct
93 Correct 762 ms 21000 KB Output is correct
94 Correct 799 ms 20792 KB Output is correct
95 Correct 709 ms 19896 KB Output is correct
96 Correct 838 ms 14680 KB Output is correct
97 Correct 733 ms 16020 KB Output is correct
98 Correct 668 ms 32320 KB Output is correct
99 Correct 816 ms 20200 KB Output is correct
100 Correct 899 ms 18652 KB Output is correct
101 Correct 973 ms 17704 KB Output is correct
102 Correct 768 ms 16196 KB Output is correct
103 Correct 789 ms 42084 KB Output is correct
104 Correct 860 ms 43008 KB Output is correct
105 Correct 670 ms 42116 KB Output is correct
106 Correct 787 ms 18704 KB Output is correct
107 Correct 988 ms 16240 KB Output is correct
108 Correct 916 ms 16580 KB Output is correct
109 Correct 861 ms 16320 KB Output is correct