답안 #631797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631797 2022-08-18T19:00:40 Z 4123xr4323 디지털 회로 (IOI22_circuit) C++17
2 / 100
594 ms 6768 KB
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(),a.end()
using namespace std;
using pii = pair <long long, long long>;
constexpr int maxn = 1e5 + 10;
constexpr int mod = 1000002022;
constexpr long long inf = 1e17 + 10;

vector <int> graph [maxn];
long long sub_size [maxn], ans [maxn];
long long x [maxn], tree [maxn << 2], S [maxn << 2];
bool R [maxn << 2];
int n, m;

inline void build (int v, int t_l, int t_r) {
    if (t_l == t_r) {
        S[v] = ans[t_l];
        return;
    }
    int t_m = t_l + t_r >> 1;
    build (v << 1, t_l, t_m);
    build (v << 1 | 1, t_m + 1, t_r);
    S[v] = (S[v << 1] + S[v << 1 | 1]) % mod;
} 

inline void push (int v, int t_l, int t_r) {
    if (!R[v]) return;
    tree[v] = S[v] - tree[v];
    if (t_l < t_r) {
        R[v << 1] ^= 1;
        R[v << 1 | 1] ^= 1;
    }
    R[v] = false;
}

inline void update (int l, int r, int v, int t_l, int t_r) {
    push (v, t_l, t_r);
    if (l > t_r || t_l > r) return;
    if (l <= t_l && t_r <= r) {
        R[v] = true;
        push (v, t_l, t_r);
        return;
    }
    int t_m = t_l + t_r >> 1;
    update (l, r, v << 1, t_l, t_m);
    update (l, r, v << 1 | 1, t_m + 1, t_r);
    tree[v] = tree[v << 1] + tree[v << 1 | 1];
}

inline void dfs0 (int v) {
    sub_size[v] = max (1LL, (long long) graph[v].size ());
    for (int i : graph[v]) {
        dfs0 (i);
        sub_size[v] = (sub_size[v] * sub_size[i]) % mod;
    }
}

inline void dfs1 (int v, long long cur) {
    x[v] = cur;
    for (int i : graph[v]) {
        long long cur0 = cur;
        for (int j : graph[v]) if (i != j) cur0 = (cur0 * sub_size[j]) % mod;
        dfs1 (i, cur0);
    }
}

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);
    dfs0 (0);
    dfs1 (0, 1);
    for (int i = n; i < n + m; ++i) ans[i] = x[P[i]];
    build (1, n, n + m - 1);
    for (int i = 0; i < m; ++i) if (A[i]) update (i + n, i + n, 1, n, n + m - 1);
}

int count_ways (int L, int R) {
    update (L, R, 1, n, n + m - 1);
    return tree[1];
}

Compilation message

circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:21:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int t_m = t_l + t_r >> 1;
      |               ~~~~^~~~~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:45:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |     int t_m = t_l + t_r >> 1;
      |               ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 7 ms 2640 KB Output is correct
4 Correct 7 ms 2640 KB Output is correct
5 Correct 8 ms 2640 KB Output is correct
6 Correct 7 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Incorrect 2 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 7 ms 2640 KB Output is correct
4 Correct 7 ms 2640 KB Output is correct
5 Correct 8 ms 2640 KB Output is correct
6 Correct 7 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 3 ms 2640 KB Output is correct
10 Incorrect 2 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 594 ms 6768 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 594 ms 6768 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Incorrect 2 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 7 ms 2640 KB Output is correct
4 Correct 7 ms 2640 KB Output is correct
5 Correct 8 ms 2640 KB Output is correct
6 Correct 7 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 3 ms 2640 KB Output is correct
10 Incorrect 2 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 7 ms 2640 KB Output is correct
4 Correct 7 ms 2640 KB Output is correct
5 Correct 8 ms 2640 KB Output is correct
6 Correct 7 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 3 ms 2640 KB Output is correct
10 Incorrect 2 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -