QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44238 | #4564. Digital Circuit | Remocuz | 0 | 61ms | 11480kb | C++20 | 3.5kb | 2022-08-14 10:08:23 | 2022-08-14 10:08:24 |
Judging History
answer
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 1000002022
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define inc(x,y) x=add(x,y)
#define dec(x,y) x=sub(x,y)
#define N 200005
vector<int> G[N];
int cnt[N],siz[N],f[N];
void dfs1(int u)
{
cnt[u]=1,siz[u]=1;
for(int v:G[u]) dfs1(v),cnt[u]=mul(cnt[u],cnt[v]),siz[u]+=siz[v];
if(!G[u].empty()) cnt[u]=mul(cnt[u],(int)G[u].size());
}
void dfs2(int u,int fv)
{
f[u]=fv;
if(G[u].empty()) return ;
int s=(int)G[u].size();
vector<int> pre(s),suf(s);
pre[0]=cnt[G[u][0]]; for(int i=1;i<s;i++) pre[i]=mul(pre[i-1],cnt[G[u][i]]);
suf[s-1]=cnt[G[u][s-1]]; for(int i=s-2;i>=0;i--) suf[i]=mul(suf[i+1],cnt[G[u][i]]);
// print(pre),print(suf);
for(int i=0;i<s;i++)
{
int cv=mul(i==0?1:pre[i-1],i==s-1?1:suf[i+1],fv);
dfs2(G[u][i],cv);
}
}
int cur[N],w[N],n,m;
struct SMT
{
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((l+r)/2)
int t[N*4][2],tag[N*4];
void pushup(int u) {t[u][0]=add(t[ls][0],t[rs][0]),t[u][1]=add(t[ls][1],t[rs][1]);}
void pushdown(int u)
{
if(tag[u])
{
swap(t[u][0],t[u][1]);
tag[ls]^=1,tag[rs]^=1;
tag[u]=0;
}
}
void build(int u,int l,int r)
{
if(l==r)
{
t[u][0]=0,t[u][1]=w[l];
tag[u]=cur[l];
return ;
}
build(ls,l,mid),build(rs,mid+1,r);
pushup(u);
}
void update(int u,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
{
tag[u]^=1;
return ;
}
pushdown(u);
if(mid>=L) update(ls,l,mid,L,R);
if(mid<R) update(rs,mid+1,r,L,R);
pushup(u);
}
int query(int u,int l,int r,int L,int R)
{
if(L<=l&&r<=R) return t[u][tag[u]];
pushdown(u); int ans=0;
if(mid>=L) ans=add(ans,query(ls,l,mid,L,R));
if(mid<R) ans=add(ans,query(rs,mid+1,r,L,R));
return ans;
}
}smt;
void init(int _n, int _m, std::vector<int> fa, std::vector<int> A) {
n=_n,m=_m;
for(int i=1;i<n+m;i++) G[fa[i]].pb(i);
dfs1(0);
// for(int i=0;i<n+m;i++) printf("%d%c",cnt[i]," \n"[i==n+m-1]);
dfs2(0,1);
// for(int i=0;i<n+m;i++) printf("%d%c",f[i]," \n"[i==n+m-1]);
for(int i=0;i<m;i++) cur[i]=A[i],w[i]=f[i+n];
smt.build(1,0,m-1);
}
int count_ways(int L, int R) {
int l=L-n,r=R-n;
smt.update(1,0,m-1,l,r);
return smt.query(1,0,m-1,l,r);
}
#undef N
#ifdef wasa855
#include "circuit.h"
#include <cassert>
#include <cstdio>
#include <vector>
int main() {
int N, M, Q;
assert(3 == scanf("%d %d %d", &N, &M, &Q));
std::vector<int> P(N + M), A(M);
for (int i = 0; i < N + M; ++i) {
assert(1 == scanf("%d", &P[i]));
}
for (int j = 0; j < M; ++j) {
assert(1 == scanf("%d", &A[j]));
}
init(N, M, P, A);
for (int i = 0; i < Q; ++i) {
int L, R;
assert(2 == scanf("%d %d", &L, &R));
printf("%d\n", count_ways(L, R));
}
return 0;
}
#endif
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: 8408kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
1 1 2 1 2
result:
wrong answer 4th lines differ - expected: '2', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 5ms
memory: 8500kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
1 1 2 1 2
result:
wrong answer 4th lines differ - expected: '2', found: '1'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #43:
score: 0
Wrong Answer
time: 61ms
memory: 11480kb
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:
37399904 0 37399904 37399904 37399904 0 0 37399904 0 37399904 37399904 0 0 0 0 0 37399904 37399904 37399904 0 0 37399904 37399904 37399904 37399904 0 0 0 0 0 0 0 37399904 37399904 0 0 0 37399904 0 37399904 0 37399904 0 37399904 37399904 0 37399904 0 37399904 37399904 37399904 0 0 0 37399904 37399904...
result:
wrong answer 3rd lines differ - expected: '431985922', found: '37399904'
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%