Submission #683415

# Submission time Handle Problem Language Result Execution time Memory
683415 2023-01-18T10:41:57 Z sunwukong123 Digital Circuit (IOI22_circuit) C++17
100 / 100
1270 ms 51100 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(i,s,e) for(int i = s; i <= (int)e; ++i)
#define DEC(i,s,e) for(int i = s; i >= (int)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define reach 
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first 
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
typedef tuple<int,int,int,int> ti4;
int rand(int a, int b) { return a + rng() % (b-a+1); }
const int MOD =  1'000'002'022;
const int inf = (int)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; }
template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; }
const int MAXN = 200005;
vector<int> V[MAXN];
int state[MAXN];
int C[MAXN];
int choices[MAXN];
int n,k;

void pre(int x) {
    int S=V[x].size();
    choices[x]=max(1ll,S);
    
    for(auto v:V[x]) {
      pre(v);
      choices[x]=choices[x]*choices[v]%MOD;
    }
}
void dfs(int x, int mult) {
  int S=V[x].size();
  if(S == 0) {
    C[x-n]=mult;
    return;
  }
  int pre[S+3]; 
  int suf[S+3];
  memset(pre, 0, sizeof pre);
  memset(suf, 0, sizeof suf);
  pre[0]=1;
  suf[S+1]=1;
  FOR(i,1,S) {
    int node = V[x][i-1];
    pre[i] = (pre[i-1] * choices[node]) % MOD;

  }
  DEC(i,S,1) {
    int node = V[x][i-1];
    suf[i] = (suf[i+1] * choices[node]) % MOD;
  }

  FOR(i,1,S) {
    int node = V[x][i-1];
    int mul = pre[i-1] * suf[i+1] % MOD;
    dfs(node, mult * mul % MOD);
  }

}

struct node {
  int s,e,m,pot,lazy,sum;
  node *l, *r;
  node (int _s, int _e) {
    s=_s;e=_e;m=(s+e)/2;
    if(s!=e){
      l=new node(s,m);
      r=new node(m+1,e);
      pot=(l->pot + r->pot)%MOD;
      sum = lazy = 0;
    } else {
      sum = lazy = 0;
      pot=C[s];
    }
  }
  void value() {
    if(lazy==0)return;
    sum=((pot-sum)%MOD+MOD)%MOD;


    if(s==e){
      lazy=0;
      value();
      return;
    }
    l->lazy^=lazy;
    r->lazy^=lazy;
    lazy=0;
  }
  void update(int x, int y) {
   
    value();
    if(s==x&&e==y) {
      lazy=1;
      return;
    }
    if(x>m)r->update(x,y);
    else if(y<=m)l->update(x,y);
    else l->update(x,m), r->update(m+1,y);
    l->value(); r->value();
    sum = (l->sum + r->sum)%MOD;
    //assert(sum<=pot);
  }
} *seg;

void init(int32_t n, int32_t m, vector<int32_t> P, vector<int32_t> A) {
    ::n=n;
    ::k=m;
   
    FOR(i,1,n+m-1) {
      V[P[i]].pb(i);
    }
    FOR(i,0,m-1) {
      state[i]=A[i];
    }
    pre(0);
    dfs(0,1);
    seg=new node(0,m-1);
    FOR(i,0,m-1) {
      if(state[i])seg->update(i,i);
    }
}

int32_t count_ways(int32_t L, int32_t R) {
    L-=n;R-=n;
    seg->update(L,R);
    seg->value();
    return seg->sum;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5200 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 3 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5200 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 KB Output is correct
10 Correct 3 ms 5456 KB Output is correct
11 Correct 3 ms 5456 KB Output is correct
12 Correct 4 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5200 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 3 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5456 KB Output is correct
19 Correct 3 ms 5456 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5220 KB Output is correct
25 Correct 3 ms 5200 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 5 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5200 KB Output is correct
33 Correct 4 ms 5200 KB Output is correct
34 Correct 4 ms 5200 KB Output is correct
35 Correct 3 ms 5200 KB Output is correct
36 Correct 3 ms 5456 KB Output is correct
37 Correct 3 ms 5456 KB Output is correct
38 Correct 4 ms 5392 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 3 ms 5200 KB Output is correct
42 Correct 3 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 645 ms 12880 KB Output is correct
2 Correct 960 ms 20864 KB Output is correct
3 Correct 1105 ms 20868 KB Output is correct
4 Correct 923 ms 20880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 645 ms 12880 KB Output is correct
2 Correct 960 ms 20864 KB Output is correct
3 Correct 1105 ms 20868 KB Output is correct
4 Correct 923 ms 20880 KB Output is correct
5 Correct 815 ms 12964 KB Output is correct
6 Correct 1127 ms 20884 KB Output is correct
7 Correct 984 ms 20876 KB Output is correct
8 Correct 868 ms 20892 KB Output is correct
9 Correct 514 ms 5456 KB Output is correct
10 Correct 1132 ms 5968 KB Output is correct
11 Correct 792 ms 5968 KB Output is correct
12 Correct 1002 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5068 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5200 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 KB Output is correct
10 Correct 3 ms 5456 KB Output is correct
11 Correct 3 ms 5456 KB Output is correct
12 Correct 4 ms 5200 KB Output is correct
13 Correct 645 ms 12880 KB Output is correct
14 Correct 960 ms 20864 KB Output is correct
15 Correct 1105 ms 20868 KB Output is correct
16 Correct 923 ms 20880 KB Output is correct
17 Correct 815 ms 12964 KB Output is correct
18 Correct 1127 ms 20884 KB Output is correct
19 Correct 984 ms 20876 KB Output is correct
20 Correct 868 ms 20892 KB Output is correct
21 Correct 514 ms 5456 KB Output is correct
22 Correct 1132 ms 5968 KB Output is correct
23 Correct 792 ms 5968 KB Output is correct
24 Correct 1002 ms 5968 KB Output is correct
25 Correct 1176 ms 28836 KB Output is correct
26 Correct 1192 ms 29184 KB Output is correct
27 Correct 1196 ms 29212 KB Output is correct
28 Correct 822 ms 29240 KB Output is correct
29 Correct 983 ms 51100 KB Output is correct
30 Correct 951 ms 51072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5200 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 3 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5456 KB Output is correct
19 Correct 3 ms 5456 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5220 KB Output is correct
25 Correct 3 ms 5200 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 5 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5200 KB Output is correct
33 Correct 4 ms 5200 KB Output is correct
34 Correct 4 ms 5200 KB Output is correct
35 Correct 3 ms 5200 KB Output is correct
36 Correct 3 ms 5456 KB Output is correct
37 Correct 3 ms 5456 KB Output is correct
38 Correct 4 ms 5392 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 3 ms 5200 KB Output is correct
42 Correct 3 ms 5200 KB Output is correct
43 Correct 663 ms 5584 KB Output is correct
44 Correct 658 ms 5584 KB Output is correct
45 Correct 778 ms 5712 KB Output is correct
46 Correct 786 ms 6224 KB Output is correct
47 Correct 719 ms 6148 KB Output is correct
48 Correct 1032 ms 6224 KB Output is correct
49 Correct 980 ms 6216 KB Output is correct
50 Correct 686 ms 6152 KB Output is correct
51 Correct 889 ms 6020 KB Output is correct
52 Correct 869 ms 6096 KB Output is correct
53 Correct 885 ms 6148 KB Output is correct
54 Correct 949 ms 6156 KB Output is correct
55 Correct 832 ms 6020 KB Output is correct
56 Correct 878 ms 5968 KB Output is correct
57 Correct 1042 ms 5936 KB Output is correct
58 Correct 1270 ms 7296 KB Output is correct
59 Correct 964 ms 7176 KB Output is correct
60 Correct 1039 ms 7228 KB Output is correct
61 Correct 772 ms 5772 KB Output is correct
62 Correct 853 ms 5712 KB Output is correct
63 Correct 957 ms 5840 KB Output is correct
64 Correct 824 ms 5968 KB Output is correct
65 Correct 522 ms 5456 KB Output is correct
66 Correct 960 ms 5968 KB Output is correct
67 Correct 898 ms 5892 KB Output is correct
68 Correct 799 ms 5964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5200 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5200 KB Output is correct
6 Correct 4 ms 5200 KB Output is correct
7 Correct 3 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5456 KB Output is correct
19 Correct 3 ms 5456 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5220 KB Output is correct
25 Correct 3 ms 5200 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 5 ms 5200 KB Output is correct
30 Correct 3 ms 5200 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5200 KB Output is correct
33 Correct 4 ms 5200 KB Output is correct
34 Correct 4 ms 5200 KB Output is correct
35 Correct 3 ms 5200 KB Output is correct
36 Correct 3 ms 5456 KB Output is correct
37 Correct 3 ms 5456 KB Output is correct
38 Correct 4 ms 5392 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 3 ms 5200 KB Output is correct
42 Correct 3 ms 5200 KB Output is correct
43 Correct 645 ms 12880 KB Output is correct
44 Correct 960 ms 20864 KB Output is correct
45 Correct 1105 ms 20868 KB Output is correct
46 Correct 923 ms 20880 KB Output is correct
47 Correct 815 ms 12964 KB Output is correct
48 Correct 1127 ms 20884 KB Output is correct
49 Correct 984 ms 20876 KB Output is correct
50 Correct 868 ms 20892 KB Output is correct
51 Correct 514 ms 5456 KB Output is correct
52 Correct 1132 ms 5968 KB Output is correct
53 Correct 792 ms 5968 KB Output is correct
54 Correct 1002 ms 5968 KB Output is correct
55 Correct 1176 ms 28836 KB Output is correct
56 Correct 1192 ms 29184 KB Output is correct
57 Correct 1196 ms 29212 KB Output is correct
58 Correct 822 ms 29240 KB Output is correct
59 Correct 983 ms 51100 KB Output is correct
60 Correct 951 ms 51072 KB Output is correct
61 Correct 663 ms 5584 KB Output is correct
62 Correct 658 ms 5584 KB Output is correct
63 Correct 778 ms 5712 KB Output is correct
64 Correct 786 ms 6224 KB Output is correct
65 Correct 719 ms 6148 KB Output is correct
66 Correct 1032 ms 6224 KB Output is correct
67 Correct 980 ms 6216 KB Output is correct
68 Correct 686 ms 6152 KB Output is correct
69 Correct 889 ms 6020 KB Output is correct
70 Correct 869 ms 6096 KB Output is correct
71 Correct 885 ms 6148 KB Output is correct
72 Correct 949 ms 6156 KB Output is correct
73 Correct 832 ms 6020 KB Output is correct
74 Correct 878 ms 5968 KB Output is correct
75 Correct 1042 ms 5936 KB Output is correct
76 Correct 1270 ms 7296 KB Output is correct
77 Correct 964 ms 7176 KB Output is correct
78 Correct 1039 ms 7228 KB Output is correct
79 Correct 772 ms 5772 KB Output is correct
80 Correct 853 ms 5712 KB Output is correct
81 Correct 957 ms 5840 KB Output is correct
82 Correct 824 ms 5968 KB Output is correct
83 Correct 522 ms 5456 KB Output is correct
84 Correct 960 ms 5968 KB Output is correct
85 Correct 898 ms 5892 KB Output is correct
86 Correct 799 ms 5964 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 739 ms 25972 KB Output is correct
89 Correct 1167 ms 18172 KB Output is correct
90 Correct 1006 ms 19576 KB Output is correct
91 Correct 982 ms 29852 KB Output is correct
92 Correct 1137 ms 29808 KB Output is correct
93 Correct 1129 ms 29848 KB Output is correct
94 Correct 1134 ms 29848 KB Output is correct
95 Correct 942 ms 29816 KB Output is correct
96 Correct 979 ms 26864 KB Output is correct
97 Correct 994 ms 26868 KB Output is correct
98 Correct 815 ms 28452 KB Output is correct
99 Correct 1150 ms 29232 KB Output is correct
100 Correct 1086 ms 27892 KB Output is correct
101 Correct 1110 ms 27004 KB Output is correct
102 Correct 1097 ms 25472 KB Output is correct
103 Correct 932 ms 51076 KB Output is correct
104 Correct 1050 ms 50288 KB Output is correct
105 Correct 1197 ms 50352 KB Output is correct
106 Correct 1067 ms 21368 KB Output is correct
107 Correct 1175 ms 20220 KB Output is correct
108 Correct 1139 ms 22236 KB Output is correct
109 Correct 930 ms 25588 KB Output is correct