답안 #944809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944809 2024-03-13T05:51:34 Z KG07 디지털 회로 (IOI22_circuit) C++17
46 / 100
598 ms 24244 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

struct segment_tree{
    int n, m;
    long long tree_size[200002], sum[400004], counting[400004], multiplier[100001];
    bool toggle[400004];
    vector<int> child[100001], A;
    vector<long long> left_product[100001], right_product[100001];
    void init(int N, int M, vector<int> p, vector<int> a){
        n = N;
        m = M;
        A = a;
        tree_size[0] = 1LL;
        for(int i = 1; i < N+M; i++){
            tree_size[i] = 1LL;
            child[p[i]].push_back(i);
            left_product[p[i]].push_back(0LL);
            right_product[p[i]].push_back(0LL);
        }
    }
    void calculate_size(int N){
        if(N >= n)return;
        tree_size[N] = (long long) child[N].size();
        for(int i = 0; i < child[N].size(); i++){
            calculate_size(child[N][i]);
            left_product[N][i] = tree_size[child[N][i]];
            right_product[N][i] = tree_size[child[N][i]];
            tree_size[N] *= tree_size[child[N][i]];
            tree_size[N] %= 1000002022;
        }
        for(int i = 1; i < child[N].size(); i++){
            left_product[N][i] *= left_product[N][i-1];
            left_product[N][i] %= 1000002022;
        }
        for(int i = child[N].size()-1; i; i--){
            right_product[N][i-1] *= right_product[N][i];
            right_product[N][i-1] %= 1000002022;
        }
    }
    void calculate_multiplier(int N, long long M){
        if(N >= n){
            multiplier[N] = M;
            return;
        }
        if(child[N].size() == 1){
            calculate_multiplier(child[N][0], M);
            return;
        }
        for(int i = 0; i < child[N].size(); i++){
            if(!i)calculate_multiplier(child[N][i], (M*right_product[N][1])%1000002022);
            else if(i+1==child[N].size())calculate_multiplier(child[N][i], (M*left_product[N][child[N].size()-2])%1000002022);
            else calculate_multiplier(child[N][i], (M*((right_product[N][i+1]*left_product[N][i-1])%1000002022))%1000002022);
        }
    }
    void create_tree(int N, int l, int r){
        toggle[N] = false;
        if(l == r){
            sum[N] = multiplier[n+r-1];
            if(A[r-1])counting[N] = multiplier[n+r-1];
            else counting[N] = 0LL;
            return;
        }
        create_tree(2*N, l, (l+r)/2);
        create_tree(2*N+1,(l+r)/2+1, r);
        sum[N] = (sum[2*N] + sum[2*N+1]) % 1000002022;
        counting[N] = (counting[2*N] + counting[2*N+1]) % 1000002022;
    }
    void lazy_update(int N){
        if(toggle[N]){
            toggle[N] = false;
            toggle[2*N] = !toggle[2*N];
            toggle[2*N+1] = !toggle[2*N+1];
            counting[2*N] = (sum[2*N]-counting[2*N]+1000002022) % 1000002022;
            counting[2*N+1] = (sum[2*N+1]-counting[2*N+1]+1000002022) % 1000002022;
        }
    }
    void update(int N, int l, int r, int s, int t){
        if(l > t || r < s)return;
        if(l <= s && r >= t){
            toggle[N] = !toggle[N];
            counting[N] = (sum[N]-counting[N]+1000002022) % 1000002022;
            return;
        }
        lazy_update(N);
        update(2*N, l, r, s, (s+t)/2);
        update(2*N+1, l, r, (s+t)/2+1, t);
        counting[N] = (counting[2*N] + counting[2*N+1]) % 1000002022;
    }
} A;

void init(int N, int M, vector<int> p, vector<int> a) {
    A.init(N, M, p, a);
    A.calculate_size(0);
    A.calculate_multiplier(0, 1LL);
    A.create_tree(1, 1, M);
}

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

Compilation message

circuit.cpp: In member function 'void segment_tree::calculate_size(int)':
circuit.cpp:27:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i = 0; i < child[N].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~
circuit.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i = 1; i < child[N].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~
circuit.cpp: In member function 'void segment_tree::calculate_multiplier(int, long long int)':
circuit.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i = 0; i < child[N].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~
circuit.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             else if(i+1==child[N].size())calculate_multiplier(child[N][i], (M*left_product[N][child[N].size()-2])%1000002022);
      |                     ~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Correct 3 ms 14168 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 3 ms 14168 KB Output is correct
6 Correct 3 ms 14168 KB Output is correct
7 Correct 3 ms 14168 KB Output is correct
8 Correct 3 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Correct 3 ms 14168 KB Output is correct
3 Correct 3 ms 14168 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 3 ms 14168 KB Output is correct
6 Correct 3 ms 14168 KB Output is correct
7 Correct 3 ms 14168 KB Output is correct
8 Correct 3 ms 14168 KB Output is correct
9 Correct 3 ms 14168 KB Output is correct
10 Correct 3 ms 14424 KB Output is correct
11 Correct 5 ms 14424 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Correct 3 ms 14168 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 3 ms 14168 KB Output is correct
6 Correct 3 ms 14168 KB Output is correct
7 Correct 3 ms 14168 KB Output is correct
8 Correct 3 ms 14168 KB Output is correct
9 Correct 3 ms 14168 KB Output is correct
10 Correct 3 ms 14168 KB Output is correct
11 Correct 3 ms 14168 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 3 ms 14168 KB Output is correct
14 Correct 3 ms 14168 KB Output is correct
15 Correct 3 ms 14168 KB Output is correct
16 Correct 3 ms 14168 KB Output is correct
17 Correct 3 ms 14168 KB Output is correct
18 Correct 3 ms 14424 KB Output is correct
19 Correct 5 ms 14424 KB Output is correct
20 Correct 3 ms 14168 KB Output is correct
21 Correct 3 ms 14168 KB Output is correct
22 Correct 3 ms 14168 KB Output is correct
23 Correct 3 ms 14168 KB Output is correct
24 Correct 3 ms 14424 KB Output is correct
25 Correct 3 ms 14424 KB Output is correct
26 Correct 3 ms 14424 KB Output is correct
27 Correct 3 ms 14424 KB Output is correct
28 Correct 4 ms 14424 KB Output is correct
29 Correct 3 ms 14168 KB Output is correct
30 Correct 3 ms 14168 KB Output is correct
31 Correct 3 ms 14676 KB Output is correct
32 Correct 4 ms 14168 KB Output is correct
33 Correct 3 ms 14168 KB Output is correct
34 Correct 3 ms 14168 KB Output is correct
35 Correct 3 ms 14168 KB Output is correct
36 Correct 4 ms 14424 KB Output is correct
37 Correct 3 ms 14424 KB Output is correct
38 Correct 4 ms 14424 KB Output is correct
39 Correct 3 ms 14168 KB Output is correct
40 Correct 3 ms 14168 KB Output is correct
41 Correct 4 ms 14168 KB Output is correct
42 Correct 3 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 413 ms 18364 KB Output is correct
2 Incorrect 586 ms 24244 KB 1st lines differ - on the 1st token, expected: '913758140', found: '24813050'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 413 ms 18364 KB Output is correct
2 Incorrect 586 ms 24244 KB 1st lines differ - on the 1st token, expected: '913758140', found: '24813050'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Correct 3 ms 14168 KB Output is correct
3 Correct 3 ms 14168 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 3 ms 14168 KB Output is correct
6 Correct 3 ms 14168 KB Output is correct
7 Correct 3 ms 14168 KB Output is correct
8 Correct 3 ms 14168 KB Output is correct
9 Correct 3 ms 14168 KB Output is correct
10 Correct 3 ms 14424 KB Output is correct
11 Correct 5 ms 14424 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 413 ms 18364 KB Output is correct
14 Incorrect 586 ms 24244 KB 1st lines differ - on the 1st token, expected: '913758140', found: '24813050'
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Correct 3 ms 14168 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 3 ms 14168 KB Output is correct
6 Correct 3 ms 14168 KB Output is correct
7 Correct 3 ms 14168 KB Output is correct
8 Correct 3 ms 14168 KB Output is correct
9 Correct 3 ms 14168 KB Output is correct
10 Correct 3 ms 14168 KB Output is correct
11 Correct 3 ms 14168 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 3 ms 14168 KB Output is correct
14 Correct 3 ms 14168 KB Output is correct
15 Correct 3 ms 14168 KB Output is correct
16 Correct 3 ms 14168 KB Output is correct
17 Correct 3 ms 14168 KB Output is correct
18 Correct 3 ms 14424 KB Output is correct
19 Correct 5 ms 14424 KB Output is correct
20 Correct 3 ms 14168 KB Output is correct
21 Correct 3 ms 14168 KB Output is correct
22 Correct 3 ms 14168 KB Output is correct
23 Correct 3 ms 14168 KB Output is correct
24 Correct 3 ms 14424 KB Output is correct
25 Correct 3 ms 14424 KB Output is correct
26 Correct 3 ms 14424 KB Output is correct
27 Correct 3 ms 14424 KB Output is correct
28 Correct 4 ms 14424 KB Output is correct
29 Correct 3 ms 14168 KB Output is correct
30 Correct 3 ms 14168 KB Output is correct
31 Correct 3 ms 14676 KB Output is correct
32 Correct 4 ms 14168 KB Output is correct
33 Correct 3 ms 14168 KB Output is correct
34 Correct 3 ms 14168 KB Output is correct
35 Correct 3 ms 14168 KB Output is correct
36 Correct 4 ms 14424 KB Output is correct
37 Correct 3 ms 14424 KB Output is correct
38 Correct 4 ms 14424 KB Output is correct
39 Correct 3 ms 14168 KB Output is correct
40 Correct 3 ms 14168 KB Output is correct
41 Correct 4 ms 14168 KB Output is correct
42 Correct 3 ms 14168 KB Output is correct
43 Correct 416 ms 14680 KB Output is correct
44 Correct 542 ms 14680 KB Output is correct
45 Correct 542 ms 14680 KB Output is correct
46 Correct 586 ms 14936 KB Output is correct
47 Correct 561 ms 14936 KB Output is correct
48 Correct 557 ms 14936 KB Output is correct
49 Correct 574 ms 14936 KB Output is correct
50 Correct 541 ms 14936 KB Output is correct
51 Correct 561 ms 14648 KB Output is correct
52 Correct 577 ms 14640 KB Output is correct
53 Correct 543 ms 14936 KB Output is correct
54 Correct 545 ms 14936 KB Output is correct
55 Correct 533 ms 14680 KB Output is correct
56 Correct 598 ms 14680 KB Output is correct
57 Correct 586 ms 14544 KB Output is correct
58 Correct 567 ms 15192 KB Output is correct
59 Correct 550 ms 15512 KB Output is correct
60 Correct 548 ms 15508 KB Output is correct
61 Correct 565 ms 14680 KB Output is correct
62 Correct 585 ms 14424 KB Output is correct
63 Correct 585 ms 14424 KB Output is correct
64 Correct 571 ms 14676 KB Output is correct
65 Correct 293 ms 14420 KB Output is correct
66 Correct 568 ms 14680 KB Output is correct
67 Correct 586 ms 14680 KB Output is correct
68 Correct 553 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Correct 3 ms 14168 KB Output is correct
3 Correct 4 ms 14584 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 3 ms 14168 KB Output is correct
6 Correct 3 ms 14168 KB Output is correct
7 Correct 3 ms 14168 KB Output is correct
8 Correct 3 ms 14168 KB Output is correct
9 Correct 3 ms 14168 KB Output is correct
10 Correct 3 ms 14168 KB Output is correct
11 Correct 3 ms 14168 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 3 ms 14168 KB Output is correct
14 Correct 3 ms 14168 KB Output is correct
15 Correct 3 ms 14168 KB Output is correct
16 Correct 3 ms 14168 KB Output is correct
17 Correct 3 ms 14168 KB Output is correct
18 Correct 3 ms 14424 KB Output is correct
19 Correct 5 ms 14424 KB Output is correct
20 Correct 3 ms 14168 KB Output is correct
21 Correct 3 ms 14168 KB Output is correct
22 Correct 3 ms 14168 KB Output is correct
23 Correct 3 ms 14168 KB Output is correct
24 Correct 3 ms 14424 KB Output is correct
25 Correct 3 ms 14424 KB Output is correct
26 Correct 3 ms 14424 KB Output is correct
27 Correct 3 ms 14424 KB Output is correct
28 Correct 4 ms 14424 KB Output is correct
29 Correct 3 ms 14168 KB Output is correct
30 Correct 3 ms 14168 KB Output is correct
31 Correct 3 ms 14676 KB Output is correct
32 Correct 4 ms 14168 KB Output is correct
33 Correct 3 ms 14168 KB Output is correct
34 Correct 3 ms 14168 KB Output is correct
35 Correct 3 ms 14168 KB Output is correct
36 Correct 4 ms 14424 KB Output is correct
37 Correct 3 ms 14424 KB Output is correct
38 Correct 4 ms 14424 KB Output is correct
39 Correct 3 ms 14168 KB Output is correct
40 Correct 3 ms 14168 KB Output is correct
41 Correct 4 ms 14168 KB Output is correct
42 Correct 3 ms 14168 KB Output is correct
43 Correct 413 ms 18364 KB Output is correct
44 Incorrect 586 ms 24244 KB 1st lines differ - on the 1st token, expected: '913758140', found: '24813050'
45 Halted 0 ms 0 KB -