Submission #1058824

# Submission time Handle Problem Language Result Execution time Memory
1058824 2024-08-14T14:11:00 Z mychecksedad Digital Circuit (IOI22_circuit) C++17
2 / 100
371 ms 48984 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define en cout << '\n'
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vi vector<int>
#define ll long long int
#define ff first
#define ss second
const int N = 500000+10;
const ll MOD = 1000002022;

int n, m;
vector<int> g[N];
ll sum[N];
array<ll, 2> T[N];
ll X[N];
vi val;
int lazy[N];
int F;
array<ll, 2> comb(array<ll, 2> x, array<ll, 2> y){
  array<ll, 2> z;
  z[0] = (x[0]+y[0])%MOD;
  z[1] = (x[1]+y[1])%MOD;
  return z;
}
void build(int l, int r, int k){
  lazy[k] = 0;
  if(l == r){
    T[k][0] = sum[l + n] * (1 - val[l]);
    T[k][1] = sum[l + n] * val[l];
    // cout << T[k][1] << ' ' << l << '\n';
    return;
  }
  int m = l+r>>1;
  build(l, m, k<<1);
  build(m+1, r, k<<1|1);
  T[k] = comb(T[k<<1], T[k<<1|1]);
}
int get(){
  return T[1][1];
}
void push(int k){
  if(lazy[k]){
    lazy[k<<1] ^= lazy[k];
    lazy[k<<1|1] ^= lazy[k];
    swap(T[k<<1][0], T[k<<1][1]);
    swap(T[k<<1|1][0], T[k<<1|1][1]);
    lazy[k] = 0;
  }
}
void upd(int l, int r, int ql, int qr, int k){
  if(ql > r || l > qr) return;
  if(ql <= l && r <= qr){
    swap(T[k][0], T[k][1]);
    lazy[k] ^= 1;
    // cout << l << ' ' << r << ' ' << T[k][0] << ' ' << T[k][1] << '\n';
    return;
  }
  push(k);
  int m = l+r>>1;
  upd(l, m, ql, qr, k<<1);
  upd(m+1, r, ql, qr, k<<1|1);
  T[k] = comb(T[k<<1], T[k<<1|1]);
  // cout << l << ' ' << r << ' ' << T[k][0] << ' ' << T[k][1] << '\n';
}
vector<ll> pref[N];
vector<ll> suf[N];
void dfs(int v){
  X[v] = 1;
  if(g[v].size() == 0) return;
  pref[v].resize(g[v].size());
  suf[v].resize(g[v].size());
  for(int u: g[v]){
    dfs(u);
    X[v] *= X[u];
    X[v] %= MOD;
  }
  X[v] *= g[v].size();
  X[v] %= MOD;
  pref[v][0] = X[g[v][0]];
  suf[v].back() = X[g[v].back()];
  for(int i = 1; i < pref[v].size(); ++i) pref[v][i] = (pref[v][i - 1] * X[g[v][i]]) % MOD;
  for(int i = int(suf[v].size()) - 2; i >= 0; --i) suf[v][i] = (suf[v][i + 1] * X[g[v][i]]) % MOD;
}
void dfs2(int v, ll num){
  if(g[v].size() == 0){
    sum[v] = num;
    return;
  }
  for(int i = 0; i < g[v].size(); ++i){
    ll x = 1;
    if(i > 0) x = pref[v][i - 1];
    ll y = 1;
    if(i + 1 < g[v].size()) y = suf[v][i + 1];
    x = x * y % MOD;
    dfs2(g[v][i], x);
  }
}
void init(int nn, int mm, std::vector<int> P, std::vector<int> A) { n=nn, m=mm;
  for(int i = 1; i < n + m; ++i) g[P[i]].pb(i);
  dfs(0);
  dfs2(0, 1);
  val = A;
  build(0, m - 1, 1);
  // for(int i = 0; i < n + m; ++i) cout << X[i] << ' ';en;
  // for(int i = 0; i < n + m; ++i) cout << sum[i] << ' ';en;
}

int count_ways(int L, int R) {
  L -= n, R -= n;
  upd(0, m - 1, L, R, 1);
  ll num = get();
  return num;
}

Compilation message

circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:37:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   int m = l+r>>1;
      |           ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:63:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |   int m = l+r>>1;
      |           ~^~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for(int i = 1; i < pref[v].size(); ++i) pref[v][i] = (pref[v][i - 1] * X[g[v][i]]) % MOD;
      |                  ~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, long long int)':
circuit.cpp:93:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for(int i = 0; i < g[v].size(); ++i){
      |                  ~~^~~~~~~~~~~~~
circuit.cpp:97:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     if(i + 1 < g[v].size()) y = suf[v][i + 1];
      |        ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44888 KB Output is correct
3 Correct 5 ms 44888 KB Output is correct
4 Correct 6 ms 44888 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 7 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Incorrect 6 ms 45092 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44888 KB Output is correct
3 Correct 5 ms 44888 KB Output is correct
4 Correct 6 ms 44888 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 7 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
9 Correct 6 ms 44888 KB Output is correct
10 Incorrect 6 ms 45092 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 371 ms 48984 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16402'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 371 ms 48984 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16402'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Incorrect 6 ms 45092 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44888 KB Output is correct
3 Correct 5 ms 44888 KB Output is correct
4 Correct 6 ms 44888 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 7 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
9 Correct 6 ms 44888 KB Output is correct
10 Incorrect 6 ms 45092 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44888 KB Output is correct
3 Correct 5 ms 44888 KB Output is correct
4 Correct 6 ms 44888 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 7 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
9 Correct 6 ms 44888 KB Output is correct
10 Incorrect 6 ms 45092 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -