Submission #1077479

#TimeUsernameProblemLanguageResultExecution timeMemory
1077479Faisal_SaqibDigital Circuit (IOI22_circuit)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll NP=2e5+100,mod=1e9+2022; ll n,m,p[NP],a[NP]; vector<ll> ma[NP]; ll dp[NP][2],lazy[NP],dp1[NP][2]; void compute(int x=0,bool continue_=1) { dp[x][0]=dp[x][1]=0; dp1[x][0]=dp1[x][1]=0; if(n<=x){ dp[x][a[x-n]]=1; dp1[x][1-a[x-n]]=1; return; } int sz=ma[x].size(); vector<int> tmp(sz+1); // DP 1 tmp[0]=1; for(auto y:ma[x]) { if(continue_) compute(y); for(int j=sz;j>=0;j--) { if(j==0) { tmp[j]=(tmp[j]*dp[y][0])%mod; } else { tmp[j]=(tmp[j]*dp[y][0])%mod; tmp[j]=(tmp[j] + ((tmp[j-1]*dp[y][1])%mod))%mod; } } } int sm=0; for(int j=sz;j>=1;j--) { sm = ( sm + tmp[j] ) % mod; dp[x][1] = ( dp[x][1] + sm ) % mod; } sm=tmp[0]; for(int j=1;j<=sz;j++) { dp[x][0] = ( dp[x][0] + sm ) % mod; sm = ( sm + tmp[j] ) % mod; } // Dp 1 for(int j=0;j<=sz;j++)tmp[j]=0; tmp[0]=1; for(auto y:ma[x]) { for(int j=sz;j>=0;j--) { if(j==0) { tmp[j]=(tmp[j]*dp1[y][0])%mod; } else { tmp[j]=(tmp[j]*dp1[y][0])%mod; tmp[j]=(tmp[j] + ((tmp[j-1]*dp1[y][1])%mod))%mod; } } } sm=0; for(int j=sz;j>=1;j--) { sm = ( sm + tmp[j] ) % mod; dp1[x][1] = ( dp1[x][1] + sm ) % mod; } sm=tmp[0]; for(int j=1;j<=sz;j++) { dp1[x][0] = ( dp1[x][0] + sm ) % mod; sm = ( sm + tmp[j] ) % mod; } } void prepro(int x=0){ if(n<=x) { lc[x]=rc[x]=-1; return; } lc[x]=ma[x][0]; rc[x]=ma[x][1]; prepro(lc[x]); prepro(rc[x]); } void push(int v) { lazy[lc[v]]^=lazy[v]; lazy[rc[v]]^=lazy[v]; if(lazy[v]) { swap(dp[v][0],dp1[v][0]); swap(dp[v][1],dp1[v][1]); } } void update(int v,int l,int r,int ql,int qr) { if(qr<l or r<ql) // nothing changes here return; if(ql<=l and r<=qr) // whole subtree to be updated { lazy[v]^=1; return; } push(v); int mid=(l+r)/2; update(lc[v],l,mid,ql,qr); update(rc[v],mid+1,r,ql,qr); compute(v,0); } void init(int N, int M, std::vector<int> P, std::vector<int> A) { n=N,m=M; for(ll i=0;i<n+m;i++) { p[i]=P[i]; if(p[i]!=-1)ma[p[i]].push_back(i); } for(ll j=0;j<m;j++)a[j]=A[j]; prepro(); compute(); } int count_ways(int L, int R) { for(ll i=L-n;i<=R-n;i++)a[i]=(a[i]?0:1); update(0,0,m-1,L-n,R-n); push(0); return (int)dp[0][1]; }

Compilation message (stderr)

circuit.cpp: In function 'void prepro(int)':
circuit.cpp:86:3: error: 'lc' was not declared in this scope; did you mean 'll'?
   86 |   lc[x]=rc[x]=-1;
      |   ^~
      |   ll
circuit.cpp:86:9: error: 'rc' was not declared in this scope
   86 |   lc[x]=rc[x]=-1;
      |         ^~
circuit.cpp:89:2: error: 'lc' was not declared in this scope; did you mean 'll'?
   89 |  lc[x]=ma[x][0];
      |  ^~
      |  ll
circuit.cpp:90:2: error: 'rc' was not declared in this scope
   90 |  rc[x]=ma[x][1];
      |  ^~
circuit.cpp: In function 'void push(int)':
circuit.cpp:96:7: error: 'lc' was not declared in this scope; did you mean 'll'?
   96 |  lazy[lc[v]]^=lazy[v];
      |       ^~
      |       ll
circuit.cpp:97:7: error: 'rc' was not declared in this scope
   97 |  lazy[rc[v]]^=lazy[v];
      |       ^~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:115:9: error: 'lc' was not declared in this scope; did you mean 'l'?
  115 |  update(lc[v],l,mid,ql,qr);
      |         ^~
      |         l
circuit.cpp:116:9: error: 'rc' was not declared in this scope; did you mean 'r'?
  116 |  update(rc[v],mid+1,r,ql,qr);
      |         ^~
      |         r