Submission #746566

# Submission time Handle Problem Language Result Execution time Memory
746566 2023-05-22T19:31:02 Z Rafi22 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 19316 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000002022;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=200007,pot=1<<17;

bool is[N];
vector<int>G[N];
ll ile[N];
vector<ll>P[N];
vector<ll>S[N];

ll seg[2][2*pot+7];
bool lzy[2*pot+7];

void ins(int v,int a,int b,int l,int r)
{
    if(a<=l&&b>=r)
    {
        swap(seg[0][v],seg[1][v]);
        lzy[v]^=1;
        return ;
    }
    if(r<a||l>b) return ;
    if(lzy[v])
    {
        swap(seg[0][2*v],seg[1][2*v]);
        swap(seg[0][2*v+1],seg[1][2*v+1]);
        lzy[2*v]^=1;
        lzy[2*v+1]^=1;
        lzy[v]=0;
    }

    ins(2*v,a,b,l,(l+r)/2);
    ins(2*v+1,a,b,(l+r)/2+1,r);
    seg[0][v]=seg[0][2*v]+seg[0][2*v+1];
    seg[1][v]=seg[1][2*v]+seg[1][2*v+1];
}

int n,m;

void dfs(int v)
{
    ile[v]=max(1,sz(G[v]));
    for(auto u:G[v])
    {
        dfs(u);
        ile[v]=ile[v]*ile[u]%mod;
    }
}

void dfs1(int v,ll c)
{
    if(sz(G[v])==0)
    {
        seg[is[v]][v-n+1+pot-1]=c;
        return ;
    }
    P[v].resize(sz(G[v])+2,1);
    for(int i=0;i<sz(G[v]);i++) P[v][i+1]=P[v][i]*ile[G[v][i]]%mod;
    S[v].resize(sz(G[v])+2,1);
    for(int i=sz(G[v])-1;i>=0;i--) S[v][i+1]=S[v][i+2]*ile[G[v][i]]%mod;
    for(int i=0;i<sz(G[v]);i++)
    {
        dfs1(G[v][i],c*P[v][i]%mod*S[v][i+2]%mod);
    }
    for(int i=pot-1;i>0;i--)
    {
        seg[0][i]=(seg[0][2*i]+seg[0][2*i+1])%mod;
        seg[1][i]=(seg[1][2*i]+seg[1][2*i+1])%mod;
    }
}

void init(int N,int M,vector<int>p,vector<int>a)
{
    n=N,m=M;
    for(int i=0;i<m;i++) is[i+n]=a[i];
    for(int i=1;i<n+m;i++) G[p[i]].pb(i);
    dfs(0);
    dfs1(0,1);
}

int count_ways(int l,int r)
{
    ins(1,l-n+1,r-n+1,1,pot);
    return seg[1][1]%mod;
}

/*int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    init(3, 4, {-1, 0, 1, 2, 1, 1, 0}, {1, 0, 1, 0});
    cout<<count_ways(3, 4)<<endl;
    cout<<count_ways(4, 5)<<endl;
    cout<<count_ways(3, 6)<<endl;
    return 0;
}*/

# Verdict Execution time Memory Grader output
1 Correct 10 ms 16432 KB Output is correct
2 Correct 11 ms 16464 KB Output is correct
3 Correct 11 ms 16528 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 12 ms 16464 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16464 KB Output is correct
8 Correct 10 ms 16464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16420 KB Output is correct
2 Correct 322 ms 16480 KB Output is correct
3 Correct 643 ms 16620 KB Output is correct
4 Correct 638 ms 16628 KB Output is correct
5 Correct 628 ms 16748 KB Output is correct
6 Correct 910 ms 16796 KB Output is correct
7 Correct 1230 ms 16720 KB Output is correct
8 Correct 1205 ms 16808 KB Output is correct
9 Correct 1219 ms 16836 KB Output is correct
10 Correct 1232 ms 16720 KB Output is correct
11 Correct 1281 ms 16832 KB Output is correct
12 Correct 1046 ms 16936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16432 KB Output is correct
2 Correct 11 ms 16464 KB Output is correct
3 Correct 11 ms 16528 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 12 ms 16464 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16464 KB Output is correct
8 Correct 10 ms 16464 KB Output is correct
9 Correct 10 ms 16420 KB Output is correct
10 Correct 322 ms 16480 KB Output is correct
11 Correct 643 ms 16620 KB Output is correct
12 Correct 638 ms 16628 KB Output is correct
13 Correct 628 ms 16748 KB Output is correct
14 Correct 910 ms 16796 KB Output is correct
15 Correct 1230 ms 16720 KB Output is correct
16 Correct 1205 ms 16808 KB Output is correct
17 Correct 1219 ms 16836 KB Output is correct
18 Correct 1232 ms 16720 KB Output is correct
19 Correct 1281 ms 16832 KB Output is correct
20 Correct 1046 ms 16936 KB Output is correct
21 Correct 882 ms 16672 KB Output is correct
22 Correct 1002 ms 16896 KB Output is correct
23 Correct 838 ms 16740 KB Output is correct
24 Correct 1230 ms 16820 KB Output is correct
25 Correct 1256 ms 16720 KB Output is correct
26 Correct 1271 ms 16676 KB Output is correct
27 Correct 1237 ms 16660 KB Output is correct
28 Correct 1211 ms 16696 KB Output is correct
29 Correct 10 ms 16464 KB Output is correct
30 Correct 12 ms 16480 KB Output is correct
31 Correct 1231 ms 16592 KB Output is correct
32 Correct 1266 ms 16700 KB Output is correct
33 Correct 614 ms 16532 KB Output is correct
34 Correct 325 ms 16524 KB Output is correct
35 Correct 15 ms 16496 KB Output is correct
36 Correct 1207 ms 16720 KB Output is correct
37 Correct 1214 ms 16720 KB Output is correct
38 Correct 1230 ms 16720 KB Output is correct
39 Correct 855 ms 16624 KB Output is correct
40 Correct 620 ms 16640 KB Output is correct
41 Correct 450 ms 16656 KB Output is correct
42 Correct 76 ms 16508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3034 ms 19316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3034 ms 19316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16420 KB Output is correct
2 Correct 322 ms 16480 KB Output is correct
3 Correct 643 ms 16620 KB Output is correct
4 Correct 638 ms 16628 KB Output is correct
5 Correct 628 ms 16748 KB Output is correct
6 Correct 910 ms 16796 KB Output is correct
7 Correct 1230 ms 16720 KB Output is correct
8 Correct 1205 ms 16808 KB Output is correct
9 Correct 1219 ms 16836 KB Output is correct
10 Correct 1232 ms 16720 KB Output is correct
11 Correct 1281 ms 16832 KB Output is correct
12 Correct 1046 ms 16936 KB Output is correct
13 Execution timed out 3034 ms 19316 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16432 KB Output is correct
2 Correct 11 ms 16464 KB Output is correct
3 Correct 11 ms 16528 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 12 ms 16464 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16464 KB Output is correct
8 Correct 10 ms 16464 KB Output is correct
9 Correct 10 ms 16420 KB Output is correct
10 Correct 322 ms 16480 KB Output is correct
11 Correct 643 ms 16620 KB Output is correct
12 Correct 638 ms 16628 KB Output is correct
13 Correct 628 ms 16748 KB Output is correct
14 Correct 910 ms 16796 KB Output is correct
15 Correct 1230 ms 16720 KB Output is correct
16 Correct 1205 ms 16808 KB Output is correct
17 Correct 1219 ms 16836 KB Output is correct
18 Correct 1232 ms 16720 KB Output is correct
19 Correct 1281 ms 16832 KB Output is correct
20 Correct 1046 ms 16936 KB Output is correct
21 Correct 882 ms 16672 KB Output is correct
22 Correct 1002 ms 16896 KB Output is correct
23 Correct 838 ms 16740 KB Output is correct
24 Correct 1230 ms 16820 KB Output is correct
25 Correct 1256 ms 16720 KB Output is correct
26 Correct 1271 ms 16676 KB Output is correct
27 Correct 1237 ms 16660 KB Output is correct
28 Correct 1211 ms 16696 KB Output is correct
29 Correct 10 ms 16464 KB Output is correct
30 Correct 12 ms 16480 KB Output is correct
31 Correct 1231 ms 16592 KB Output is correct
32 Correct 1266 ms 16700 KB Output is correct
33 Correct 614 ms 16532 KB Output is correct
34 Correct 325 ms 16524 KB Output is correct
35 Correct 15 ms 16496 KB Output is correct
36 Correct 1207 ms 16720 KB Output is correct
37 Correct 1214 ms 16720 KB Output is correct
38 Correct 1230 ms 16720 KB Output is correct
39 Correct 855 ms 16624 KB Output is correct
40 Correct 620 ms 16640 KB Output is correct
41 Correct 450 ms 16656 KB Output is correct
42 Correct 76 ms 16508 KB Output is correct
43 Execution timed out 3034 ms 17032 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16432 KB Output is correct
2 Correct 11 ms 16464 KB Output is correct
3 Correct 11 ms 16528 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 12 ms 16464 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16464 KB Output is correct
8 Correct 10 ms 16464 KB Output is correct
9 Correct 10 ms 16420 KB Output is correct
10 Correct 322 ms 16480 KB Output is correct
11 Correct 643 ms 16620 KB Output is correct
12 Correct 638 ms 16628 KB Output is correct
13 Correct 628 ms 16748 KB Output is correct
14 Correct 910 ms 16796 KB Output is correct
15 Correct 1230 ms 16720 KB Output is correct
16 Correct 1205 ms 16808 KB Output is correct
17 Correct 1219 ms 16836 KB Output is correct
18 Correct 1232 ms 16720 KB Output is correct
19 Correct 1281 ms 16832 KB Output is correct
20 Correct 1046 ms 16936 KB Output is correct
21 Correct 882 ms 16672 KB Output is correct
22 Correct 1002 ms 16896 KB Output is correct
23 Correct 838 ms 16740 KB Output is correct
24 Correct 1230 ms 16820 KB Output is correct
25 Correct 1256 ms 16720 KB Output is correct
26 Correct 1271 ms 16676 KB Output is correct
27 Correct 1237 ms 16660 KB Output is correct
28 Correct 1211 ms 16696 KB Output is correct
29 Correct 10 ms 16464 KB Output is correct
30 Correct 12 ms 16480 KB Output is correct
31 Correct 1231 ms 16592 KB Output is correct
32 Correct 1266 ms 16700 KB Output is correct
33 Correct 614 ms 16532 KB Output is correct
34 Correct 325 ms 16524 KB Output is correct
35 Correct 15 ms 16496 KB Output is correct
36 Correct 1207 ms 16720 KB Output is correct
37 Correct 1214 ms 16720 KB Output is correct
38 Correct 1230 ms 16720 KB Output is correct
39 Correct 855 ms 16624 KB Output is correct
40 Correct 620 ms 16640 KB Output is correct
41 Correct 450 ms 16656 KB Output is correct
42 Correct 76 ms 16508 KB Output is correct
43 Execution timed out 3034 ms 19316 KB Time limit exceeded
44 Halted 0 ms 0 KB -