Submission #1078475

# Submission time Handle Problem Language Result Execution time Memory
1078475 2024-08-27T17:59:58 Z allin27x Digital Circuit (IOI22_circuit) C++17
13 / 100
3000 ms 14416 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() <= 1) 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++) {
        if (ar[i]) {
            res -= rel[i]; res %= mod; res += mod; res %= mod;
            ar[i] = 0;
        } else {
            res += rel[i]; res %= mod;
            ar[i] = 1;
        }
    }
    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;
      |                                           ^
# Verdict Execution time Memory 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 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 4 ms 9816 KB Output is correct
8 Correct 5 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 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 4 ms 9816 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 7 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
# Verdict Execution time Memory 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 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 4 ms 9816 KB Output is correct
8 Correct 5 ms 9708 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9816 KB Output is correct
15 Correct 4 ms 9816 KB Output is correct
16 Correct 4 ms 9816 KB Output is correct
17 Correct 7 ms 9816 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 4 ms 9816 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Incorrect 6 ms 9816 KB 1st lines differ - on the 1st token, expected: '759476520', found: '209535362'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 497 ms 12120 KB Output is correct
2 Correct 651 ms 14220 KB Output is correct
3 Correct 657 ms 14416 KB Output is correct
4 Correct 634 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 12120 KB Output is correct
2 Correct 651 ms 14220 KB Output is correct
3 Correct 657 ms 14416 KB Output is correct
4 Correct 634 ms 14416 KB Output is correct
5 Execution timed out 3013 ms 12112 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 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 4 ms 9816 KB Output is correct
8 Correct 4 ms 9816 KB Output is correct
9 Correct 7 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 497 ms 12120 KB Output is correct
14 Correct 651 ms 14220 KB Output is correct
15 Correct 657 ms 14416 KB Output is correct
16 Correct 634 ms 14416 KB Output is correct
17 Execution timed out 3013 ms 12112 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 4 ms 9816 KB Output is correct
8 Correct 5 ms 9708 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9816 KB Output is correct
15 Correct 4 ms 9816 KB Output is correct
16 Correct 4 ms 9816 KB Output is correct
17 Correct 7 ms 9816 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 4 ms 9816 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Incorrect 6 ms 9816 KB 1st lines differ - on the 1st token, expected: '759476520', found: '209535362'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 4 ms 9816 KB Output is correct
8 Correct 5 ms 9708 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9816 KB Output is correct
15 Correct 4 ms 9816 KB Output is correct
16 Correct 4 ms 9816 KB Output is correct
17 Correct 7 ms 9816 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 4 ms 9816 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Incorrect 6 ms 9816 KB 1st lines differ - on the 1st token, expected: '759476520', found: '209535362'
22 Halted 0 ms 0 KB -