답안 #964808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964808 2024-04-17T15:21:41 Z steveonalex 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 8216 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 2e5 + 69, MOD = 1e9 + 2022;
int n, m;
vector<int> graph[N];
int dp[N];
int prod[N];

void init(int _n, int _m, vector<int> P, vector<int> A) {
    n = _n, m = _m;
    for(int i = 1; i<n+m; ++i){
        graph[P[i]].push_back(i);
    }

    for(int i = 0; i<m; ++i){
        prod[i+n] = 1;
        dp[i+n] = A[i];
    }
}   

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

void sub(int &a, int b){
    a -= b;
    if (a < 0) a += MOD;
}

void go(int u, int p){
    if (u >= n) return;
    dp[u] = 0;
    prod[u] = 1;

    for(int v: graph[u]) {
        go(v, u);
        prod[u] = 1LL * prod[u] * prod[v] % MOD;
    }
    prod[u] = 1LL * prod[u] * graph[u].size() % MOD;

    vector<int> pref(graph[u].size() + 1, 1), suff(graph[u].size() + 1, 1);
    for(int i = 0; i<graph[u].size(); ++i){
        pref[i+1] = 1LL * pref[i] * prod[graph[u][i]] % MOD;
    }
    for(int i = graph[u].size() - 1; i>=0; --i){
        suff[i] = 1LL * suff[i+1] * prod[graph[u][i]] % MOD;
    }

    for(int i = 0; i<graph[u].size(); ++i){
        int v = graph[u][i];
        int cur = 1LL * pref[i] * suff[i+1] % MOD;
        cur = 1LL * cur * dp[v] % MOD;
        add(dp[u], cur);
    }
}

int count_ways(int l, int r) {
    for(int i = l; i <= r; ++i){
        dp[i] ^= 1;
    }

    go(0, 0);

    return dp[0];
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n, m; cin >> n >> m;
//     vector<int> P(n+m, -1);
//     for(int i = 1; i<n+m; ++i) cin >> P[i];
//     vector<int> A(m); 
//     for(int i = 0; i<m; ++i) cin >> A[i];

//     init(n, m, P, A);
//     int q; cin >> q;
//     while(q--){
//         int l, r; cin >> l >> r;
//         cout << count_ways(l, r) << "\n";
//     }


//     return 0;
// }

Compilation message

circuit.cpp: In function 'void go(int, int)':
circuit.cpp:87:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i = 0; i<graph[u].size(); ++i){
      |                    ~^~~~~~~~~~~~~~~~
circuit.cpp:94:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i = 0; i<graph[u].size(); ++i){
      |                    ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6484 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 4 ms 6488 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 3 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 3 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6576 KB Output is correct
10 Correct 3 ms 6488 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6484 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 4 ms 6488 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6576 KB Output is correct
18 Correct 3 ms 6488 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 3 ms 6488 KB Output is correct
22 Correct 4 ms 6488 KB Output is correct
23 Correct 3 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 3 ms 6488 KB Output is correct
26 Correct 4 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6488 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 4 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 2 ms 6488 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6672 KB Output is correct
38 Correct 3 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 2 ms 6488 KB Output is correct
41 Correct 2 ms 6488 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3071 ms 8216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3071 ms 8216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 3 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 3 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6576 KB Output is correct
10 Correct 3 ms 6488 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Execution timed out 3071 ms 8216 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6484 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 4 ms 6488 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6576 KB Output is correct
18 Correct 3 ms 6488 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 3 ms 6488 KB Output is correct
22 Correct 4 ms 6488 KB Output is correct
23 Correct 3 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 3 ms 6488 KB Output is correct
26 Correct 4 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6488 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 4 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 2 ms 6488 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6672 KB Output is correct
38 Correct 3 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 2 ms 6488 KB Output is correct
41 Correct 2 ms 6488 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
43 Execution timed out 3068 ms 6488 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6484 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6484 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 4 ms 6488 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6576 KB Output is correct
18 Correct 3 ms 6488 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 3 ms 6488 KB Output is correct
22 Correct 4 ms 6488 KB Output is correct
23 Correct 3 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 3 ms 6488 KB Output is correct
26 Correct 4 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6488 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 4 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 2 ms 6488 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 2 ms 6672 KB Output is correct
38 Correct 3 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 2 ms 6488 KB Output is correct
41 Correct 2 ms 6488 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
43 Execution timed out 3071 ms 8216 KB Time limit exceeded
44 Halted 0 ms 0 KB -