Submission #1058780

# Submission time Handle Problem Language Result Execution time Memory
1058780 2024-08-14T13:44:19 Z mychecksedad Digital Circuit (IOI22_circuit) C++17
0 / 100
314 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];
    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][0], T[k][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;
    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]);
}
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());
  pref[v][0] = X[g[v][0]];
  suf[v].back() = X[g[v].back()];
  for(int u: g[v]){
    dfs(u);
  }
  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) 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);
}

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:36:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |   int m = l+r>>1;
      |           ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:60:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |   int m = l+r>>1;
      |           ~^~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   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:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for(int i = 0; i < g[v].size(); ++i){
      |                  ~~^~~~~~~~~~~~~
circuit.cpp:89:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     if(i + 1 < g[v].size()) y = suf[v][i + 1];
      |        ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 44884 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 44888 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 44884 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 48984 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 48984 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 44888 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 44884 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 44884 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -