#include "circuit.h"
#include <bits/stdc++.h>
#define N 200005
using namespace std;
const int mod = 1e9 + 2022;
struct SegTree{
vector<pair<int,int>> t;
vector<int> lazy;
int n;
void init(int sz ,vector<pair<int,int>> a){
n = sz;
t.assign(4*n,{0,0});
lazy.assign(4*n,0);
build(1,0,n-1,a);
}
void build(int v,int tl,int tr,vector<pair<int,int>> &a){
if(tl == tr){
t[v].first = a[tl].first;
t[v].second = a[tl].second;
return;
}
int tm = (tl + tr)/2;
build(v*2,tl,tm,a);
build(v*2+1,tm+1,tr,a);
t[v].first = (t[v*2].first + t[v*2 + 1].first)%mod;
t[v].second = (t[v*2].second + t[v*2 + 1].second)%mod;
}
void push(int v){
if(lazy[v]){
swap(t[v*2].first,t[v*2].second);
lazy[v*2] ^= 1;
swap(t[v*2+1].first,t[v*2+1].second);
lazy[v*2 + 1] ^= 1;
lazy[v] = 0;
}
}
void upd(int v,int tl,int tr,int l,int r){
if(tr < l || r < tl)
return;
if(l <= tl && tr <= r){
swap(t[v].first,t[v].second);
lazy[v] ^= 1;
return;
}
push(v);
int tm = (tl + tr)/2;
upd(v*2,tl,tm,l,r);
upd(v*2+1,tm+1,tr,l,r);
t[v].first = (t[v*2].first + t[v*2 + 1].first)%mod;
t[v].second = (t[v*2].second + t[v*2 + 1].second)%mod;
}
void upd(int l,int r){
upd(1,0,n-1,l,r);
}
};
vector<int> adj[N];
vector<pair<int,int>> xx;
int val[N];
int n,m;
void dfs1(int v){
val[v] = max(1,(int)adj[v].size());
for(auto u:adj[v]){
dfs1(u);
val[v] = (long long)val[v] * val[u] % mod;
}
}
void dfs2(int v,int num){
vector<int> x;
for(auto u:adj[v]){
x.push_back(val[u]);
}
for(int i = x.size()-2;i>=0;i--){
x[i] = (long long)x[i] * x[i+1] % mod;
}
if(v >= n){
xx[v - n].first = num;
}
int now = num;
for(int i = 0;i<adj[v].size();i++){
int tmp = now;
if(i != adj[v].size() - 1)
tmp = (long long)tmp * x[i+1]%mod;
// cout << v << ' ' << adj[v][i] << ' ' << tmp << endl;
dfs2(adj[v][i],tmp);
now = (long long)now * val[adj[v][i]];
}
}
SegTree t;
void init(int _n, int _m, vector<int> P, vector<int> A){
n = _n;
m = _m;
xx.assign(m,{0,0});
for(int i = 1;i<n+m;i++){
adj[P[i]].push_back(i);
}
dfs1(0);
dfs2(0,1);
for(int i = 0;i<m;i++){
// cout << i << ' ' << xx[i].first << endl;
if(A[i] == 0)
swap(xx[i].first,xx[i].second);
}
t.init(m,xx);
}
int count_ways(int L, int R) {
t.upd(L-n,R-n);
return t.t[1].first;
}
Compilation message
circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0;i<adj[v].size();i++){
| ~^~~~~~~~~~~~~~
circuit.cpp:81:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | if(i != adj[v].size() - 1)
| ~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4876 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '42773112' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4876 KB |
Output is correct |
10 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '42773112' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
562 ms |
9040 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-516285398' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
562 ms |
9040 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-516285398' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4876 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '42773112' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4876 KB |
Output is correct |
10 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '42773112' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4876 KB |
Output is correct |
10 |
Incorrect |
3 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '42773112' |
11 |
Halted |
0 ms |
0 KB |
- |