Submission #1013281

# Submission time Handle Problem Language Result Execution time Memory
1013281 2024-07-03T11:18:22 Z andrei_iorgulescu Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 14424 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

int modulo = (int)1e9 + 2022;

int n,m;
int t[200005];
vector<int> f[200005];
int a[100005];
int v[100005];
int dp[200005],s[200005],sp[200005];
int ff[200005];

void dfs(int nod)
{
    if (nod > n)
        s[nod] = 1;
    else
    {
        for (auto fiu : f[nod])
            dfs(fiu);
        s[nod] = f[nod].size();
        for (auto fiu : f[nod])
            s[nod] = 1ll * s[nod] * s[fiu] % modulo;
        vector<int> pref_prod(f[nod].size()),suf_prod(f[nod].size());
        pref_prod[0] = s[f[nod][0]];
        for (int i = 1; i < f[nod].size(); i++)
            pref_prod[i] = 1ll * pref_prod[i - 1] * s[f[nod][i]] % modulo;
        suf_prod[f[nod].size() - 1] = s[f[nod].back()];
        for (int i = (int)f[nod].size() - 2; i >= 0; i--)
            suf_prod[i] = 1ll * suf_prod[i + 1] * s[f[nod][i]] % modulo;
        for (int i = 0; i < f[nod].size(); i++)
        {
            sp[f[nod][i]] = 1;
            if (i != 0)
                sp[f[nod][i]] = pref_prod[i - 1];
            if (i + 1 != f[nod].size())
                sp[f[nod][i]] = 1ll * sp[f[nod][i]] * suf_prod[i + 1] % modulo;
        }
    }
}

void dfs2(int nod)
{
    if (nod == 1)
        ff[nod] = 1;
    else
        ff[nod] = 1ll * sp[nod] * ff[t[nod]] % modulo;
    for (auto fiu : f[nod])
        dfs2(fiu);
}

int aint[400005],sm[400005];
bool lazy[400005];

void build(int nod,int l,int r)
{
    if (l == r)
    {
        sm[nod] = v[l];
        aint[nod] = v[l] * a[l];
    }
    else
    {
        int mij = (l + r) / 2;
        build(2 * nod,l,mij);
        build(2 * nod + 1,mij + 1,r);
        sm[nod] = (sm[2 * nod] + sm[2 * nod + 1]) % modulo;
        aint[nod] = (aint[2 * nod] + aint[2 * nod + 1]) % modulo;
    }
}

void prop(int nod,int l,int r)
{
    if (!lazy[nod])
        return;
    lazy[nod] = false;
    if (l == r)
        return;
    aint[2 * nod] = (sm[2 * nod] + modulo - aint[2 * nod]) % modulo;
    aint[2 * nod + 1] = (sm[2 * nod + 1] + modulo - aint[2 * nod + 1]) % modulo;
    lazy[2 * nod] ^= 1;
    lazy[2 * nod + 1] ^= 1;
}

void update(int nod,int l,int r,int st,int dr)
{
    prop(nod,l,r);
    if (r < st or dr < l)
        return;
    if (st <= l and r <= dr)
    {
        aint[nod] = (sm[nod] + modulo - aint[nod]) % modulo;
        lazy[nod] = true;
        return;
    }
    int mij = (l + r) / 2;
    update(2 * nod,l,mij,st,dr);
    update(2 * nod + 1,mij + 1,r,st,dr);
    aint[nod] = (aint[2 * nod] + aint[2 * nod + 1]) % modulo;
}

void init(int N, int M, vector<int> P, vector<int> A)
{
    n = N;
    m = M;
    for (int i = 0; i < P.size(); i++)
        P[i]++;
    for (int i = 0; i < P.size(); i++)
    {
        t[i + 1] = P[i];
        f[P[i]].push_back(i + 1);
    }
    for (int i = 1; i <= m; i++)
        a[i] = A[i - 1];
    dfs(1);
    dfs2(1);
    for (int i = 1; i <= m; i++)
        v[i] = ff[n + i];
    build(1,1,m);
}

int count_ways(int L, int R)
{
    L++;
    R++;
    L -= n;
    R -= n;
    //update(1,1,m,L,R);
    for (int i = L; i <= R; i++)
        a[i] ^= 1;
    int ans = 0;
    for (int i = 1; i <= m; i++)
        ans = (ans + a[i] * v[i]) % modulo;
    return ans;
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i = 1; i < f[nod].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
circuit.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i = 0; i < f[nod].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
circuit.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if (i + 1 != f[nod].size())
      |                 ~~~~~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:109:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (int i = 0; i < P.size(); i++)
      |                     ~~^~~~~~~~~~
circuit.cpp:111:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int i = 0; i < P.size(); i++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 1 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 1 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 1 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12772 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12888 KB Output is correct
11 Correct 2 ms 12888 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 1 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 1 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 1 ms 12632 KB Output is correct
9 Correct 1 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 12632 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12772 KB Output is correct
14 Correct 2 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12888 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 12632 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12632 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 12632 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 12632 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 12888 KB Output is correct
37 Correct 2 ms 12888 KB Output is correct
38 Correct 3 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 3 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3013 ms 14424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3013 ms 14424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12772 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12888 KB Output is correct
11 Correct 2 ms 12888 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Execution timed out 3013 ms 14424 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 1 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 1 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 1 ms 12632 KB Output is correct
9 Correct 1 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 12632 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12772 KB Output is correct
14 Correct 2 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12888 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 12632 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12632 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 12632 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 12632 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 12888 KB Output is correct
37 Correct 2 ms 12888 KB Output is correct
38 Correct 3 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 3 ms 12632 KB Output is correct
43 Correct 1102 ms 12888 KB Output is correct
44 Correct 1510 ms 12888 KB Output is correct
45 Correct 1648 ms 13048 KB Output is correct
46 Correct 2327 ms 12888 KB Output is correct
47 Correct 2474 ms 12888 KB Output is correct
48 Correct 2424 ms 12884 KB Output is correct
49 Correct 2411 ms 13020 KB Output is correct
50 Correct 2534 ms 12888 KB Output is correct
51 Correct 2490 ms 12888 KB Output is correct
52 Correct 2364 ms 12888 KB Output is correct
53 Correct 533 ms 13400 KB Output is correct
54 Correct 2438 ms 12888 KB Output is correct
55 Correct 2345 ms 12888 KB Output is correct
56 Correct 2381 ms 12888 KB Output is correct
57 Correct 2283 ms 12632 KB Output is correct
58 Correct 2234 ms 13400 KB Output is correct
59 Correct 2216 ms 13540 KB Output is correct
60 Correct 2500 ms 7356 KB Output is correct
61 Correct 1325 ms 13276 KB Output is correct
62 Correct 1820 ms 12632 KB Output is correct
63 Correct 1884 ms 12632 KB Output is correct
64 Correct 2355 ms 12632 KB Output is correct
65 Correct 670 ms 12632 KB Output is correct
66 Correct 2106 ms 12888 KB Output is correct
67 Correct 2130 ms 12888 KB Output is correct
68 Correct 2086 ms 12888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 1 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 1 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 1 ms 12632 KB Output is correct
9 Correct 1 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 12632 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12772 KB Output is correct
14 Correct 2 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12888 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 12632 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12632 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 12632 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 12632 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 12888 KB Output is correct
37 Correct 2 ms 12888 KB Output is correct
38 Correct 3 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 3 ms 12632 KB Output is correct
43 Execution timed out 3013 ms 14424 KB Time limit exceeded
44 Halted 0 ms 0 KB -