답안 #697353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697353 2023-02-09T12:23:57 Z FEDIKUS 디지털 회로 (IOI22_circuit) C++17
4 / 100
914 ms 11124 KB
#include "circuit.h"

#include<bits/stdc++.h>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn=2e5+10;
const int mod=1e9+2022;

int n,m;

vector<int> g[maxn];
vector<int> p,a;

int add(int a,int b){
  return (a+b)%mod;
}

int mul(int a,int b){
  return ll(a)*ll(b)%mod;
}

int bruk[maxn];
int power[maxn];

void dfs(int node){
  bruk[node]=1;
  if(node<n) bruk[node]=mul(bruk[node],g[node].size());
  for(int i:g[node]){
    dfs(i);
    bruk[node]=mul(bruk[node],bruk[i]);
  }
}

void dfs2(int node,int tren){
  if(node>=n){
    power[node-n]=tren;
    return;
  }
  vector<int> pref(g[node].size());
  vector<int> suf(g[node].size());
  for(int i=0;i<(int)g[node].size();i++){
    if(i==0) pref[i]=bruk[g[node][i]];
    else pref[i]=mul(pref[i-1],bruk[g[node][i]]);
  }
  for(int i=(int)g[node].size()-1;i>=0;i--){
    if(i==(int)g[node].size()-1) suf[i]=bruk[g[node][i]];
    else suf[i]=mul(suf[i+1],bruk[g[node][i]]);
  }
  for(int i=0;i<(int)g[node].size();i++){
    int ntren=tren;
    if(i>0) ntren=mul(ntren,pref[i-1]);
    if(i<(int)g[node].size()-1) ntren=mul(ntren,suf[i+1]);
    dfs2(g[node][i],ntren);
  }
}

pair<int,int> segt[4*maxn];
int lazy[4*maxn];

void update(int t,int v1,int v0,int ind=1,int l=0,int r=m-1){
  if(l==r){
    segt[ind].first=v1;
    segt[ind].second=v0;
    return;
  }
  int mid=(l+r)/2;
  if(t<=mid) update(t,v1,v0,2*ind,l,mid);
  else update(t,v1,v0,2*ind+1,mid+1,r);
  segt[ind].first=add(segt[2*ind].first,segt[2*ind+1].first);
  segt[ind].second=add(segt[2*ind].second,segt[2*ind+1].second);
}

void push(int ind){
  if(!lazy[ind]) return;
  swap(segt[2*ind].first,segt[2*ind].second);
  swap(segt[2*ind+1].first,segt[2*ind+1].second);
  lazy[ind]=0;
}

void flip(int tl,int tr,int ind=1,int l=0,int r=m-1){
  if(l!=r) push(ind);
  if(tl<=l && r<=tr){
    swap(segt[ind].first,segt[ind].second);
    lazy[ind]^=1;
    return;
  }
  int mid=(l+r)/2;
  if(tl<=mid) flip(tl,tr,2*ind,l,mid);
  if(tr>mid) flip(tl,tr,2*ind+1,mid+1,r);
  segt[ind].first=add(segt[2*ind].first,segt[2*ind+1].first);
  segt[ind].second=add(segt[2*ind].second,segt[2*ind+1].second);
}

void init(int N,int M, vector<int> P, vector<int> A) {
  n=N; m=M; p=P; a=A;
  for(int i=1;i<n+m;i++) g[p[i]].push_back(i);
  dfs(0);
  dfs2(0,1);
  for(int i=0;i<m;i++){
    int v1=power[i];
    int v0=0;
    if(!a[i]) swap(v1,v0);
    update(i,v1,v0);
  }
}

int count_ways(int L, int R) {
  L-=n;
  R-=n;
  flip(L,R);
  return segt[1].first;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 3 ms 5088 KB 3rd lines differ - on the 1st token, expected: '489', found: '488'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 3 ms 5072 KB 2nd lines differ - on the 1st token, expected: '979089518', found: '148157742'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 3 ms 5088 KB 3rd lines differ - on the 1st token, expected: '489', found: '488'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 8080 KB Output is correct
2 Correct 914 ms 11124 KB Output is correct
3 Correct 793 ms 11100 KB Output is correct
4 Correct 902 ms 11080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 8080 KB Output is correct
2 Correct 914 ms 11124 KB Output is correct
3 Correct 793 ms 11100 KB Output is correct
4 Correct 902 ms 11080 KB Output is correct
5 Incorrect 737 ms 8016 KB 3rd lines differ - on the 1st token, expected: '249436868', found: '887016876'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 3 ms 5072 KB 2nd lines differ - on the 1st token, expected: '979089518', found: '148157742'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 3 ms 5088 KB 3rd lines differ - on the 1st token, expected: '489', found: '488'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 3 ms 5088 KB 3rd lines differ - on the 1st token, expected: '489', found: '488'
4 Halted 0 ms 0 KB -