답안 #1078489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078489 2024-08-27T18:22:30 Z allin27x 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 12120 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000002022;

const int MAXN = 100007;
int ar[MAXN];
int n,m;
vector<int> ch[2*MAXN];
int mlt[2*MAXN];
int sgt[4*MAXN];
int rel[MAXN];
int res = 0;


void update(int i, int v) {
    for (sgt[i+=2*MAXN]=v; i>1; i>>=1) sgt[i>>1] = (sgt[i] * sgt[i^1]) % mod;
}

int query(int l, int r) {
    int res = 1;
    for (l+=2*MAXN, r+=2*MAXN+1; l<r; l>>=1, r>>=1) {
        if (l&1) res *= sgt[l++], res %= mod;
        if (r&1) res *= sgt[--r], res %= mod;
    }
    return res;
}

int dfs0(int i) {
    vector<int> vl;
    for (int c: ch[i]) vl.push_back(dfs0(c));
    if (vl.size() == 0) return 1;
    int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod;
    for (int i=0; i<vl.size(); i++) update(i, vl[i]);
    for (int j=0; j<vl.size(); j++) {
        mlt[ch[i][j]] = ((query(0, j-1)) * query(j+1, vl.size()-1)) % mod;
    }
    return ans;
}

void dfs1(int i, int p) {
    if (ch[i].size() == 0) {
        rel[i-n] = (p*mlt[i]) % mod;
    } else {
        for (int c: ch[i]) {
            dfs1(c, (p*mlt[i]) % mod);
        }
    }
}

void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
    for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
    for (int i=1; i<M+N; i++) ch[P[i]].push_back(i);
    for (int i=0; i<4*MAXN; i++) sgt[i] = 1;
    for (int i=0; i<2*MAXN; i++) mlt[i] = 1;
    dfs0(0); dfs1(0,1);
    for (int i=0; i<M; i++) if (A[i]) res += rel[i], res %= mod;
}

signed count_ways(signed L, signed R) {
    L-=n; R-=n;
    for (int i=L; i<=R; i++) ar[i] ^= 1;
    res = 0;
    for (int i=0; i<m; i++) res += ar[i] * rel[i], res %= mod;
    return  res;
}

Compilation message

circuit.cpp: In function 'long long int dfs0(long long int)':
circuit.cpp:33:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod;
      |                                        ~^~~~~~~~~~
circuit.cpp:34:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i=0; i<vl.size(); i++) update(i, vl[i]);
      |                   ~^~~~~~~~~~
circuit.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int j=0; j<vl.size(); j++) {
      |                   ~^~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:52:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   52 |     for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
      |     ^~~
circuit.cpp:52:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |     for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
      |                                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 5 ms 9672 KB Output is correct
4 Correct 5 ms 9816 KB Output is correct
5 Correct 4 ms 9816 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 4 ms 9768 KB Output is correct
9 Correct 6 ms 9816 KB Output is correct
10 Correct 5 ms 9816 KB Output is correct
11 Correct 5 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 5 ms 9672 KB Output is correct
12 Correct 5 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9816 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 4 ms 9768 KB Output is correct
17 Correct 6 ms 9816 KB Output is correct
18 Correct 5 ms 9816 KB Output is correct
19 Correct 5 ms 9816 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 9772 KB Output is correct
23 Correct 4 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9816 KB Output is correct
26 Correct 5 ms 9856 KB Output is correct
27 Correct 4 ms 9816 KB Output is correct
28 Correct 5 ms 9816 KB Output is correct
29 Correct 4 ms 9816 KB Output is correct
30 Correct 4 ms 9892 KB Output is correct
31 Correct 5 ms 10072 KB Output is correct
32 Correct 5 ms 9816 KB Output is correct
33 Correct 5 ms 9764 KB Output is correct
34 Correct 4 ms 9716 KB Output is correct
35 Correct 6 ms 9816 KB Output is correct
36 Correct 5 ms 9816 KB Output is correct
37 Correct 5 ms 9860 KB Output is correct
38 Correct 4 ms 9852 KB Output is correct
39 Correct 4 ms 9816 KB Output is correct
40 Correct 4 ms 9816 KB Output is correct
41 Correct 4 ms 9816 KB Output is correct
42 Correct 4 ms 9796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3088 ms 12120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3088 ms 12120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 5 ms 9672 KB Output is correct
4 Correct 5 ms 9816 KB Output is correct
5 Correct 4 ms 9816 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 4 ms 9768 KB Output is correct
9 Correct 6 ms 9816 KB Output is correct
10 Correct 5 ms 9816 KB Output is correct
11 Correct 5 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Execution timed out 3088 ms 12120 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 5 ms 9672 KB Output is correct
12 Correct 5 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9816 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 4 ms 9768 KB Output is correct
17 Correct 6 ms 9816 KB Output is correct
18 Correct 5 ms 9816 KB Output is correct
19 Correct 5 ms 9816 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 9772 KB Output is correct
23 Correct 4 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9816 KB Output is correct
26 Correct 5 ms 9856 KB Output is correct
27 Correct 4 ms 9816 KB Output is correct
28 Correct 5 ms 9816 KB Output is correct
29 Correct 4 ms 9816 KB Output is correct
30 Correct 4 ms 9892 KB Output is correct
31 Correct 5 ms 10072 KB Output is correct
32 Correct 5 ms 9816 KB Output is correct
33 Correct 5 ms 9764 KB Output is correct
34 Correct 4 ms 9716 KB Output is correct
35 Correct 6 ms 9816 KB Output is correct
36 Correct 5 ms 9816 KB Output is correct
37 Correct 5 ms 9860 KB Output is correct
38 Correct 4 ms 9852 KB Output is correct
39 Correct 4 ms 9816 KB Output is correct
40 Correct 4 ms 9816 KB Output is correct
41 Correct 4 ms 9816 KB Output is correct
42 Correct 4 ms 9796 KB Output is correct
43 Correct 1246 ms 9816 KB Output is correct
44 Correct 1618 ms 10072 KB Output is correct
45 Correct 1732 ms 10072 KB Output is correct
46 Correct 2470 ms 10072 KB Output is correct
47 Correct 2550 ms 10072 KB Output is correct
48 Correct 2549 ms 10072 KB Output is correct
49 Correct 2526 ms 10072 KB Output is correct
50 Correct 2692 ms 10072 KB Output is correct
51 Correct 2702 ms 10124 KB Output is correct
52 Correct 2536 ms 10124 KB Output is correct
53 Correct 576 ms 10584 KB Output is correct
54 Correct 2580 ms 10072 KB Output is correct
55 Correct 2559 ms 10072 KB Output is correct
56 Correct 2541 ms 10072 KB Output is correct
57 Correct 2496 ms 9816 KB Output is correct
58 Correct 2542 ms 10584 KB Output is correct
59 Correct 2543 ms 10948 KB Output is correct
60 Correct 2693 ms 10944 KB Output is correct
61 Correct 1540 ms 10072 KB Output is correct
62 Correct 1943 ms 9816 KB Output is correct
63 Correct 2044 ms 9816 KB Output is correct
64 Correct 2561 ms 9816 KB Output is correct
65 Correct 732 ms 9816 KB Output is correct
66 Correct 2202 ms 10072 KB Output is correct
67 Correct 2199 ms 10072 KB Output is correct
68 Correct 2385 ms 10072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 5 ms 9672 KB Output is correct
12 Correct 5 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9816 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 4 ms 9768 KB Output is correct
17 Correct 6 ms 9816 KB Output is correct
18 Correct 5 ms 9816 KB Output is correct
19 Correct 5 ms 9816 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 9772 KB Output is correct
23 Correct 4 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9816 KB Output is correct
26 Correct 5 ms 9856 KB Output is correct
27 Correct 4 ms 9816 KB Output is correct
28 Correct 5 ms 9816 KB Output is correct
29 Correct 4 ms 9816 KB Output is correct
30 Correct 4 ms 9892 KB Output is correct
31 Correct 5 ms 10072 KB Output is correct
32 Correct 5 ms 9816 KB Output is correct
33 Correct 5 ms 9764 KB Output is correct
34 Correct 4 ms 9716 KB Output is correct
35 Correct 6 ms 9816 KB Output is correct
36 Correct 5 ms 9816 KB Output is correct
37 Correct 5 ms 9860 KB Output is correct
38 Correct 4 ms 9852 KB Output is correct
39 Correct 4 ms 9816 KB Output is correct
40 Correct 4 ms 9816 KB Output is correct
41 Correct 4 ms 9816 KB Output is correct
42 Correct 4 ms 9796 KB Output is correct
43 Execution timed out 3088 ms 12120 KB Time limit exceeded
44 Halted 0 ms 0 KB -