답안 #1011138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011138 2024-06-29T22:09:42 Z damjandavkov 디지털 회로 (IOI22_circuit) C++17
100 / 100
780 ms 26320 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll r = 1000002022, p, n;
vector<ll> en, nu, lz, wl, wr;
void upd(int a, int b, int i)
{
    if (wl[i] >= b || wr[i] <= a)
        return;
    if (wl[i] >= a && wr[i] <= b)
    {
        lz[i] ^= 1;
        return;
    }
    upd(a, b, 2 * i);
    upd(a, b, 2 * i + 1);
    nu[i] = en[i] = 0;
    if (lz[2 * i])
    {
        nu[i] += en[2 * i];
        en[i] += nu[2 * i];
    }
    else
    {
        nu[i] += nu[2 * i];
        en[i] += en[2 * i];
    }
    if (lz[2 * i + 1])
    {
        nu[i] += en[2 * i + 1];
        en[i] += nu[2 * i + 1];
    }
    else
    {
        nu[i] += nu[2 * i + 1];
        en[i] += en[2 * i + 1];
    }
}
void init(int N, int M, vector<int> P, vector<int> A)
{
    n = N;
    ll m = M, i, a, b;
    vector<vector<int> > ch(n + m);
    vector<ll> t(n + m), d(n + m), pf, sf;
    for (i = 1; i < n + m; i++)
        ch[P[i]].push_back(i);
    for (i = n; i < n + m; i++)
        t[i] = 1;
    for (i = n - 1; i >= 0; i--)
    {
        t[i] = ch[i].size();
        for (auto h : ch[i])
            t[i] = t[i] * t[h] % r;
    }
    queue<int> q;
    d[0] = 1;
    q.push(0);
    while (!q.empty())
    {
        a = q.front();
        q.pop();
        b = ch[a].size();
        pf.resize(b + 1);
        sf.resize(b + 1);
        pf[0] = sf[b] = 1;
        for (i = 0; i < b; i++)
            pf[i + 1] = pf[i] * t[ch[a][i]] % r;
        for (i = b - 1; i >= 0; i--)
            sf[i] = sf[i + 1] * t[ch[a][i]] % r;
        for (i = 0; i < b; i++)
        {
            d[ch[a][i]] = (pf[i] * sf[i + 1] % r) * d[a] % r;
            q.push(ch[a][i]);
        }
    }
    p = m;
    while (p != (p & -p))
        p++;
    en.resize(2 * p);
    nu.resize(2 * p);
    lz.resize(2 * p);
    wl.resize(2 * p);
    wr.resize(2 * p);
    for (i = p; i < 2 * p; i++)
    {
        nu[i] = 0;
        en[i] = 0;
        if (i < p + m)
        {
            if (A[i - p])
                en[i] = d[i - p + n];
            else
                nu[i] = d[i - p + n];
        }
        lz[i] = 0;
        wl[i] = i;
        wr[i] = i + 1;
    }
    for (i = p - 1; i > 0; i--)
    {
        wl[i] = wl[2 * i];
        wr[i] = wr[2 * i + 1];
        lz[i] = 0;
        nu[i] = nu[2 * i] + nu[2 * i + 1];
        en[i] = en[2 * i] + en[2 * i + 1];
    }
}
int count_ways(int L, int R)
{
    upd(L - n + p, R - n + p + 1, 1);
    if (lz[1])
        return nu[1] % r;
    return en[1] % r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 7484 KB Output is correct
2 Correct 625 ms 14424 KB Output is correct
3 Correct 648 ms 14416 KB Output is correct
4 Correct 593 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 7484 KB Output is correct
2 Correct 625 ms 14424 KB Output is correct
3 Correct 648 ms 14416 KB Output is correct
4 Correct 593 ms 14424 KB Output is correct
5 Correct 562 ms 7400 KB Output is correct
6 Correct 746 ms 14424 KB Output is correct
7 Correct 694 ms 14424 KB Output is correct
8 Correct 685 ms 14520 KB Output is correct
9 Correct 280 ms 856 KB Output is correct
10 Correct 618 ms 1112 KB Output is correct
11 Correct 672 ms 1112 KB Output is correct
12 Correct 624 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 439 ms 7484 KB Output is correct
14 Correct 625 ms 14424 KB Output is correct
15 Correct 648 ms 14416 KB Output is correct
16 Correct 593 ms 14424 KB Output is correct
17 Correct 562 ms 7400 KB Output is correct
18 Correct 746 ms 14424 KB Output is correct
19 Correct 694 ms 14424 KB Output is correct
20 Correct 685 ms 14520 KB Output is correct
21 Correct 280 ms 856 KB Output is correct
22 Correct 618 ms 1112 KB Output is correct
23 Correct 672 ms 1112 KB Output is correct
24 Correct 624 ms 1112 KB Output is correct
25 Correct 740 ms 23632 KB Output is correct
26 Correct 727 ms 23888 KB Output is correct
27 Correct 643 ms 23888 KB Output is correct
28 Correct 578 ms 23880 KB Output is correct
29 Correct 780 ms 23888 KB Output is correct
30 Correct 676 ms 23888 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 454 ms 1112 KB Output is correct
44 Correct 717 ms 1192 KB Output is correct
45 Correct 687 ms 1112 KB Output is correct
46 Correct 556 ms 1624 KB Output is correct
47 Correct 603 ms 1624 KB Output is correct
48 Correct 575 ms 1624 KB Output is correct
49 Correct 561 ms 1624 KB Output is correct
50 Correct 592 ms 1624 KB Output is correct
51 Correct 581 ms 1488 KB Output is correct
52 Correct 589 ms 1616 KB Output is correct
53 Correct 527 ms 600 KB Output is correct
54 Correct 613 ms 1624 KB Output is correct
55 Correct 570 ms 1376 KB Output is correct
56 Correct 593 ms 1368 KB Output is correct
57 Correct 597 ms 1384 KB Output is correct
58 Correct 611 ms 1624 KB Output is correct
59 Correct 558 ms 1880 KB Output is correct
60 Correct 567 ms 1880 KB Output is correct
61 Correct 592 ms 1112 KB Output is correct
62 Correct 570 ms 1112 KB Output is correct
63 Correct 627 ms 1064 KB Output is correct
64 Correct 627 ms 1404 KB Output is correct
65 Correct 303 ms 856 KB Output is correct
66 Correct 621 ms 1112 KB Output is correct
67 Correct 643 ms 1112 KB Output is correct
68 Correct 558 ms 1112 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 439 ms 7484 KB Output is correct
44 Correct 625 ms 14424 KB Output is correct
45 Correct 648 ms 14416 KB Output is correct
46 Correct 593 ms 14424 KB Output is correct
47 Correct 562 ms 7400 KB Output is correct
48 Correct 746 ms 14424 KB Output is correct
49 Correct 694 ms 14424 KB Output is correct
50 Correct 685 ms 14520 KB Output is correct
51 Correct 280 ms 856 KB Output is correct
52 Correct 618 ms 1112 KB Output is correct
53 Correct 672 ms 1112 KB Output is correct
54 Correct 624 ms 1112 KB Output is correct
55 Correct 740 ms 23632 KB Output is correct
56 Correct 727 ms 23888 KB Output is correct
57 Correct 643 ms 23888 KB Output is correct
58 Correct 578 ms 23880 KB Output is correct
59 Correct 780 ms 23888 KB Output is correct
60 Correct 676 ms 23888 KB Output is correct
61 Correct 454 ms 1112 KB Output is correct
62 Correct 717 ms 1192 KB Output is correct
63 Correct 687 ms 1112 KB Output is correct
64 Correct 556 ms 1624 KB Output is correct
65 Correct 603 ms 1624 KB Output is correct
66 Correct 575 ms 1624 KB Output is correct
67 Correct 561 ms 1624 KB Output is correct
68 Correct 592 ms 1624 KB Output is correct
69 Correct 581 ms 1488 KB Output is correct
70 Correct 589 ms 1616 KB Output is correct
71 Correct 527 ms 600 KB Output is correct
72 Correct 613 ms 1624 KB Output is correct
73 Correct 570 ms 1376 KB Output is correct
74 Correct 593 ms 1368 KB Output is correct
75 Correct 597 ms 1384 KB Output is correct
76 Correct 611 ms 1624 KB Output is correct
77 Correct 558 ms 1880 KB Output is correct
78 Correct 567 ms 1880 KB Output is correct
79 Correct 592 ms 1112 KB Output is correct
80 Correct 570 ms 1112 KB Output is correct
81 Correct 627 ms 1064 KB Output is correct
82 Correct 627 ms 1404 KB Output is correct
83 Correct 303 ms 856 KB Output is correct
84 Correct 621 ms 1112 KB Output is correct
85 Correct 643 ms 1112 KB Output is correct
86 Correct 558 ms 1112 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 397 ms 22616 KB Output is correct
89 Correct 688 ms 14424 KB Output is correct
90 Correct 709 ms 13904 KB Output is correct
91 Correct 633 ms 24144 KB Output is correct
92 Correct 739 ms 24144 KB Output is correct
93 Correct 767 ms 24144 KB Output is correct
94 Correct 723 ms 24148 KB Output is correct
95 Correct 681 ms 24144 KB Output is correct
96 Correct 710 ms 18384 KB Output is correct
97 Correct 690 ms 18384 KB Output is correct
98 Correct 603 ms 8024 KB Output is correct
99 Correct 700 ms 23888 KB Output is correct
100 Correct 731 ms 20048 KB Output is correct
101 Correct 708 ms 18684 KB Output is correct
102 Correct 722 ms 16724 KB Output is correct
103 Correct 679 ms 23888 KB Output is correct
104 Correct 744 ms 26320 KB Output is correct
105 Correct 688 ms 26304 KB Output is correct
106 Correct 614 ms 13912 KB Output is correct
107 Correct 638 ms 17496 KB Output is correct
108 Correct 657 ms 17492 KB Output is correct
109 Correct 719 ms 16840 KB Output is correct