#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back
void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}
template<typename T,typename V>
void PRINT(pair<T,V>& x){
cerr<<"{";
PRINT(x.fi);
cerr<<",";
PRINT(x.se);
cerr<<"}";
}
template<typename T>
void PRINT(T &x){
int id=0;
cerr<<"{";
for(auto _i:x){
cerr<<(id++ ? "," : "");
PRINT(_i);
}
cerr<<"}";
}
void _PRINT(){
cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
PRINT(h);
if(sizeof...(t)) cerr<<", ";
_PRINT(t...);
}
#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)
const int mxN=1e5;
const ll MOD=1000002022;
vector<ll> contribute(mxN,1),sub(mxN,1);
vector<int> lazy(4*mxN),adj[mxN];
int N,M;
void Md(ll& x){
if(x>=MOD) x%=MOD;
if(x<0) x+=MOD;
}
struct Node{
ll tmp,all;
}; vector<Node> seg(4*mxN);
Node Merge(Node& n1,Node& n2){
Node ret={n1.tmp+n2.tmp,n1.all+n2.all};
Md(ret.tmp); Md(ret.all);
return ret;
}
void Propagate(int node,int l,int r){
if(lazy[node]){
seg[node].tmp=seg[node].all-seg[node].tmp; Md(seg[node].tmp);
if(l<=r){
lazy[2*node]^=1;
lazy[2*node+1]^=1;
}
lazy[node]=0;
}
}
void Build(int node,int l,int r,vector<int>& A){
if(l==r){
seg[node].tmp=(A[l] ? contribute[l+N] : 0);
seg[node].all=contribute[l+N];
return;
}
Build(2*node,l,mid,A); Build(2*node+1,mid+1,r,A);
seg[node]=Merge(seg[2*node],seg[2*node+1]);
}
void Update(int node,int l,int r,int L,int R){
if(l>r) return;
Propagate(node,l,r);
if(L>r || R<l) return;
if(L<=l && r<=R){
lazy[node]=1;
Propagate(node,l,r);
return;
}
Update(2*node,l,mid,L,R); Update(2*node+1,mid+1,r,L,R);
seg[node]=Merge(seg[2*node],seg[2*node+1]);
}
void DfsSub(int node,int par){
int c=0;
for(int v:adj[node]){
if(v!=par){
DfsSub(v,node);
sub[node]*=sub[v]; Md(sub[node]);
c++;
}
}
if(0<=node && node<N){
sub[node]*=c; Md(sub[node]);
}
}
void DfsCon(int node,int par){
if(par!=-1){
contribute[node]*=contribute[par]; Md(contribute[node]);
}
vector<ll> pref(sz(adj[node]),1),suf(sz(adj[node]),1);
for(int i=0;i<sz(adj[node]);i++){
int v=adj[node][i];
if(i){
pref[i]=pref[i-1]; Md(pref[i]);
}
if(v!=par){
pref[i]*=sub[v]; Md(pref[i]);
}
}
for(int i=sz(adj[node])-1;i>=0;i--){
int v=adj[node][i];
if(i!=sz(adj[node])-1){
suf[i]=suf[i+1]; Md(suf[i]);
}
if(v!=par){
suf[i]*=sub[v]; Md(suf[i]);
}
}
for(int i=0;i<sz(adj[node]);i++){
int v=adj[node][i];
if(v!=par){
if(i){
contribute[v]*=pref[i-1]; Md(contribute[v]);
}
if(i<sz(adj[node])-1){
contribute[v]*=suf[i+1]; Md(contribute[v]);
}
}
}
for(int v:adj[node]){
if(v!=par){
DfsCon(v,node);
}
}
}
void init(int N1, int M1, std::vector<int> P, std::vector<int> A) {
N=N1,M=M1;
for(int i=1;i<N+M;i++){
adj[P[i]].pb(i);
}
DfsSub(0,-1);
DfsCon(0,-1);
Build(1,0,M-1,A);
}
int count_ways(int L, int R) {
Update(1,0,M-1,L-N,R-N);
return seg[1].tmp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
4 ms |
12376 KB |
Output is correct |
3 |
Correct |
4 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12376 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
4 ms |
12120 KB |
Output is correct |
8 |
Correct |
4 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12120 KB |
Output is correct |
2 |
Correct |
4 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
4 ms |
12120 KB |
Output is correct |
6 |
Correct |
4 ms |
12120 KB |
Output is correct |
7 |
Correct |
4 ms |
12120 KB |
Output is correct |
8 |
Correct |
4 ms |
12120 KB |
Output is correct |
9 |
Correct |
4 ms |
12120 KB |
Output is correct |
10 |
Correct |
4 ms |
12376 KB |
Output is correct |
11 |
Correct |
4 ms |
12376 KB |
Output is correct |
12 |
Correct |
3 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
4 ms |
12376 KB |
Output is correct |
3 |
Correct |
4 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12376 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
4 ms |
12120 KB |
Output is correct |
8 |
Correct |
4 ms |
12376 KB |
Output is correct |
9 |
Correct |
4 ms |
12120 KB |
Output is correct |
10 |
Correct |
4 ms |
12120 KB |
Output is correct |
11 |
Correct |
3 ms |
12120 KB |
Output is correct |
12 |
Correct |
3 ms |
12120 KB |
Output is correct |
13 |
Correct |
4 ms |
12120 KB |
Output is correct |
14 |
Correct |
4 ms |
12120 KB |
Output is correct |
15 |
Correct |
4 ms |
12120 KB |
Output is correct |
16 |
Correct |
4 ms |
12120 KB |
Output is correct |
17 |
Correct |
4 ms |
12120 KB |
Output is correct |
18 |
Correct |
4 ms |
12376 KB |
Output is correct |
19 |
Correct |
4 ms |
12376 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
4 ms |
12120 KB |
Output is correct |
22 |
Correct |
4 ms |
12376 KB |
Output is correct |
23 |
Correct |
4 ms |
12120 KB |
Output is correct |
24 |
Correct |
4 ms |
12120 KB |
Output is correct |
25 |
Correct |
4 ms |
12120 KB |
Output is correct |
26 |
Correct |
4 ms |
12120 KB |
Output is correct |
27 |
Correct |
5 ms |
12120 KB |
Output is correct |
28 |
Correct |
5 ms |
12120 KB |
Output is correct |
29 |
Correct |
4 ms |
12120 KB |
Output is correct |
30 |
Correct |
3 ms |
12132 KB |
Output is correct |
31 |
Correct |
5 ms |
12376 KB |
Output is correct |
32 |
Correct |
4 ms |
12120 KB |
Output is correct |
33 |
Correct |
5 ms |
12120 KB |
Output is correct |
34 |
Correct |
4 ms |
12120 KB |
Output is correct |
35 |
Correct |
3 ms |
12120 KB |
Output is correct |
36 |
Correct |
4 ms |
12376 KB |
Output is correct |
37 |
Correct |
4 ms |
12376 KB |
Output is correct |
38 |
Correct |
3 ms |
12376 KB |
Output is correct |
39 |
Correct |
4 ms |
12120 KB |
Output is correct |
40 |
Correct |
4 ms |
12120 KB |
Output is correct |
41 |
Correct |
4 ms |
12120 KB |
Output is correct |
42 |
Correct |
5 ms |
12176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
367 ms |
13864 KB |
Output is correct |
2 |
Execution timed out |
3030 ms |
23088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
367 ms |
13864 KB |
Output is correct |
2 |
Execution timed out |
3030 ms |
23088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12120 KB |
Output is correct |
2 |
Correct |
4 ms |
12120 KB |
Output is correct |
3 |
Correct |
3 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
4 ms |
12120 KB |
Output is correct |
6 |
Correct |
4 ms |
12120 KB |
Output is correct |
7 |
Correct |
4 ms |
12120 KB |
Output is correct |
8 |
Correct |
4 ms |
12120 KB |
Output is correct |
9 |
Correct |
4 ms |
12120 KB |
Output is correct |
10 |
Correct |
4 ms |
12376 KB |
Output is correct |
11 |
Correct |
4 ms |
12376 KB |
Output is correct |
12 |
Correct |
3 ms |
12120 KB |
Output is correct |
13 |
Correct |
367 ms |
13864 KB |
Output is correct |
14 |
Execution timed out |
3030 ms |
23088 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
4 ms |
12376 KB |
Output is correct |
3 |
Correct |
4 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12376 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
4 ms |
12120 KB |
Output is correct |
8 |
Correct |
4 ms |
12376 KB |
Output is correct |
9 |
Correct |
4 ms |
12120 KB |
Output is correct |
10 |
Correct |
4 ms |
12120 KB |
Output is correct |
11 |
Correct |
3 ms |
12120 KB |
Output is correct |
12 |
Correct |
3 ms |
12120 KB |
Output is correct |
13 |
Correct |
4 ms |
12120 KB |
Output is correct |
14 |
Correct |
4 ms |
12120 KB |
Output is correct |
15 |
Correct |
4 ms |
12120 KB |
Output is correct |
16 |
Correct |
4 ms |
12120 KB |
Output is correct |
17 |
Correct |
4 ms |
12120 KB |
Output is correct |
18 |
Correct |
4 ms |
12376 KB |
Output is correct |
19 |
Correct |
4 ms |
12376 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
4 ms |
12120 KB |
Output is correct |
22 |
Correct |
4 ms |
12376 KB |
Output is correct |
23 |
Correct |
4 ms |
12120 KB |
Output is correct |
24 |
Correct |
4 ms |
12120 KB |
Output is correct |
25 |
Correct |
4 ms |
12120 KB |
Output is correct |
26 |
Correct |
4 ms |
12120 KB |
Output is correct |
27 |
Correct |
5 ms |
12120 KB |
Output is correct |
28 |
Correct |
5 ms |
12120 KB |
Output is correct |
29 |
Correct |
4 ms |
12120 KB |
Output is correct |
30 |
Correct |
3 ms |
12132 KB |
Output is correct |
31 |
Correct |
5 ms |
12376 KB |
Output is correct |
32 |
Correct |
4 ms |
12120 KB |
Output is correct |
33 |
Correct |
5 ms |
12120 KB |
Output is correct |
34 |
Correct |
4 ms |
12120 KB |
Output is correct |
35 |
Correct |
3 ms |
12120 KB |
Output is correct |
36 |
Correct |
4 ms |
12376 KB |
Output is correct |
37 |
Correct |
4 ms |
12376 KB |
Output is correct |
38 |
Correct |
3 ms |
12376 KB |
Output is correct |
39 |
Correct |
4 ms |
12120 KB |
Output is correct |
40 |
Correct |
4 ms |
12120 KB |
Output is correct |
41 |
Correct |
4 ms |
12120 KB |
Output is correct |
42 |
Correct |
5 ms |
12176 KB |
Output is correct |
43 |
Correct |
420 ms |
12336 KB |
Output is correct |
44 |
Correct |
593 ms |
12376 KB |
Output is correct |
45 |
Correct |
573 ms |
12532 KB |
Output is correct |
46 |
Correct |
518 ms |
12452 KB |
Output is correct |
47 |
Correct |
599 ms |
12456 KB |
Output is correct |
48 |
Correct |
566 ms |
12456 KB |
Output is correct |
49 |
Correct |
595 ms |
12464 KB |
Output is correct |
50 |
Correct |
526 ms |
12460 KB |
Output is correct |
51 |
Correct |
495 ms |
12384 KB |
Output is correct |
52 |
Correct |
535 ms |
12448 KB |
Output is correct |
53 |
Correct |
474 ms |
13400 KB |
Output is correct |
54 |
Correct |
561 ms |
12448 KB |
Output is correct |
55 |
Correct |
582 ms |
12352 KB |
Output is correct |
56 |
Correct |
569 ms |
12344 KB |
Output is correct |
57 |
Correct |
569 ms |
12300 KB |
Output is correct |
58 |
Correct |
567 ms |
13448 KB |
Output is correct |
59 |
Correct |
536 ms |
13564 KB |
Output is correct |
60 |
Correct |
509 ms |
13568 KB |
Output is correct |
61 |
Correct |
573 ms |
12600 KB |
Output is correct |
62 |
Correct |
552 ms |
12320 KB |
Output is correct |
63 |
Correct |
568 ms |
12304 KB |
Output is correct |
64 |
Correct |
562 ms |
12332 KB |
Output is correct |
65 |
Correct |
280 ms |
12284 KB |
Output is correct |
66 |
Correct |
560 ms |
12400 KB |
Output is correct |
67 |
Correct |
600 ms |
12400 KB |
Output is correct |
68 |
Correct |
551 ms |
12400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
4 ms |
12376 KB |
Output is correct |
3 |
Correct |
4 ms |
12120 KB |
Output is correct |
4 |
Correct |
3 ms |
12120 KB |
Output is correct |
5 |
Correct |
3 ms |
12376 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
4 ms |
12120 KB |
Output is correct |
8 |
Correct |
4 ms |
12376 KB |
Output is correct |
9 |
Correct |
4 ms |
12120 KB |
Output is correct |
10 |
Correct |
4 ms |
12120 KB |
Output is correct |
11 |
Correct |
3 ms |
12120 KB |
Output is correct |
12 |
Correct |
3 ms |
12120 KB |
Output is correct |
13 |
Correct |
4 ms |
12120 KB |
Output is correct |
14 |
Correct |
4 ms |
12120 KB |
Output is correct |
15 |
Correct |
4 ms |
12120 KB |
Output is correct |
16 |
Correct |
4 ms |
12120 KB |
Output is correct |
17 |
Correct |
4 ms |
12120 KB |
Output is correct |
18 |
Correct |
4 ms |
12376 KB |
Output is correct |
19 |
Correct |
4 ms |
12376 KB |
Output is correct |
20 |
Correct |
3 ms |
12120 KB |
Output is correct |
21 |
Correct |
4 ms |
12120 KB |
Output is correct |
22 |
Correct |
4 ms |
12376 KB |
Output is correct |
23 |
Correct |
4 ms |
12120 KB |
Output is correct |
24 |
Correct |
4 ms |
12120 KB |
Output is correct |
25 |
Correct |
4 ms |
12120 KB |
Output is correct |
26 |
Correct |
4 ms |
12120 KB |
Output is correct |
27 |
Correct |
5 ms |
12120 KB |
Output is correct |
28 |
Correct |
5 ms |
12120 KB |
Output is correct |
29 |
Correct |
4 ms |
12120 KB |
Output is correct |
30 |
Correct |
3 ms |
12132 KB |
Output is correct |
31 |
Correct |
5 ms |
12376 KB |
Output is correct |
32 |
Correct |
4 ms |
12120 KB |
Output is correct |
33 |
Correct |
5 ms |
12120 KB |
Output is correct |
34 |
Correct |
4 ms |
12120 KB |
Output is correct |
35 |
Correct |
3 ms |
12120 KB |
Output is correct |
36 |
Correct |
4 ms |
12376 KB |
Output is correct |
37 |
Correct |
4 ms |
12376 KB |
Output is correct |
38 |
Correct |
3 ms |
12376 KB |
Output is correct |
39 |
Correct |
4 ms |
12120 KB |
Output is correct |
40 |
Correct |
4 ms |
12120 KB |
Output is correct |
41 |
Correct |
4 ms |
12120 KB |
Output is correct |
42 |
Correct |
5 ms |
12176 KB |
Output is correct |
43 |
Correct |
367 ms |
13864 KB |
Output is correct |
44 |
Execution timed out |
3030 ms |
23088 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |