제출 #746562

#제출 시각아이디문제언어결과실행 시간메모리
746562Rafi22디지털 회로 (IOI22_circuit)C++17
18 / 100
3062 ms21264 KiB
#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];
    seg[v][1]=seg[2*v][1]+seg[2*v+1][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[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]%mod;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...