#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "circuit.h"
const ll MOD = 1000002022;
bool test5;
int n, sz;
VVI gp;
VI val;
VL dpa; // sev
VL dpb; // spitak
void dfs(int u);
void init(int N, int M, VI P, VI A) {
n = N + M;
sz = M;
gp = VVI(n);
rep(u, n) if (u) gp[P[u]].pb(u);
val = VI(n);
rep(u, M) val[u+N] = A[u];
test5 = true;
replr(i, 1, n-1) if (P[i] != (i-1)/2) {
test5 = false;
break;
}
if (M != N+1) test5 = false;
if (M & (M-1)) test5 = false;
if (test5) {
/*cout << "TEST 5" << endl;*/
dpa = dpb = VL(n);
dfs(0);
}
}
VL subsets(VL& a, VL& b) {
int n = a.size();
VVL dp(n+1, VL(n+1));
dp[0][0] = 1;
replr(j, 1, n) dp[j][0] = dp[j-1][0]*b[j-1]%MOD;
replr(i, 1, n) replr(j, 1, n) {
dp[i][j] = dp[i-1][j-1]*a[i-1]%MOD + dp[i-1][j]*b[i-1]%MOD;
dp[i][j] %= MOD;
}
VL ret(n+1);
replr(i, 0, n) ret[i] = dp[n][i];
return ret;
}
void recalc(int u) {
dpa[u] = dpb[u] = 0;
if (gp[u].size() == 0) {
if (val[u]) dpa[u] = 1;
else dpb[u] = 1;
return;
}
VL a, b;
for (int v : gp[u]) {
a.pb(dpa[v]);
b.pb(dpb[v]);
}
int c = gp[u].size();
VL s = subsets(a, b);
replr(i, 0, c) {
dpa[u] += s[i]*i % MOD;
dpa[u] %= MOD;
dpb[u] += s[i]*(c-i) % MOD;
dpb[u] %= MOD;
}
}
void dfs(int u = 0) {
for (int v : gp[u]) dfs(v);
recalc(u);
}
void upd(int N, int L, int R, int i) {
if (i < L || i > R) return;
if (L == R) {
swap(dpa[N], dpb[N]);
return;
}
int M = (L + R) / 2;
upd(2*N+1, L, M, i);
upd(2*N+2, M+1, R, i);
recalc(N);
}
int count_ways(int L, int R) {
if (test5) {
replr(ind, L, R) {
upd(0, sz-1, 2*(sz-1), ind);
}
} else {
replr(i, L, R) val[i] = !val[i];
dpa = dpb = VL(n);
dfs();
}
return dpa[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
36 ms |
7976 KB |
Output is correct |
4 |
Correct |
36 ms |
8380 KB |
Output is correct |
5 |
Correct |
39 ms |
8380 KB |
Output is correct |
6 |
Correct |
37 ms |
8376 KB |
Output is correct |
7 |
Correct |
37 ms |
8380 KB |
Output is correct |
8 |
Correct |
36 ms |
8372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
36 ms |
7976 KB |
Output is correct |
4 |
Correct |
36 ms |
8380 KB |
Output is correct |
5 |
Correct |
39 ms |
8380 KB |
Output is correct |
6 |
Correct |
37 ms |
8376 KB |
Output is correct |
7 |
Correct |
37 ms |
8380 KB |
Output is correct |
8 |
Correct |
36 ms |
8372 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
444 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
3 ms |
344 KB |
Output is correct |
29 |
Correct |
38 ms |
8420 KB |
Output is correct |
30 |
Correct |
33 ms |
8380 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
7 ms |
872 KB |
Output is correct |
36 |
Correct |
2 ms |
600 KB |
Output is correct |
37 |
Correct |
33 ms |
8464 KB |
Output is correct |
38 |
Correct |
39 ms |
8468 KB |
Output is correct |
39 |
Correct |
2 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
380 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
717 ms |
4952 KB |
Output is correct |
2 |
Correct |
1079 ms |
9560 KB |
Output is correct |
3 |
Correct |
1095 ms |
9560 KB |
Output is correct |
4 |
Correct |
1106 ms |
9560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
717 ms |
4952 KB |
Output is correct |
2 |
Correct |
1079 ms |
9560 KB |
Output is correct |
3 |
Correct |
1095 ms |
9560 KB |
Output is correct |
4 |
Correct |
1106 ms |
9560 KB |
Output is correct |
5 |
Execution timed out |
3059 ms |
4952 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
717 ms |
4952 KB |
Output is correct |
14 |
Correct |
1079 ms |
9560 KB |
Output is correct |
15 |
Correct |
1095 ms |
9560 KB |
Output is correct |
16 |
Correct |
1106 ms |
9560 KB |
Output is correct |
17 |
Execution timed out |
3059 ms |
4952 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
36 ms |
7976 KB |
Output is correct |
4 |
Correct |
36 ms |
8380 KB |
Output is correct |
5 |
Correct |
39 ms |
8380 KB |
Output is correct |
6 |
Correct |
37 ms |
8376 KB |
Output is correct |
7 |
Correct |
37 ms |
8380 KB |
Output is correct |
8 |
Correct |
36 ms |
8372 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
444 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
3 ms |
344 KB |
Output is correct |
29 |
Correct |
38 ms |
8420 KB |
Output is correct |
30 |
Correct |
33 ms |
8380 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
7 ms |
872 KB |
Output is correct |
36 |
Correct |
2 ms |
600 KB |
Output is correct |
37 |
Correct |
33 ms |
8464 KB |
Output is correct |
38 |
Correct |
39 ms |
8468 KB |
Output is correct |
39 |
Correct |
2 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
380 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
2 ms |
344 KB |
Output is correct |
43 |
Execution timed out |
3080 ms |
856 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
36 ms |
7976 KB |
Output is correct |
4 |
Correct |
36 ms |
8380 KB |
Output is correct |
5 |
Correct |
39 ms |
8380 KB |
Output is correct |
6 |
Correct |
37 ms |
8376 KB |
Output is correct |
7 |
Correct |
37 ms |
8380 KB |
Output is correct |
8 |
Correct |
36 ms |
8372 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
444 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
3 ms |
344 KB |
Output is correct |
29 |
Correct |
38 ms |
8420 KB |
Output is correct |
30 |
Correct |
33 ms |
8380 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
7 ms |
872 KB |
Output is correct |
36 |
Correct |
2 ms |
600 KB |
Output is correct |
37 |
Correct |
33 ms |
8464 KB |
Output is correct |
38 |
Correct |
39 ms |
8468 KB |
Output is correct |
39 |
Correct |
2 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
380 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
2 ms |
344 KB |
Output is correct |
43 |
Correct |
717 ms |
4952 KB |
Output is correct |
44 |
Correct |
1079 ms |
9560 KB |
Output is correct |
45 |
Correct |
1095 ms |
9560 KB |
Output is correct |
46 |
Correct |
1106 ms |
9560 KB |
Output is correct |
47 |
Execution timed out |
3059 ms |
4952 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |