Submission #826194

# Submission time Handle Problem Language Result Execution time Memory
826194 2023-08-15T11:05:20 Z PixelCat Digital Circuit (IOI22_circuit) C++17
0 / 100
829 ms 2097152 KB
#include "circuit.h"

#ifdef NYAOWO
#include "stub.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 200'000;
const int MOD = 1'000'002'022;

#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
    struct Node {
        bool flip;
        int dp1, sum;
    } a[MAXN * 4 + 10];
    void build(int id, int l, int r, int* A) {
        a[id].flip = 0;
        if(l == r) {
            a[id].sum = A[l];
            if(A[l] == 1) {
                a[id].dp1 = A[l];
            } else {
                a[id].dp1 = 0;
            }
            return;
        }
        int m = (l + r) / 2;
        build(L(id), l, m, A);
        build(R(id), m + 1, r, A);
        a[id].dp1 = (a[L(id)].dp1 + a[R(id)].dp1) % MOD;
        a[id].sum = (a[L(id)].sum + a[R(id)].sum) % MOD;
    }
    void range_flip(int id, int l, int r, int L, int R) {
        if(l >= L && r <= R) {
            a[id].flip ^= 1;
            a[id].dp1 = a[id].sum - a[id].dp1;
            return;
        }
        int m = (l + r) / 2;
        if(L <= m) range_flip(L(id), l, m, L, R);
        if(R > m)  range_flip(R(id), m + 1, r, L, R);
        a[id].dp1 = (a[L(id)].dp1 + a[R(id)].dp1) % MOD;
        a[id].sum = (a[L(id)].sum + a[R(id)].sum) % MOD;
        if(a[id].flip) a[id].dp1 = a[id].sum - a[id].dp1;
    }
    int qry() {
        return (a[0].dp1 + MOD) % MOD;
    }
} seg;

int n, m;
vector<int> adj[MAXN + 10];
int p[MAXN + 10];
int a[MAXN + 10];

int s[MAXN + 10];

void dfs(int x) {
    if(x >= n) {
        s[x] = 1;
        return;
    }
    s[x] = sz(adj[x]);
    for(auto &i:adj[x]) {
        dfs(i);
        s[x] = s[x] * s[i] % MOD;
    }
}

int ss[MAXN + 10];
void dfs2(int x, int owo) {
    if(x >= n) {
        ss[x] = owo;
        return;
    }
    int l = adj[x][0];
    int r = adj[x][1];
    dfs2(l, owo * s[r] % MOD);
    dfs2(r, owo * s[l] % MOD);
}

// int ans = 0;
// void update_leaf(int pos, int val) {
//     ans = ((ans + val * ss[pos]) % MOD + MOD) % MOD;
// }

void init(i32 N, i32 M, std::vector<i32> P, std::vector<i32> A) {
    n = N; m = M;
    p[0] = -1;
    For(i, 1, n + m - 1) {
        adj[P[i]].eb(i);
        p[i] = P[i];
    }
    dfs(0);
    dfs2(0, 1);
    seg.build(0, n, n + m - 1, ss);
    For(i, 0, m - 1) {
        a[n + i] = A[i];
        if(A[i]) seg.range_flip(0, n, n + m - 1, i, i);
        // update_leaf(n + i, A[i]);
    }
}

i32 count_ways(i32 L, i32 R) {
    seg.range_flip(0, n, n + m - 1, L, R);
    return (i32) seg.qry();
    // int i = min(L, R);
    // int last = i;
    // int d = 1 - 2 * a[i];
    // a[i] += d;
    // update_leaf(i, d);
    // return (i32)ans;
}

/*

3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6

2
0
6

*/
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 829 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 829 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '0'
2 Halted 0 ms 0 KB -