QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44337 | #4564. Digital Circuit | Crysfly | 0 | 2ms | 17064kb | C++11 | 3.5kb | 2022-08-15 20:10:32 | 2022-08-15 20:10:33 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for( int i=(a);i<=(b);++i)
#define Rep(i,a,b) for( int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000002022
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,m,fa[maxn],a[maxn];
vi e[maxn];
modint f[maxn],g[maxn],val[maxn];
modint t[maxn<<2],s[maxn<<2]; int rev[maxn<<2];
void up(int p){t[p]=t[p<<1]+t[p<<1|1];}
void build(int p,int l,int r){
if(l==r){
s[p]=val[l];
t[p]=a[l]*s[p];
return;
}
int mid=l+r>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
s[p]=s[p<<1]+s[p<<1|1]; up(p);
}
void pushr(int p){
rev[p]^=1;
t[p]=s[p]-t[p];
}
void down(int p){
if(rev[p])
pushr(p<<1),pushr(p<<1|1),rev[p]=0;
}
void dfs1(int u){
if(!e[u].size())return f[u]=1,void();
f[u]=e[u].size();
for(auto v:e[u])dfs1(v),f[u]*=f[v];
}
void dfs2(int u){
if(!e[u].size())return;
int siz=e[u].size();
vector<modint>pre(siz,0),suf(siz,0);
pre[0]=1; For(i,1,siz-1)pre[i]=pre[i-1]*f[i-1];
suf[siz-1]=1; Rep(i,siz-2,0)suf[i]=suf[i+1]*f[i+1];
For(i,0,siz-1){
int v=e[u][i];
g[v]=g[u]*pre[i]*suf[i];
dfs2(v);
}
}
void mdf(int p,int l,int r,int nl,int nr){
if(l>=nl&&r<=nr)return pushr(p);
int mid=l+r>>1; down(p);
if(nl<=mid)mdf(p<<1,l,mid,nl,nr);
if(nr>mid)mdf(p<<1|1,mid+1,r,nl,nr); up(p);
}
void init(int nn,int mm,vi P,vi A)
{
n=nn,m=mm;
For(i,1,n+m-1)e[fa[i]=P[i]].pb(i);
For(i,0,m-1)a[i]=A[i];
dfs1(1),g[1]=1,dfs2(1);
For(i,0,m-1)val[i]=g[i+n];
build(1,0,m-1);
}
int count_ways(int l,int r){
mdf(1,0,m-1,l,r);
return t[1].x;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 17064kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
0 0 0 0 0
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 17028kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
0 0 0 0 0
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Runtime Error
Test #43:
score: 0
Runtime Error
input:
32767 32768 -1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%