Submission #746561

# Submission time Handle Problem Language Result Execution time Memory
746561 2023-05-22T19:22:26 Z Rafi22 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 21144 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<<18;

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

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

void push(int v)
{
    if(lzy[v])
    {
        swap(seg[2*v][0],seg[2*v][1]);
        swap(seg[2*v+1][0],seg[2*v+1][1]);
        lzy[2*v]^=1;
        lzy[2*v+1]^=1;
        lzy[v]=0;
    }
}

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

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[v+pot-1][is[v]]=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[i][0]=(seg[2*i][0]+seg[2*i+1][0])%mod;
        seg[i][1]=(seg[2*i][1]+seg[2*i+1][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,r,1,pot);
    return seg[1][1];
}

# Verdict Execution time Memory Grader output
1 Correct 12 ms 18512 KB Output is correct
2 Correct 13 ms 18404 KB Output is correct
3 Correct 12 ms 18504 KB Output is correct
4 Correct 13 ms 18512 KB Output is correct
5 Correct 14 ms 18504 KB Output is correct
6 Correct 13 ms 18516 KB Output is correct
7 Correct 13 ms 18604 KB Output is correct
8 Correct 13 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 18512 KB Output is correct
2 Correct 617 ms 18656 KB Output is correct
3 Correct 1223 ms 18592 KB Output is correct
4 Correct 1221 ms 18688 KB Output is correct
5 Correct 1216 ms 18696 KB Output is correct
6 Correct 1720 ms 18696 KB Output is correct
7 Correct 2368 ms 18848 KB Output is correct
8 Correct 2376 ms 18880 KB Output is correct
9 Correct 2372 ms 18760 KB Output is correct
10 Correct 2377 ms 18768 KB Output is correct
11 Correct 2388 ms 18904 KB Output is correct
12 Correct 2025 ms 18700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 18512 KB Output is correct
2 Correct 13 ms 18404 KB Output is correct
3 Correct 12 ms 18504 KB Output is correct
4 Correct 13 ms 18512 KB Output is correct
5 Correct 14 ms 18504 KB Output is correct
6 Correct 13 ms 18516 KB Output is correct
7 Correct 13 ms 18604 KB Output is correct
8 Correct 13 ms 18512 KB Output is correct
9 Correct 13 ms 18512 KB Output is correct
10 Correct 617 ms 18656 KB Output is correct
11 Correct 1223 ms 18592 KB Output is correct
12 Correct 1221 ms 18688 KB Output is correct
13 Correct 1216 ms 18696 KB Output is correct
14 Correct 1720 ms 18696 KB Output is correct
15 Correct 2368 ms 18848 KB Output is correct
16 Correct 2376 ms 18880 KB Output is correct
17 Correct 2372 ms 18760 KB Output is correct
18 Correct 2377 ms 18768 KB Output is correct
19 Correct 2388 ms 18904 KB Output is correct
20 Correct 2025 ms 18700 KB Output is correct
21 Correct 1744 ms 18716 KB Output is correct
22 Correct 1921 ms 18656 KB Output is correct
23 Correct 1589 ms 18732 KB Output is correct
24 Correct 2374 ms 18792 KB Output is correct
25 Correct 2386 ms 18872 KB Output is correct
26 Correct 2382 ms 18760 KB Output is correct
27 Correct 2381 ms 18744 KB Output is correct
28 Correct 2367 ms 18828 KB Output is correct
29 Correct 13 ms 18552 KB Output is correct
30 Correct 13 ms 18512 KB Output is correct
31 Correct 2400 ms 18704 KB Output is correct
32 Correct 2402 ms 18892 KB Output is correct
33 Correct 1196 ms 18696 KB Output is correct
34 Correct 603 ms 18632 KB Output is correct
35 Correct 20 ms 18552 KB Output is correct
36 Correct 2404 ms 18888 KB Output is correct
37 Correct 2405 ms 18768 KB Output is correct
38 Correct 2354 ms 18764 KB Output is correct
39 Correct 1714 ms 18732 KB Output is correct
40 Correct 1222 ms 18820 KB Output is correct
41 Correct 887 ms 18692 KB Output is correct
42 Correct 119 ms 18556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 21144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 21144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 18512 KB Output is correct
2 Correct 617 ms 18656 KB Output is correct
3 Correct 1223 ms 18592 KB Output is correct
4 Correct 1221 ms 18688 KB Output is correct
5 Correct 1216 ms 18696 KB Output is correct
6 Correct 1720 ms 18696 KB Output is correct
7 Correct 2368 ms 18848 KB Output is correct
8 Correct 2376 ms 18880 KB Output is correct
9 Correct 2372 ms 18760 KB Output is correct
10 Correct 2377 ms 18768 KB Output is correct
11 Correct 2388 ms 18904 KB Output is correct
12 Correct 2025 ms 18700 KB Output is correct
13 Execution timed out 3064 ms 21144 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 18512 KB Output is correct
2 Correct 13 ms 18404 KB Output is correct
3 Correct 12 ms 18504 KB Output is correct
4 Correct 13 ms 18512 KB Output is correct
5 Correct 14 ms 18504 KB Output is correct
6 Correct 13 ms 18516 KB Output is correct
7 Correct 13 ms 18604 KB Output is correct
8 Correct 13 ms 18512 KB Output is correct
9 Correct 13 ms 18512 KB Output is correct
10 Correct 617 ms 18656 KB Output is correct
11 Correct 1223 ms 18592 KB Output is correct
12 Correct 1221 ms 18688 KB Output is correct
13 Correct 1216 ms 18696 KB Output is correct
14 Correct 1720 ms 18696 KB Output is correct
15 Correct 2368 ms 18848 KB Output is correct
16 Correct 2376 ms 18880 KB Output is correct
17 Correct 2372 ms 18760 KB Output is correct
18 Correct 2377 ms 18768 KB Output is correct
19 Correct 2388 ms 18904 KB Output is correct
20 Correct 2025 ms 18700 KB Output is correct
21 Correct 1744 ms 18716 KB Output is correct
22 Correct 1921 ms 18656 KB Output is correct
23 Correct 1589 ms 18732 KB Output is correct
24 Correct 2374 ms 18792 KB Output is correct
25 Correct 2386 ms 18872 KB Output is correct
26 Correct 2382 ms 18760 KB Output is correct
27 Correct 2381 ms 18744 KB Output is correct
28 Correct 2367 ms 18828 KB Output is correct
29 Correct 13 ms 18552 KB Output is correct
30 Correct 13 ms 18512 KB Output is correct
31 Correct 2400 ms 18704 KB Output is correct
32 Correct 2402 ms 18892 KB Output is correct
33 Correct 1196 ms 18696 KB Output is correct
34 Correct 603 ms 18632 KB Output is correct
35 Correct 20 ms 18552 KB Output is correct
36 Correct 2404 ms 18888 KB Output is correct
37 Correct 2405 ms 18768 KB Output is correct
38 Correct 2354 ms 18764 KB Output is correct
39 Correct 1714 ms 18732 KB Output is correct
40 Correct 1222 ms 18820 KB Output is correct
41 Correct 887 ms 18692 KB Output is correct
42 Correct 119 ms 18556 KB Output is correct
43 Execution timed out 3045 ms 19120 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 18512 KB Output is correct
2 Correct 13 ms 18404 KB Output is correct
3 Correct 12 ms 18504 KB Output is correct
4 Correct 13 ms 18512 KB Output is correct
5 Correct 14 ms 18504 KB Output is correct
6 Correct 13 ms 18516 KB Output is correct
7 Correct 13 ms 18604 KB Output is correct
8 Correct 13 ms 18512 KB Output is correct
9 Correct 13 ms 18512 KB Output is correct
10 Correct 617 ms 18656 KB Output is correct
11 Correct 1223 ms 18592 KB Output is correct
12 Correct 1221 ms 18688 KB Output is correct
13 Correct 1216 ms 18696 KB Output is correct
14 Correct 1720 ms 18696 KB Output is correct
15 Correct 2368 ms 18848 KB Output is correct
16 Correct 2376 ms 18880 KB Output is correct
17 Correct 2372 ms 18760 KB Output is correct
18 Correct 2377 ms 18768 KB Output is correct
19 Correct 2388 ms 18904 KB Output is correct
20 Correct 2025 ms 18700 KB Output is correct
21 Correct 1744 ms 18716 KB Output is correct
22 Correct 1921 ms 18656 KB Output is correct
23 Correct 1589 ms 18732 KB Output is correct
24 Correct 2374 ms 18792 KB Output is correct
25 Correct 2386 ms 18872 KB Output is correct
26 Correct 2382 ms 18760 KB Output is correct
27 Correct 2381 ms 18744 KB Output is correct
28 Correct 2367 ms 18828 KB Output is correct
29 Correct 13 ms 18552 KB Output is correct
30 Correct 13 ms 18512 KB Output is correct
31 Correct 2400 ms 18704 KB Output is correct
32 Correct 2402 ms 18892 KB Output is correct
33 Correct 1196 ms 18696 KB Output is correct
34 Correct 603 ms 18632 KB Output is correct
35 Correct 20 ms 18552 KB Output is correct
36 Correct 2404 ms 18888 KB Output is correct
37 Correct 2405 ms 18768 KB Output is correct
38 Correct 2354 ms 18764 KB Output is correct
39 Correct 1714 ms 18732 KB Output is correct
40 Correct 1222 ms 18820 KB Output is correct
41 Correct 887 ms 18692 KB Output is correct
42 Correct 119 ms 18556 KB Output is correct
43 Execution timed out 3064 ms 21144 KB Time limit exceeded
44 Halted 0 ms 0 KB -