Submission #821822

# Submission time Handle Problem Language Result Execution time Memory
821822 2023-08-11T17:58:33 Z I_Love_EliskaM_ Digital Circuit (IOI22_circuit) C++17
100 / 100
1020 ms 50036 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0; i<n; ++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;
#define int int64_t

const int N=2e5+5;
int n,m;
vector<int> adj[N];
int dp[N][2];
int a[N];
const int mod = 1e9+2022;

int f[N];
int z[N];

int one=1;

void dfs(int u) {
  z[u]=adj[u].size();
  z[u]=max(z[u],one);
  for(auto&v:adj[u]) {
    dfs(v);
    z[u]=(z[u]*z[v])%mod;
  }
}
void dfs(int u, int o) {
  vector<int> pr={1}, sf={1};
  for(auto&v:adj[u]) pr.pb( (pr.back()*z[v])%mod );
  reverse(all(adj[u]));
  for(auto&v:adj[u]) sf.pb( (sf.back()*z[v])%mod );
  reverse(all(sf));
  reverse(all(adj[u]));

  f[u]=o;

  forn(i,adj[u].size()) {
    int x = (o*pr[i])%mod;
    x = (x*sf[i+1])%mod;
    dfs(adj[u][i],x);
  }
}

const int sz=1<<17;
struct node {
  int sum=0,now=0,lazy=0;
};
node t[4*sz];
node merge(node a, node b) {
  node n;
  n.sum=(a.sum+b.sum)%mod;
  n.now=(a.now+b.now)%mod;
  n.lazy=0;
  return n;
}
void build(int v, int l, int r) {
  if (r-l==1) return;
  int m=(l+r)>>1;
  build(2*v+1,l,m);
  build(2*v+2,m,r);
  t[v]=merge(t[2*v+1],t[2*v+2]);
}
void build() {
  forn(i,m) {
    t[sz-1+i].sum=f[n+i];
    t[sz-1+i].now=a[i]*f[n+i];
    t[sz-1+i].lazy=0;
  }
  build(0,0,sz);
}

void push(int v) {
  if (t[v].lazy) {
    t[v].now=(t[v].sum-t[v].now+mod)%mod;
    t[2*v+1].lazy^=t[v].lazy;
    t[2*v+2].lazy^=t[v].lazy;
    t[v].lazy=0;
  }
}
void flip(int v, int l, int r, int lx, int rx) {
  if (t[v].lazy) push(v);
  if (rx<=l || r<=lx) return;
  if (lx<=l && r<=rx) {
    t[v].lazy^=1;
    push(v);
    return;
  }
  int m=(l+r)>>1;
  flip(2*v+1,l,m,lx,rx);
  flip(2*v+2,m,r,lx,rx);
  t[v]=merge(t[2*v+1],t[2*v+2]);
}
void flip(int l, int r) {
  flip(0,0,sz,l,r);
}

#undef int

void init(int _n, int _m, vector<int>p, vector<int>_a) {

  n=_n, m=_m;
  forn(i,m) a[i]=_a[i];
  for (int i=1; i<n+m; ++i) {
    adj[p[i]].pb(i);
  }
  dfs(0);
  dfs(0,1);
  build();

}

int count_ways(int l, int r) {
  flip(l-n,r-n+1);
  return t[0].now;
}

Compilation message

circuit.cpp: In function 'void dfs(int64_t, int64_t)':
circuit.cpp:4:33: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0; i<n; ++i)
......
   43 |   forn(i,adj[u].size()) {
      |        ~~~~~~~~~~~~~~~           
circuit.cpp:43:3: note: in expansion of macro 'forn'
   43 |   forn(i,adj[u].size()) {
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8016 KB Output is correct
2 Correct 5 ms 8004 KB Output is correct
3 Correct 5 ms 8144 KB Output is correct
4 Correct 4 ms 8144 KB Output is correct
5 Correct 4 ms 8144 KB Output is correct
6 Correct 6 ms 8144 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 4 ms 8212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8016 KB Output is correct
2 Correct 4 ms 8144 KB Output is correct
3 Correct 5 ms 8144 KB Output is correct
4 Correct 6 ms 8144 KB Output is correct
5 Correct 5 ms 8156 KB Output is correct
6 Correct 5 ms 8144 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 5 ms 8144 KB Output is correct
9 Correct 5 ms 8144 KB Output is correct
10 Correct 5 ms 8488 KB Output is correct
11 Correct 5 ms 8400 KB Output is correct
12 Correct 5 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8016 KB Output is correct
2 Correct 5 ms 8004 KB Output is correct
3 Correct 5 ms 8144 KB Output is correct
4 Correct 4 ms 8144 KB Output is correct
5 Correct 4 ms 8144 KB Output is correct
6 Correct 6 ms 8144 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 4 ms 8212 KB Output is correct
9 Correct 5 ms 8016 KB Output is correct
10 Correct 4 ms 8144 KB Output is correct
11 Correct 5 ms 8144 KB Output is correct
12 Correct 6 ms 8144 KB Output is correct
13 Correct 5 ms 8156 KB Output is correct
14 Correct 5 ms 8144 KB Output is correct
15 Correct 5 ms 8144 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 5 ms 8144 KB Output is correct
18 Correct 5 ms 8488 KB Output is correct
19 Correct 5 ms 8400 KB Output is correct
20 Correct 5 ms 8128 KB Output is correct
21 Correct 4 ms 8144 KB Output is correct
22 Correct 5 ms 8144 KB Output is correct
23 Correct 4 ms 8144 KB Output is correct
24 Correct 5 ms 8240 KB Output is correct
25 Correct 6 ms 8144 KB Output is correct
26 Correct 5 ms 8144 KB Output is correct
27 Correct 5 ms 8240 KB Output is correct
28 Correct 5 ms 8144 KB Output is correct
29 Correct 4 ms 8144 KB Output is correct
30 Correct 4 ms 8144 KB Output is correct
31 Correct 5 ms 8272 KB Output is correct
32 Correct 5 ms 8144 KB Output is correct
33 Correct 5 ms 8144 KB Output is correct
34 Correct 4 ms 8192 KB Output is correct
35 Correct 4 ms 8188 KB Output is correct
36 Correct 5 ms 8400 KB Output is correct
37 Correct 5 ms 8444 KB Output is correct
38 Correct 5 ms 8400 KB Output is correct
39 Correct 5 ms 8144 KB Output is correct
40 Correct 6 ms 8144 KB Output is correct
41 Correct 5 ms 8192 KB Output is correct
42 Correct 5 ms 8096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 13108 KB Output is correct
2 Correct 759 ms 18116 KB Output is correct
3 Correct 623 ms 18112 KB Output is correct
4 Correct 692 ms 18108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 13108 KB Output is correct
2 Correct 759 ms 18116 KB Output is correct
3 Correct 623 ms 18112 KB Output is correct
4 Correct 692 ms 18108 KB Output is correct
5 Correct 553 ms 13112 KB Output is correct
6 Correct 803 ms 18232 KB Output is correct
7 Correct 883 ms 18108 KB Output is correct
8 Correct 488 ms 15756 KB Output is correct
9 Correct 433 ms 8516 KB Output is correct
10 Correct 651 ms 8784 KB Output is correct
11 Correct 556 ms 8784 KB Output is correct
12 Correct 695 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8016 KB Output is correct
2 Correct 4 ms 8144 KB Output is correct
3 Correct 5 ms 8144 KB Output is correct
4 Correct 6 ms 8144 KB Output is correct
5 Correct 5 ms 8156 KB Output is correct
6 Correct 5 ms 8144 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 5 ms 8144 KB Output is correct
9 Correct 5 ms 8144 KB Output is correct
10 Correct 5 ms 8488 KB Output is correct
11 Correct 5 ms 8400 KB Output is correct
12 Correct 5 ms 8128 KB Output is correct
13 Correct 559 ms 13108 KB Output is correct
14 Correct 759 ms 18116 KB Output is correct
15 Correct 623 ms 18112 KB Output is correct
16 Correct 692 ms 18108 KB Output is correct
17 Correct 553 ms 13112 KB Output is correct
18 Correct 803 ms 18232 KB Output is correct
19 Correct 883 ms 18108 KB Output is correct
20 Correct 488 ms 15756 KB Output is correct
21 Correct 433 ms 8516 KB Output is correct
22 Correct 651 ms 8784 KB Output is correct
23 Correct 556 ms 8784 KB Output is correct
24 Correct 695 ms 8528 KB Output is correct
25 Correct 987 ms 23092 KB Output is correct
26 Correct 700 ms 23368 KB Output is correct
27 Correct 802 ms 23356 KB Output is correct
28 Correct 634 ms 19780 KB Output is correct
29 Correct 671 ms 49968 KB Output is correct
30 Correct 962 ms 46344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8016 KB Output is correct
2 Correct 5 ms 8004 KB Output is correct
3 Correct 5 ms 8144 KB Output is correct
4 Correct 4 ms 8144 KB Output is correct
5 Correct 4 ms 8144 KB Output is correct
6 Correct 6 ms 8144 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 4 ms 8212 KB Output is correct
9 Correct 5 ms 8016 KB Output is correct
10 Correct 4 ms 8144 KB Output is correct
11 Correct 5 ms 8144 KB Output is correct
12 Correct 6 ms 8144 KB Output is correct
13 Correct 5 ms 8156 KB Output is correct
14 Correct 5 ms 8144 KB Output is correct
15 Correct 5 ms 8144 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 5 ms 8144 KB Output is correct
18 Correct 5 ms 8488 KB Output is correct
19 Correct 5 ms 8400 KB Output is correct
20 Correct 5 ms 8128 KB Output is correct
21 Correct 4 ms 8144 KB Output is correct
22 Correct 5 ms 8144 KB Output is correct
23 Correct 4 ms 8144 KB Output is correct
24 Correct 5 ms 8240 KB Output is correct
25 Correct 6 ms 8144 KB Output is correct
26 Correct 5 ms 8144 KB Output is correct
27 Correct 5 ms 8240 KB Output is correct
28 Correct 5 ms 8144 KB Output is correct
29 Correct 4 ms 8144 KB Output is correct
30 Correct 4 ms 8144 KB Output is correct
31 Correct 5 ms 8272 KB Output is correct
32 Correct 5 ms 8144 KB Output is correct
33 Correct 5 ms 8144 KB Output is correct
34 Correct 4 ms 8192 KB Output is correct
35 Correct 4 ms 8188 KB Output is correct
36 Correct 5 ms 8400 KB Output is correct
37 Correct 5 ms 8444 KB Output is correct
38 Correct 5 ms 8400 KB Output is correct
39 Correct 5 ms 8144 KB Output is correct
40 Correct 6 ms 8144 KB Output is correct
41 Correct 5 ms 8192 KB Output is correct
42 Correct 5 ms 8096 KB Output is correct
43 Correct 498 ms 8528 KB Output is correct
44 Correct 492 ms 8604 KB Output is correct
45 Correct 726 ms 8524 KB Output is correct
46 Correct 738 ms 8892 KB Output is correct
47 Correct 713 ms 8912 KB Output is correct
48 Correct 789 ms 8912 KB Output is correct
49 Correct 570 ms 8912 KB Output is correct
50 Correct 594 ms 8700 KB Output is correct
51 Correct 1020 ms 8624 KB Output is correct
52 Correct 873 ms 8856 KB Output is correct
53 Correct 413 ms 9552 KB Output is correct
54 Correct 869 ms 8900 KB Output is correct
55 Correct 740 ms 8832 KB Output is correct
56 Correct 707 ms 8784 KB Output is correct
57 Correct 744 ms 8624 KB Output is correct
58 Correct 740 ms 10192 KB Output is correct
59 Correct 648 ms 10152 KB Output is correct
60 Correct 568 ms 10024 KB Output is correct
61 Correct 734 ms 8836 KB Output is correct
62 Correct 764 ms 8640 KB Output is correct
63 Correct 808 ms 8568 KB Output is correct
64 Correct 851 ms 8720 KB Output is correct
65 Correct 404 ms 8400 KB Output is correct
66 Correct 770 ms 8784 KB Output is correct
67 Correct 690 ms 8780 KB Output is correct
68 Correct 758 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8016 KB Output is correct
2 Correct 5 ms 8004 KB Output is correct
3 Correct 5 ms 8144 KB Output is correct
4 Correct 4 ms 8144 KB Output is correct
5 Correct 4 ms 8144 KB Output is correct
6 Correct 6 ms 8144 KB Output is correct
7 Correct 5 ms 8144 KB Output is correct
8 Correct 4 ms 8212 KB Output is correct
9 Correct 5 ms 8016 KB Output is correct
10 Correct 4 ms 8144 KB Output is correct
11 Correct 5 ms 8144 KB Output is correct
12 Correct 6 ms 8144 KB Output is correct
13 Correct 5 ms 8156 KB Output is correct
14 Correct 5 ms 8144 KB Output is correct
15 Correct 5 ms 8144 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 5 ms 8144 KB Output is correct
18 Correct 5 ms 8488 KB Output is correct
19 Correct 5 ms 8400 KB Output is correct
20 Correct 5 ms 8128 KB Output is correct
21 Correct 4 ms 8144 KB Output is correct
22 Correct 5 ms 8144 KB Output is correct
23 Correct 4 ms 8144 KB Output is correct
24 Correct 5 ms 8240 KB Output is correct
25 Correct 6 ms 8144 KB Output is correct
26 Correct 5 ms 8144 KB Output is correct
27 Correct 5 ms 8240 KB Output is correct
28 Correct 5 ms 8144 KB Output is correct
29 Correct 4 ms 8144 KB Output is correct
30 Correct 4 ms 8144 KB Output is correct
31 Correct 5 ms 8272 KB Output is correct
32 Correct 5 ms 8144 KB Output is correct
33 Correct 5 ms 8144 KB Output is correct
34 Correct 4 ms 8192 KB Output is correct
35 Correct 4 ms 8188 KB Output is correct
36 Correct 5 ms 8400 KB Output is correct
37 Correct 5 ms 8444 KB Output is correct
38 Correct 5 ms 8400 KB Output is correct
39 Correct 5 ms 8144 KB Output is correct
40 Correct 6 ms 8144 KB Output is correct
41 Correct 5 ms 8192 KB Output is correct
42 Correct 5 ms 8096 KB Output is correct
43 Correct 559 ms 13108 KB Output is correct
44 Correct 759 ms 18116 KB Output is correct
45 Correct 623 ms 18112 KB Output is correct
46 Correct 692 ms 18108 KB Output is correct
47 Correct 553 ms 13112 KB Output is correct
48 Correct 803 ms 18232 KB Output is correct
49 Correct 883 ms 18108 KB Output is correct
50 Correct 488 ms 15756 KB Output is correct
51 Correct 433 ms 8516 KB Output is correct
52 Correct 651 ms 8784 KB Output is correct
53 Correct 556 ms 8784 KB Output is correct
54 Correct 695 ms 8528 KB Output is correct
55 Correct 987 ms 23092 KB Output is correct
56 Correct 700 ms 23368 KB Output is correct
57 Correct 802 ms 23356 KB Output is correct
58 Correct 634 ms 19780 KB Output is correct
59 Correct 671 ms 49968 KB Output is correct
60 Correct 962 ms 46344 KB Output is correct
61 Correct 498 ms 8528 KB Output is correct
62 Correct 492 ms 8604 KB Output is correct
63 Correct 726 ms 8524 KB Output is correct
64 Correct 738 ms 8892 KB Output is correct
65 Correct 713 ms 8912 KB Output is correct
66 Correct 789 ms 8912 KB Output is correct
67 Correct 570 ms 8912 KB Output is correct
68 Correct 594 ms 8700 KB Output is correct
69 Correct 1020 ms 8624 KB Output is correct
70 Correct 873 ms 8856 KB Output is correct
71 Correct 413 ms 9552 KB Output is correct
72 Correct 869 ms 8900 KB Output is correct
73 Correct 740 ms 8832 KB Output is correct
74 Correct 707 ms 8784 KB Output is correct
75 Correct 744 ms 8624 KB Output is correct
76 Correct 740 ms 10192 KB Output is correct
77 Correct 648 ms 10152 KB Output is correct
78 Correct 568 ms 10024 KB Output is correct
79 Correct 734 ms 8836 KB Output is correct
80 Correct 764 ms 8640 KB Output is correct
81 Correct 808 ms 8568 KB Output is correct
82 Correct 851 ms 8720 KB Output is correct
83 Correct 404 ms 8400 KB Output is correct
84 Correct 770 ms 8784 KB Output is correct
85 Correct 690 ms 8780 KB Output is correct
86 Correct 758 ms 8576 KB Output is correct
87 Correct 4 ms 8016 KB Output is correct
88 Correct 492 ms 21728 KB Output is correct
89 Correct 836 ms 17108 KB Output is correct
90 Correct 888 ms 17672 KB Output is correct
91 Correct 716 ms 23976 KB Output is correct
92 Correct 695 ms 23976 KB Output is correct
93 Correct 619 ms 24064 KB Output is correct
94 Correct 802 ms 23980 KB Output is correct
95 Correct 727 ms 20392 KB Output is correct
96 Correct 743 ms 15228 KB Output is correct
97 Correct 688 ms 19248 KB Output is correct
98 Correct 793 ms 37012 KB Output is correct
99 Correct 858 ms 23452 KB Output is correct
100 Correct 848 ms 21924 KB Output is correct
101 Correct 825 ms 20884 KB Output is correct
102 Correct 943 ms 19400 KB Output is correct
103 Correct 737 ms 50036 KB Output is correct
104 Correct 760 ms 47740 KB Output is correct
105 Correct 872 ms 44140 KB Output is correct
106 Correct 740 ms 21944 KB Output is correct
107 Correct 777 ms 17276 KB Output is correct
108 Correct 876 ms 18316 KB Output is correct
109 Correct 896 ms 19472 KB Output is correct