답안 #922956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922956 2024-02-06T11:02:29 Z thangdz2k7 디지털 회로 (IOI22_circuit) C++17
2 / 100
404 ms 26872 KB
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

const int maxN = 2e5 + 5;
const int mod = 1000002022;

void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

vector <int> adj[maxN], pre[maxN], suf[maxN];
int val[maxN], sz[maxN];

void dfs(int u){
    sz[u] = adj[u].size();
    for (int i = 0; i < sz[u]; ++ i){
        int v = adj[u][i];
        dfs(v);
        if (!i) pre[u].pb(max(1, sz[v]));
        else pre[u].pb(1ll * pre[u].back() * max(1, sz[v]) % mod);
        suf[u].pb(0);
    }
    for (int i = sz[u] - 1; i >= 0; -- i){
        int v = adj[u][i];
        if (i == int(sz[u] - 1)) suf[u][i] = max(1, sz[v]);
        else suf[u][i] = 1ll * suf[u][i + 1] * max(1, sz[v]) % mod;
    }
}

void get(int u){
    for (int i = 0; i < sz[u]; ++ i){
        int v = adj[u][i];
        val[v] = val[u];
        if (i > 0) val[v] = 1ll * val[v] * pre[u][i - 1] % mod;
        if (i < sz[u] - 1) val[v] = 1ll * val[v] * suf[u][i + 1] % mod;
        get(v);
    }
}

int sum[2][4 * maxN];
bool used[maxN], rev[4 * maxN];

void mer(int s){
    sum[0][s] = 0;
    sum[1][s] = 0;
    for (int i = 0; i <= 1; ++ i){
        for (int j = 2 * s; j <= 2 * s + 1; ++ j) add(sum[i][s], sum[i][j]);
    }
}

void build(int s, int l, int r, int n){
    rev[s] = 0;
    if (l == r){
        sum[0][s] = used[l] * val[l + n];
        sum[1][s] = (1 ^ used[l]) * val[l + n];
        return;
    }

    int mid = (l + r) / 2;
    build(2 * s, l, mid, n);
    build(2 * s + 1, mid + 1, r, n);
    mer(s);
}

int kk, gg;

void init(int N, int M, std::vector<int> P, std::vector<int> A){
    kk = N;
    gg = M;
    for (int i = 1; i < N + M; ++ i) adj[P[i]].pb(i);
    dfs(0);
    val[0] = 1;
    get(0);
    //for (int i = 0; i < N + M; ++ i) cout << val[i] << ' ';
    for (int i = 0; i < M; ++ i) used[i] = A[i];
    build(1, 0, M - 1, N);
}

void down(int s){
    if (!rev[s]) return;
    for (int i = 2 * s; i <= 2 * s + 1; ++ i) {
        rev[i] ^= 1;
        swap(sum[0][i], sum[1][i]);
    }
    rev[s] = 0;
}

void upd(int s, int l, int r, int u, int v){
    if (u <= l && r <= v){
        rev[s] ^= 1;
        swap(sum[0][s], sum[1][s]);
        return;
    }

    int mid = (l + r) / 2;
    down(s);
    if (mid >= u) upd(2 * s, l, mid, u, v);
    if (mid + 1 <= v) upd(2 * s + 1, mid + 1, r, u, v);
    mer(s);
}

int count_ways(int L, int R){
    upd(1, 0, gg - 1, L - kk, R - kk);
    return sum[0][1];
}
//
//int main(){
//    init(3, 4, {-1, 0, 1, 2, 1, 1, 0}, {1, 0, 1, 0});
//    cout << count_ways(3, 4) << endl;
//    cout << count_ways(4, 5) << endl;
//    cout << count_ways(3, 6) << endl;
//
//
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 5 ms 21080 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 20924 KB Output is correct
6 Correct 4 ms 21072 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Incorrect 5 ms 21080 KB 1st lines differ - on the 1st token, expected: '52130940', found: '16384'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 5 ms 21080 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 20924 KB Output is correct
6 Correct 4 ms 21072 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21080 KB Output is correct
9 Correct 4 ms 21080 KB Output is correct
10 Incorrect 5 ms 21080 KB 1st lines differ - on the 1st token, expected: '52130940', found: '16384'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 404 ms 26872 KB 1st lines differ - on the 1st token, expected: '431985922', found: '268730368'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 404 ms 26872 KB 1st lines differ - on the 1st token, expected: '431985922', found: '268730368'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Incorrect 5 ms 21080 KB 1st lines differ - on the 1st token, expected: '52130940', found: '16384'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 5 ms 21080 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 20924 KB Output is correct
6 Correct 4 ms 21072 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21080 KB Output is correct
9 Correct 4 ms 21080 KB Output is correct
10 Incorrect 5 ms 21080 KB 1st lines differ - on the 1st token, expected: '52130940', found: '16384'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 5 ms 21080 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 20924 KB Output is correct
6 Correct 4 ms 21072 KB Output is correct
7 Correct 5 ms 21080 KB Output is correct
8 Correct 4 ms 21080 KB Output is correct
9 Correct 4 ms 21080 KB Output is correct
10 Incorrect 5 ms 21080 KB 1st lines differ - on the 1st token, expected: '52130940', found: '16384'
11 Halted 0 ms 0 KB -