제출 #836259

#제출 시각아이디문제언어결과실행 시간메모리
836259Trumling디지털 회로 (IOI22_circuit)C++17
7 / 100
3019 ms5840 KiB
#include "circuit.h" #include<bits/stdc++.h> using namespace std; #define F first #define S second #define all(x) x.begin(),x.end() typedef long long ll; #define pb push_back #define MOD 1000002022 ll m,n; vector<vector<int>>g; vector<pair<ll,ll>> tree; vector<int>a; void build(int start) { if(g[start].size()==1) { tree[start]={0,0}; if(a[start]) tree[start].F=1; else tree[start].S=1; //cout<<start<<" |"<<tree[start].F<<' '<<tree[start].S<<'\n'; return ; } ll l,r; for(auto x:g[start]) if(x>start) build(x); ll add=0; if(start==0) add=-1; l=g[start][1+add]; r=g[start][2+add]; tree[start].F=((tree[l].F*tree[r].F)%MOD + (tree[l].F*(tree[r].F+tree[r].S))%MOD + (tree[l].S*tree[r].F)%MOD)%MOD; tree[start].S=((tree[l].S*(tree[r].F+tree[r].S))%MOD + (tree[l].F*tree[r].S)%MOD + (tree[l].S*tree[r].S)%MOD)%MOD; // cout<<start<<" |"<<tree[start].F<<' '<<tree[start].S<<'\n'; return ; } void init(int N, int M, vector<int> P, vector<int> A) { n=N; m=M; tree.assign(n+m,{0,0}); g.assign(N+M,vector<int>()); a.assign(N+M,0); for(int i=0;i<m;i++) a[i+n]=A[i]; for(int i=1;i<N+M;i++) { g[i].pb(P[i]); g[P[i]].pb(i); } } int count_ways(int L, int R) { for(int i=L;i<=R;i++) a[i]=1-a[i]; build(0); //cout<<tree[0].F<<' '<<tree[0].S; return tree[0].F; }
#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...