Submission #821816

# Submission time Handle Problem Language Result Execution time Memory
821816 2023-08-11T17:55:34 Z I_Love_EliskaM_ Digital Circuit (IOI22_circuit) C++17
46 / 100
936 ms 14684 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=1e5+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( (1ll*pr.back()*z[v])%mod );
  reverse(all(adj[u]));
  for(auto&v:adj[u]) sf.pb( (1ll*sf.back()*z[v])%mod );
  reverse(all(sf));
  reverse(all(adj[u]));

  f[u]=o;

  forn(i,adj[u].size()) {
    int x = (1ll*o*pr[i])%mod;
    x = (1ll*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 5 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 3 ms 5852 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5688 KB Output is correct
2 Correct 4 ms 5712 KB Output is correct
3 Correct 4 ms 5712 KB Output is correct
4 Correct 5 ms 5712 KB Output is correct
5 Correct 3 ms 5712 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 4 ms 5840 KB Output is correct
8 Correct 4 ms 5876 KB Output is correct
9 Correct 4 ms 5888 KB Output is correct
10 Correct 4 ms 6116 KB Output is correct
11 Correct 5 ms 6028 KB Output is correct
12 Correct 4 ms 5864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 3 ms 5852 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5840 KB Output is correct
9 Correct 3 ms 5688 KB Output is correct
10 Correct 4 ms 5712 KB Output is correct
11 Correct 4 ms 5712 KB Output is correct
12 Correct 5 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 4 ms 5840 KB Output is correct
15 Correct 4 ms 5840 KB Output is correct
16 Correct 4 ms 5876 KB Output is correct
17 Correct 4 ms 5888 KB Output is correct
18 Correct 4 ms 6116 KB Output is correct
19 Correct 5 ms 6028 KB Output is correct
20 Correct 4 ms 5864 KB Output is correct
21 Correct 4 ms 5864 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 4 ms 5840 KB Output is correct
24 Correct 4 ms 5840 KB Output is correct
25 Correct 4 ms 5880 KB Output is correct
26 Correct 4 ms 5840 KB Output is correct
27 Correct 4 ms 5772 KB Output is correct
28 Correct 4 ms 5892 KB Output is correct
29 Correct 3 ms 5840 KB Output is correct
30 Correct 5 ms 5828 KB Output is correct
31 Correct 4 ms 5968 KB Output is correct
32 Correct 6 ms 5840 KB Output is correct
33 Correct 4 ms 5872 KB Output is correct
34 Correct 4 ms 5840 KB Output is correct
35 Correct 4 ms 5764 KB Output is correct
36 Correct 4 ms 6096 KB Output is correct
37 Correct 4 ms 6096 KB Output is correct
38 Correct 4 ms 6096 KB Output is correct
39 Correct 4 ms 5804 KB Output is correct
40 Correct 4 ms 5840 KB Output is correct
41 Correct 4 ms 5840 KB Output is correct
42 Correct 4 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 421 ms 10768 KB Output is correct
2 Runtime error 27 ms 14684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 421 ms 10768 KB Output is correct
2 Runtime error 27 ms 14684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5688 KB Output is correct
2 Correct 4 ms 5712 KB Output is correct
3 Correct 4 ms 5712 KB Output is correct
4 Correct 5 ms 5712 KB Output is correct
5 Correct 3 ms 5712 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 4 ms 5840 KB Output is correct
8 Correct 4 ms 5876 KB Output is correct
9 Correct 4 ms 5888 KB Output is correct
10 Correct 4 ms 6116 KB Output is correct
11 Correct 5 ms 6028 KB Output is correct
12 Correct 4 ms 5864 KB Output is correct
13 Correct 421 ms 10768 KB Output is correct
14 Runtime error 27 ms 14684 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 3 ms 5852 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5840 KB Output is correct
9 Correct 3 ms 5688 KB Output is correct
10 Correct 4 ms 5712 KB Output is correct
11 Correct 4 ms 5712 KB Output is correct
12 Correct 5 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 4 ms 5840 KB Output is correct
15 Correct 4 ms 5840 KB Output is correct
16 Correct 4 ms 5876 KB Output is correct
17 Correct 4 ms 5888 KB Output is correct
18 Correct 4 ms 6116 KB Output is correct
19 Correct 5 ms 6028 KB Output is correct
20 Correct 4 ms 5864 KB Output is correct
21 Correct 4 ms 5864 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 4 ms 5840 KB Output is correct
24 Correct 4 ms 5840 KB Output is correct
25 Correct 4 ms 5880 KB Output is correct
26 Correct 4 ms 5840 KB Output is correct
27 Correct 4 ms 5772 KB Output is correct
28 Correct 4 ms 5892 KB Output is correct
29 Correct 3 ms 5840 KB Output is correct
30 Correct 5 ms 5828 KB Output is correct
31 Correct 4 ms 5968 KB Output is correct
32 Correct 6 ms 5840 KB Output is correct
33 Correct 4 ms 5872 KB Output is correct
34 Correct 4 ms 5840 KB Output is correct
35 Correct 4 ms 5764 KB Output is correct
36 Correct 4 ms 6096 KB Output is correct
37 Correct 4 ms 6096 KB Output is correct
38 Correct 4 ms 6096 KB Output is correct
39 Correct 4 ms 5804 KB Output is correct
40 Correct 4 ms 5840 KB Output is correct
41 Correct 4 ms 5840 KB Output is correct
42 Correct 4 ms 5840 KB Output is correct
43 Correct 460 ms 6240 KB Output is correct
44 Correct 561 ms 6148 KB Output is correct
45 Correct 604 ms 6324 KB Output is correct
46 Correct 430 ms 6608 KB Output is correct
47 Correct 726 ms 6608 KB Output is correct
48 Correct 719 ms 6608 KB Output is correct
49 Correct 620 ms 6608 KB Output is correct
50 Correct 685 ms 6352 KB Output is correct
51 Correct 644 ms 6272 KB Output is correct
52 Correct 631 ms 6500 KB Output is correct
53 Correct 712 ms 7120 KB Output is correct
54 Correct 629 ms 6476 KB Output is correct
55 Correct 626 ms 6480 KB Output is correct
56 Correct 675 ms 6352 KB Output is correct
57 Correct 603 ms 6352 KB Output is correct
58 Correct 854 ms 7888 KB Output is correct
59 Correct 733 ms 7848 KB Output is correct
60 Correct 890 ms 7660 KB Output is correct
61 Correct 685 ms 6480 KB Output is correct
62 Correct 936 ms 6240 KB Output is correct
63 Correct 608 ms 6240 KB Output is correct
64 Correct 766 ms 6360 KB Output is correct
65 Correct 400 ms 6004 KB Output is correct
66 Correct 699 ms 6352 KB Output is correct
67 Correct 746 ms 6352 KB Output is correct
68 Correct 553 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 3 ms 5852 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5840 KB Output is correct
9 Correct 3 ms 5688 KB Output is correct
10 Correct 4 ms 5712 KB Output is correct
11 Correct 4 ms 5712 KB Output is correct
12 Correct 5 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 4 ms 5840 KB Output is correct
15 Correct 4 ms 5840 KB Output is correct
16 Correct 4 ms 5876 KB Output is correct
17 Correct 4 ms 5888 KB Output is correct
18 Correct 4 ms 6116 KB Output is correct
19 Correct 5 ms 6028 KB Output is correct
20 Correct 4 ms 5864 KB Output is correct
21 Correct 4 ms 5864 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 4 ms 5840 KB Output is correct
24 Correct 4 ms 5840 KB Output is correct
25 Correct 4 ms 5880 KB Output is correct
26 Correct 4 ms 5840 KB Output is correct
27 Correct 4 ms 5772 KB Output is correct
28 Correct 4 ms 5892 KB Output is correct
29 Correct 3 ms 5840 KB Output is correct
30 Correct 5 ms 5828 KB Output is correct
31 Correct 4 ms 5968 KB Output is correct
32 Correct 6 ms 5840 KB Output is correct
33 Correct 4 ms 5872 KB Output is correct
34 Correct 4 ms 5840 KB Output is correct
35 Correct 4 ms 5764 KB Output is correct
36 Correct 4 ms 6096 KB Output is correct
37 Correct 4 ms 6096 KB Output is correct
38 Correct 4 ms 6096 KB Output is correct
39 Correct 4 ms 5804 KB Output is correct
40 Correct 4 ms 5840 KB Output is correct
41 Correct 4 ms 5840 KB Output is correct
42 Correct 4 ms 5840 KB Output is correct
43 Correct 421 ms 10768 KB Output is correct
44 Runtime error 27 ms 14684 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -