Submission #630221

# Submission time Handle Problem Language Result Execution time Memory
630221 2022-08-16T05:58:09 Z talant117408 Digital Circuit (IOI22_circuit) C++17
13 / 100
997 ms 27288 KB
#include "circuit.h"
#include <bits/stdc++.h>

#ifndef EVAL
#include "stub.cpp"
#endif

using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define PI                  2*acos(0.0)

const ll mod = 1000002022;

ll add(ll a, ll b) {
    return ((a + b) % mod + mod) % mod;
}

ll mult(ll a, ll b) {
    return ((a * b) % mod + mod) % mod;
}

const int N = 2e5 + 7;
ll tree[2][N * 4], lz[N * 4]; // 0 - all configurations; 1 - valid configurations;
vector <int> graph[N];
vector <ll> pref[N], suff[N];
int n, m;
vector <int> parent, state;
ll valid_for[N], ans_for[N];

ll dfs(int v) {
    valid_for[v] = max(1, sz(graph[v]));
    for (auto to : graph[v]) {
        valid_for[v] = mult(valid_for[v], dfs(to));
    }
    return valid_for[v];
}

void calc(int v, ll val) {
    ans_for[v] = val;
    for (int i = 0; i < sz(graph[v]); i++) {
        auto to = graph[v][i];
        calc(to, mult(val, mult((i == 0 ? 1ll : pref[v][i - 1]), (i == sz(graph[v]) - 1ll ? 1 : suff[v][i + 1]))));
    }
}

void build(int v, int l, int r) {
    if (l == r) {
        tree[0][v] = ans_for[l + n];
        if (state[l]) {
            tree[1][v] = ans_for[l + n];
        }
        return;
    }
    int mid = (l + r) >> 1;
    build(v * 2, l, mid);
    build(v * 2 + 1, mid + 1, r);
    tree[0][v] = add(tree[0][v * 2], tree[0][v * 2 + 1]);
    tree[1][v] = add(tree[1][v * 2], tree[1][v * 2 + 1]);
}

void push(int v, int l, int r) {
    if (lz[v]) {
        tree[1][v] = tree[0][v] - tree[1][v];
        if (l != r) {
            lz[v * 2] ^= lz[v];
            lz[v * 2 + 1] ^= lz[v];
        }
        lz[v] = 0;
    }
}

void update(int v, int l, int r, int ql, int qr) {
    push(v, l, r);
    if (ql > r || l > qr) return;
    if (ql <= l && r <= qr) {
        lz[v] ^= 1;
        push(v, l, r);
        return;
    }
    int mid = (l + r) >> 1;
    update(v * 2, l, mid, ql, qr);
    update(v * 2 + 1, mid + 1, r, ql, qr);
    tree[1][v] = add(tree[1][v * 2], tree[1][v * 2 + 1]);
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N, m = M, parent = P, state = A;
    for (int i = 1; i < n + m; i++) {
        graph[parent[i]].pb(i);
    }
    dfs(0);
    for (int i = 0; i < n + m; i++) {
        for (auto to : graph[i]) {
            pref[i].pb(valid_for[to]);
            suff[i].pb(valid_for[to]);
        }
        for (int j = 1; j < sz(pref[i]); j++) {
            pref[i][j] = mult(pref[i][j], pref[i][j - 1]);
        }
        for (int j = sz(suff[i]) - 2; j >= 0; j--) {
            suff[i][j] = mult(suff[i][j], suff[i][j + 1]);
        }
    }
    calc(0, 1);
    build(1, 0, m - 1);
}

int count_ways(int L, int R) {
    update(1, 0, m - 1, L - n, R - n);
    return tree[1][1];
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14384 KB Output is correct
3 Correct 8 ms 14532 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 11 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 14376 KB Output is correct
2 Correct 8 ms 14412 KB Output is correct
3 Correct 10 ms 14408 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 11 ms 14488 KB Output is correct
6 Correct 9 ms 14476 KB Output is correct
7 Correct 9 ms 14572 KB Output is correct
8 Correct 12 ms 14544 KB Output is correct
9 Correct 9 ms 14544 KB Output is correct
10 Correct 8 ms 14672 KB Output is correct
11 Correct 8 ms 14672 KB Output is correct
12 Correct 11 ms 14544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14384 KB Output is correct
3 Correct 8 ms 14532 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 11 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 11 ms 14376 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 10 ms 14408 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 11 ms 14488 KB Output is correct
14 Correct 9 ms 14476 KB Output is correct
15 Correct 9 ms 14572 KB Output is correct
16 Correct 12 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14672 KB Output is correct
19 Correct 8 ms 14672 KB Output is correct
20 Correct 11 ms 14544 KB Output is correct
21 Correct 9 ms 14576 KB Output is correct
22 Correct 8 ms 14544 KB Output is correct
23 Correct 12 ms 14484 KB Output is correct
24 Correct 8 ms 14544 KB Output is correct
25 Correct 9 ms 14516 KB Output is correct
26 Correct 9 ms 14544 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Incorrect 11 ms 14544 KB 2nd lines differ - on the 1st token, expected: '903738266', found: '-96263756'
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 587 ms 20684 KB Output is correct
2 Correct 867 ms 26908 KB Output is correct
3 Correct 813 ms 26956 KB Output is correct
4 Correct 761 ms 26788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 587 ms 20684 KB Output is correct
2 Correct 867 ms 26908 KB Output is correct
3 Correct 813 ms 26956 KB Output is correct
4 Correct 761 ms 26788 KB Output is correct
5 Correct 758 ms 20964 KB Output is correct
6 Correct 817 ms 27288 KB Output is correct
7 Correct 997 ms 27252 KB Output is correct
8 Incorrect 911 ms 26952 KB 1099th lines differ - on the 1st token, expected: '196050388', found: '-803951634'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 14376 KB Output is correct
2 Correct 8 ms 14412 KB Output is correct
3 Correct 10 ms 14408 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 11 ms 14488 KB Output is correct
6 Correct 9 ms 14476 KB Output is correct
7 Correct 9 ms 14572 KB Output is correct
8 Correct 12 ms 14544 KB Output is correct
9 Correct 9 ms 14544 KB Output is correct
10 Correct 8 ms 14672 KB Output is correct
11 Correct 8 ms 14672 KB Output is correct
12 Correct 11 ms 14544 KB Output is correct
13 Correct 587 ms 20684 KB Output is correct
14 Correct 867 ms 26908 KB Output is correct
15 Correct 813 ms 26956 KB Output is correct
16 Correct 761 ms 26788 KB Output is correct
17 Correct 758 ms 20964 KB Output is correct
18 Correct 817 ms 27288 KB Output is correct
19 Correct 997 ms 27252 KB Output is correct
20 Incorrect 911 ms 26952 KB 1099th lines differ - on the 1st token, expected: '196050388', found: '-803951634'
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14384 KB Output is correct
3 Correct 8 ms 14532 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 11 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 11 ms 14376 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 10 ms 14408 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 11 ms 14488 KB Output is correct
14 Correct 9 ms 14476 KB Output is correct
15 Correct 9 ms 14572 KB Output is correct
16 Correct 12 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14672 KB Output is correct
19 Correct 8 ms 14672 KB Output is correct
20 Correct 11 ms 14544 KB Output is correct
21 Correct 9 ms 14576 KB Output is correct
22 Correct 8 ms 14544 KB Output is correct
23 Correct 12 ms 14484 KB Output is correct
24 Correct 8 ms 14544 KB Output is correct
25 Correct 9 ms 14516 KB Output is correct
26 Correct 9 ms 14544 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Incorrect 11 ms 14544 KB 2nd lines differ - on the 1st token, expected: '903738266', found: '-96263756'
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14384 KB Output is correct
3 Correct 8 ms 14532 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 11 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 11 ms 14376 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 10 ms 14408 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 11 ms 14488 KB Output is correct
14 Correct 9 ms 14476 KB Output is correct
15 Correct 9 ms 14572 KB Output is correct
16 Correct 12 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14672 KB Output is correct
19 Correct 8 ms 14672 KB Output is correct
20 Correct 11 ms 14544 KB Output is correct
21 Correct 9 ms 14576 KB Output is correct
22 Correct 8 ms 14544 KB Output is correct
23 Correct 12 ms 14484 KB Output is correct
24 Correct 8 ms 14544 KB Output is correct
25 Correct 9 ms 14516 KB Output is correct
26 Correct 9 ms 14544 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Incorrect 11 ms 14544 KB 2nd lines differ - on the 1st token, expected: '903738266', found: '-96263756'
29 Halted 0 ms 0 KB -