Submission #932574

# Submission time Handle Problem Language Result Execution time Memory
932574 2024-02-23T18:08:55 Z velislavgarkov Digital Circuit (IOI22_circuit) C++17
46 / 100
620 ms 35756 KB
#include "circuit.h"
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=1e5+10;
const long long mod=1e9+2022;
vector <int> v[MAXN];
vector <long long> pref[MAXN], suf[MAXN];
long long mult[MAXN];
long long tree[4*MAXN][2], val[MAXN];
int lazy[MAXN];
int start[MAXN];
int n, m;
void precomp(int x) {
    if (v[x].empty()) {
        mult[x]=1;
        return;
    }
    pref[x].resize(v[x].size());
    suf[x].resize(v[x].size());
    mult[x]=v[x].size();
    for (int i=0;i<v[x].size();i++) {
        precomp(v[x][i]);
        if (i==0) pref[x][i]=mult[v[x][i]];
        else pref[x][i]=(pref[x][i-1]*mult[v[x][i]])%mod;
        mult[x]=(mult[x]*mult[v[x][i]])%mod;
    }
    for (int i=v[x].size()-1;i>=0;i--) {
        if (i==v[x].size()-1) suf[x][i]=mult[v[x][i]];
        else suf[x][i]=(suf[x][i+1]*mult[v[x][i]])%mod;
    }
}
void dfs(int x, long long ways) {
    if (x>=n) {
        val[x-n]=ways;
        //cout << x << ' ' << ways << endl;
        return;
    }
    long long s;
    for (int i=0;i<v[x].size();i++) {
        s=1;
        if (i>0) s*=pref[x][i-1];
        if (i<v[x].size()-1) s*=suf[x][i+1];
        s%=mod;
        dfs(v[x][i],(ways*s)%mod);
    }
}
void build_tree(int node, int l, int r) {
    if (l==r) {
        tree[node][0]=tree[node][1]=0;
        tree[node][start[l]]=val[l];
        return;
    }
    int mid=(l+r)/2;
    build_tree(node*2,l,mid);
    build_tree(node*2+1,mid+1,r);
    tree[node][0]=(tree[node*2][0]+tree[node*2+1][0])%mod;
    tree[node][1]=(tree[node*2][1]+tree[node*2+1][1])%mod;
}
void push_lazy(int node, int l, int r) {
    if (l!=r && lazy[node]%2==1) {
        lazy[node*2]++;
        lazy[node*2+1]++;
        swap(tree[node*2][0],tree[node*2][1]);
        swap(tree[node*2+1][0],tree[node*2+1][1]);
    }
    lazy[node]=0;
}
void update(int node, int l, int r, int ql, int qr) {
    if (ql>r || qr<l) return;
    push_lazy(node,l,r);
    if (l>=ql && r<=qr) {
        swap(tree[node][0],tree[node][1]);
        lazy[node]++;
        return;
    }
    int mid=(l+r)/2;
    update(node*2,l,mid,ql,qr);
    update(node*2+1,mid+1,r,ql,qr);
    tree[node][0]=(tree[node*2][0]+tree[node*2+1][0])%mod;
    tree[node][1]=(tree[node*2][1]+tree[node*2+1][1])%mod;
}
void init(int N, int M, vector <int> p, vector <int> a) {
    n=N;
    m=M;
    for (int i=1;i<n+m;i++) v[p[i]].push_back(i);
    for (int i=0;i<m;i++) start[i]=a[i];
    precomp(0);
    dfs(0,1);
    build_tree(1,0,m-1);
}
int count_ways(int l, int r) {
    l-=n; r-=n;
    update(1,0,m-1,l,r);
    return tree[1][1];
}

Compilation message

circuit.cpp: In function 'void precomp(int)':
circuit.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i=0;i<v[x].size();i++) {
      |                  ~^~~~~~~~~~~~
circuit.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (i==v[x].size()-1) suf[x][i]=mult[v[x][i]];
      |             ~^~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfs(int, long long int)':
circuit.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i=0;i<v[x].size();i++) {
      |                  ~^~~~~~~~~~~~
circuit.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         if (i<v[x].size()-1) s*=suf[x][i+1];
      |             ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11608 KB Output is correct
2 Correct 2 ms 11860 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Correct 2 ms 11608 KB Output is correct
5 Correct 3 ms 11608 KB Output is correct
6 Correct 3 ms 11788 KB Output is correct
7 Correct 3 ms 11608 KB Output is correct
8 Correct 3 ms 11608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11608 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 3 ms 11864 KB Output is correct
6 Correct 3 ms 11864 KB Output is correct
7 Correct 3 ms 11864 KB Output is correct
8 Correct 4 ms 11864 KB Output is correct
9 Correct 3 ms 12116 KB Output is correct
10 Correct 3 ms 11864 KB Output is correct
11 Correct 3 ms 11864 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11608 KB Output is correct
2 Correct 2 ms 11860 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Correct 2 ms 11608 KB Output is correct
5 Correct 3 ms 11608 KB Output is correct
6 Correct 3 ms 11788 KB Output is correct
7 Correct 3 ms 11608 KB Output is correct
8 Correct 3 ms 11608 KB Output is correct
9 Correct 3 ms 11608 KB Output is correct
10 Correct 3 ms 11608 KB Output is correct
11 Correct 2 ms 11864 KB Output is correct
12 Correct 2 ms 11864 KB Output is correct
13 Correct 3 ms 11864 KB Output is correct
14 Correct 3 ms 11864 KB Output is correct
15 Correct 3 ms 11864 KB Output is correct
16 Correct 4 ms 11864 KB Output is correct
17 Correct 3 ms 12116 KB Output is correct
18 Correct 3 ms 11864 KB Output is correct
19 Correct 3 ms 11864 KB Output is correct
20 Correct 3 ms 11864 KB Output is correct
21 Correct 3 ms 11864 KB Output is correct
22 Correct 3 ms 11864 KB Output is correct
23 Correct 5 ms 11864 KB Output is correct
24 Correct 5 ms 11876 KB Output is correct
25 Correct 4 ms 11864 KB Output is correct
26 Correct 4 ms 11864 KB Output is correct
27 Correct 3 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 4 ms 11608 KB Output is correct
30 Correct 2 ms 11608 KB Output is correct
31 Correct 2 ms 11864 KB Output is correct
32 Correct 4 ms 11864 KB Output is correct
33 Correct 2 ms 11860 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 3 ms 11608 KB Output is correct
36 Correct 3 ms 11792 KB Output is correct
37 Correct 3 ms 11864 KB Output is correct
38 Correct 4 ms 11860 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 3 ms 11864 KB Output is correct
41 Correct 3 ms 11864 KB Output is correct
42 Correct 2 ms 11860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 435 ms 17752 KB Output is correct
2 Runtime error 43 ms 35756 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 435 ms 17752 KB Output is correct
2 Runtime error 43 ms 35756 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11608 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 3 ms 11864 KB Output is correct
6 Correct 3 ms 11864 KB Output is correct
7 Correct 3 ms 11864 KB Output is correct
8 Correct 4 ms 11864 KB Output is correct
9 Correct 3 ms 12116 KB Output is correct
10 Correct 3 ms 11864 KB Output is correct
11 Correct 3 ms 11864 KB Output is correct
12 Correct 3 ms 11864 KB Output is correct
13 Correct 435 ms 17752 KB Output is correct
14 Runtime error 43 ms 35756 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11608 KB Output is correct
2 Correct 2 ms 11860 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Correct 2 ms 11608 KB Output is correct
5 Correct 3 ms 11608 KB Output is correct
6 Correct 3 ms 11788 KB Output is correct
7 Correct 3 ms 11608 KB Output is correct
8 Correct 3 ms 11608 KB Output is correct
9 Correct 3 ms 11608 KB Output is correct
10 Correct 3 ms 11608 KB Output is correct
11 Correct 2 ms 11864 KB Output is correct
12 Correct 2 ms 11864 KB Output is correct
13 Correct 3 ms 11864 KB Output is correct
14 Correct 3 ms 11864 KB Output is correct
15 Correct 3 ms 11864 KB Output is correct
16 Correct 4 ms 11864 KB Output is correct
17 Correct 3 ms 12116 KB Output is correct
18 Correct 3 ms 11864 KB Output is correct
19 Correct 3 ms 11864 KB Output is correct
20 Correct 3 ms 11864 KB Output is correct
21 Correct 3 ms 11864 KB Output is correct
22 Correct 3 ms 11864 KB Output is correct
23 Correct 5 ms 11864 KB Output is correct
24 Correct 5 ms 11876 KB Output is correct
25 Correct 4 ms 11864 KB Output is correct
26 Correct 4 ms 11864 KB Output is correct
27 Correct 3 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 4 ms 11608 KB Output is correct
30 Correct 2 ms 11608 KB Output is correct
31 Correct 2 ms 11864 KB Output is correct
32 Correct 4 ms 11864 KB Output is correct
33 Correct 2 ms 11860 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 3 ms 11608 KB Output is correct
36 Correct 3 ms 11792 KB Output is correct
37 Correct 3 ms 11864 KB Output is correct
38 Correct 4 ms 11860 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 3 ms 11864 KB Output is correct
41 Correct 3 ms 11864 KB Output is correct
42 Correct 2 ms 11860 KB Output is correct
43 Correct 420 ms 12012 KB Output is correct
44 Correct 544 ms 12120 KB Output is correct
45 Correct 537 ms 12120 KB Output is correct
46 Correct 573 ms 12376 KB Output is correct
47 Correct 539 ms 12376 KB Output is correct
48 Correct 557 ms 12376 KB Output is correct
49 Correct 520 ms 12376 KB Output is correct
50 Correct 529 ms 12376 KB Output is correct
51 Correct 509 ms 12024 KB Output is correct
52 Correct 542 ms 12016 KB Output is correct
53 Correct 490 ms 12632 KB Output is correct
54 Correct 538 ms 12376 KB Output is correct
55 Correct 530 ms 12120 KB Output is correct
56 Correct 582 ms 11864 KB Output is correct
57 Correct 572 ms 11864 KB Output is correct
58 Correct 577 ms 12632 KB Output is correct
59 Correct 574 ms 12888 KB Output is correct
60 Correct 547 ms 12888 KB Output is correct
61 Correct 560 ms 12120 KB Output is correct
62 Correct 609 ms 11864 KB Output is correct
63 Correct 529 ms 11864 KB Output is correct
64 Correct 620 ms 11864 KB Output is correct
65 Correct 312 ms 11864 KB Output is correct
66 Correct 528 ms 12196 KB Output is correct
67 Correct 555 ms 12280 KB Output is correct
68 Correct 528 ms 12372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11608 KB Output is correct
2 Correct 2 ms 11860 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Correct 2 ms 11608 KB Output is correct
5 Correct 3 ms 11608 KB Output is correct
6 Correct 3 ms 11788 KB Output is correct
7 Correct 3 ms 11608 KB Output is correct
8 Correct 3 ms 11608 KB Output is correct
9 Correct 3 ms 11608 KB Output is correct
10 Correct 3 ms 11608 KB Output is correct
11 Correct 2 ms 11864 KB Output is correct
12 Correct 2 ms 11864 KB Output is correct
13 Correct 3 ms 11864 KB Output is correct
14 Correct 3 ms 11864 KB Output is correct
15 Correct 3 ms 11864 KB Output is correct
16 Correct 4 ms 11864 KB Output is correct
17 Correct 3 ms 12116 KB Output is correct
18 Correct 3 ms 11864 KB Output is correct
19 Correct 3 ms 11864 KB Output is correct
20 Correct 3 ms 11864 KB Output is correct
21 Correct 3 ms 11864 KB Output is correct
22 Correct 3 ms 11864 KB Output is correct
23 Correct 5 ms 11864 KB Output is correct
24 Correct 5 ms 11876 KB Output is correct
25 Correct 4 ms 11864 KB Output is correct
26 Correct 4 ms 11864 KB Output is correct
27 Correct 3 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 4 ms 11608 KB Output is correct
30 Correct 2 ms 11608 KB Output is correct
31 Correct 2 ms 11864 KB Output is correct
32 Correct 4 ms 11864 KB Output is correct
33 Correct 2 ms 11860 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 3 ms 11608 KB Output is correct
36 Correct 3 ms 11792 KB Output is correct
37 Correct 3 ms 11864 KB Output is correct
38 Correct 4 ms 11860 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 3 ms 11864 KB Output is correct
41 Correct 3 ms 11864 KB Output is correct
42 Correct 2 ms 11860 KB Output is correct
43 Correct 435 ms 17752 KB Output is correct
44 Runtime error 43 ms 35756 KB Execution killed with signal 6
45 Halted 0 ms 0 KB -