Submission #745272

# Submission time Handle Problem Language Result Execution time Memory
745272 2023-05-19T17:13:43 Z doowey Digital Circuit (IOI22_circuit) C++17
46 / 100
955 ms 13592 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

typedef long long ll;

const int N = (int)1e5 + 10;
const int MOD = (int)1e9 + 2022;
vector<int> T[N];
int W[N];
int n, m;

void dfs0(int u){
    if(T[u].empty()) W[u] = 1;
    else{
        W[u] = 1;
        for(auto x : T[u]){
            dfs0(x);
            W[u] = (W[u] * 1ll * W[x]) % MOD;
        }
        W[u] = (W[u] * 1ll * T[u].size()) % MOD;
    }
}

int coeff[N];



void dfs1(int u, int wei){
    if(T[u].empty()){
        coeff[u - n] = wei;
        return;
    }
    vector<int> pre, suff;
    for(auto x : T[u]){
        pre.push_back(W[x]);
        suff.push_back(W[x]);
    }
    for(int i = 1; i < pre.size(); i ++ ){
        pre[i] = (pre[i - 1] * 1ll * pre[i]) % MOD;
    }
    for(int i = (int)suff.size() - 2; i >= 0 ; i -- ){
        suff[i] = (suff[i] * 1ll * suff[i + 1]) % MOD;
    }
    int cf;
    for(int i = 0 ;i < T[u].size(); i ++ ){
        cf = 1;
        if(i) cf = (cf * 1ll * pre[i - 1]) % MOD;
        if(i + 1 < T[u].size()) cf = (cf * 1ll * suff[i + 1]) % MOD;
        dfs1(T[u][i], (wei * 1ll * cf) % MOD);
    }

}

vector<int> A;

struct Node{
    int total;
    int cum;
    int flip;
};

Node tr[N * 4 + 512];

void build(int node, int cl, int cr){
    tr[node].total = 0;
    tr[node].cum = 0;
    tr[node].flip = 0;
    if(cl == cr){
        tr[node].total = coeff[cl];
        if(A[cl]) tr[node].cum = coeff[cl];
        return;
    }
    int mid = (cl + cr) / 2;
    build(node * 2, cl, mid);
    build(node * 2 + 1, mid + 1, cr);
    tr[node].total = (tr[node * 2].total + tr[node * 2 + 1].total) % MOD;
    tr[node].cum = (tr[node * 2].cum + tr[node * 2 + 1].cum) % MOD;
}

void init(int _n, int _m, std::vector<int> P, vector<int> _A) {
    n = _n;
    m = _m;
    A = _A;
    for(int i = 1; i < n + m; i ++ ){
        T[P[i]].push_back(i);
    }
    dfs0(0);
    dfs1(0, 1);
    build(1, 0, m - 1);
}

void push(int node, int cl, int cr){
    if(tr[node].flip){
        tr[node].cum = (tr[node].total - tr[node].cum + MOD) % MOD;
        if(cl != cr){
            tr[node * 2].flip ^= 1;
            tr[node * 2 + 1].flip ^= 1;
        }
        tr[node].flip = 0;
    }
}

void inv(int node, int cl, int cr, int tl, int rr){
    push(node, cl, cr);
    if(cr < tl || cl > rr) return;
    if(cl >= tl && cr <= rr){
        tr[node].flip=1;
        push(node,cl,cr);
        return;
    }
    int mid = (cl + cr) / 2;
    inv(node * 2, cl, mid, tl, rr);
    inv(node * 2 + 1, mid + 1, cr, tl, rr);
    tr[node].cum = (tr[node * 2].cum + tr[node * 2 + 1].cum) % MOD;
}

int count_ways(int li, int ri) {
    inv(1, 0, m - 1, li - n, ri - n);
    return tr[1].cum;
}

Compilation message

circuit.cpp: In function 'void dfs1(int, int)':
circuit.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 1; i < pre.size(); i ++ ){
      |                    ~~^~~~~~~~~~~~
circuit.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0 ;i < T[u].size(); i ++ ){
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(i + 1 < T[u].size()) cf = (cf * 1ll * suff[i + 1]) % MOD;
      |            ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 3 ms 2640 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2640 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2896 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 463 ms 5704 KB Output is correct
2 Runtime error 28 ms 13592 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 463 ms 5704 KB Output is correct
2 Runtime error 28 ms 13592 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 3 ms 2640 KB Output is correct
10 Correct 2 ms 2896 KB Output is correct
11 Correct 2 ms 2896 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 463 ms 5704 KB Output is correct
14 Runtime error 28 ms 13592 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2640 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2896 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 578 ms 2896 KB Output is correct
44 Correct 856 ms 2896 KB Output is correct
45 Correct 831 ms 2896 KB Output is correct
46 Correct 729 ms 3164 KB Output is correct
47 Correct 903 ms 3152 KB Output is correct
48 Correct 695 ms 3152 KB Output is correct
49 Correct 896 ms 3152 KB Output is correct
50 Correct 902 ms 3152 KB Output is correct
51 Correct 794 ms 3100 KB Output is correct
52 Correct 880 ms 3156 KB Output is correct
53 Correct 762 ms 3920 KB Output is correct
54 Correct 839 ms 3164 KB Output is correct
55 Correct 871 ms 3024 KB Output is correct
56 Correct 789 ms 3024 KB Output is correct
57 Correct 885 ms 3024 KB Output is correct
58 Correct 839 ms 4176 KB Output is correct
59 Correct 885 ms 4376 KB Output is correct
60 Correct 699 ms 4304 KB Output is correct
61 Correct 955 ms 3152 KB Output is correct
62 Correct 801 ms 2896 KB Output is correct
63 Correct 787 ms 2896 KB Output is correct
64 Correct 689 ms 3024 KB Output is correct
65 Correct 407 ms 2768 KB Output is correct
66 Correct 927 ms 3024 KB Output is correct
67 Correct 657 ms 3024 KB Output is correct
68 Correct 871 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 1 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2640 KB Output is correct
18 Correct 2 ms 2896 KB Output is correct
19 Correct 2 ms 2896 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2896 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2896 KB Output is correct
37 Correct 2 ms 2896 KB Output is correct
38 Correct 2 ms 2896 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 463 ms 5704 KB Output is correct
44 Runtime error 28 ms 13592 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -