Submission #836370

# Submission time Handle Problem Language Result Execution time Memory
836370 2023-08-24T10:39:06 Z Trumling Digital Circuit (IOI22_circuit) C++17
0 / 100
475 ms 6204 KB
    #include "circuit.h"
    #include<bits/stdc++.h>
    using namespace std;
     
    #define F first
    #define S second
    #define all(x) x.begin(),x.end()
    typedef long long ll;
    #define pb push_back
    #define MOD 1000002022
     
    ll m,n;
    vector<vector<int>>g;
    vector<pair<ll,ll>> tree;
    vector<int>a;
    vector<int>dic;
    ll idx=0;
    void update(int l,int r,int p,int start)
    {
      if(l==r)
      {
        tree[start]={0,0};
        if(a[start])
        tree[start].F=1;
        else
        tree[start].S=1;
        return;
      }

      if(l<=p && p<=(l+r)/2)
      update(l,(l+r)/2,p,start*2+1);
      else
      update((l+r)/2+1,r,p,start*2+2);

      tree[start].F=((tree[l].F*tree[r].F)%MOD  + (tree[l].F*(tree[r].F+tree[r].S))%MOD + (tree[l].S*tree[r].F)%MOD)%MOD;
      tree[start].S=((tree[l].S*(tree[r].F+tree[r].S))%MOD + (tree[l].F*tree[r].S)%MOD + (tree[l].S*tree[r].S)%MOD)%MOD;
    }
    void build(int start)
    {
      if(g[start].size()==1)
      {
        dic[start]=idx++;
        tree[start]={0,0};
        if(a[start])
        tree[start].F=1;
        else
        tree[start].S=1;
        //cout<<start<<" |"<<tree[start].F<<' '<<tree[start].S<<'\n';
        return ;
      }
      ll l,r;
      for(auto x:g[start])
      if(x>start)
      build(x);

      ll add=0;
      if(start==0)
      add=-1;
      l=g[start][1+add];
      r=g[start][2+add];

      tree[start].F=((tree[l].F*tree[r].F)%MOD  + (tree[l].F*(tree[r].F+tree[r].S))%MOD + (tree[l].S*tree[r].F)%MOD)%MOD;
      tree[start].S=((tree[l].S*(tree[r].F+tree[r].S))%MOD + (tree[l].F*tree[r].S)%MOD + (tree[l].S*tree[r].S)%MOD)%MOD;

     // cout<<start<<" |"<<tree[start].F<<' '<<tree[start].S<<'\n';
      return ;
    }

    void init(int N, int M, vector<int> P, vector<int> A) 
    {
      n=N;
      m=M;
      tree.assign(n+m,{0,0});
      g.assign(N+M,vector<int>());
      a.assign(N+M,0);
      dic.assign(N+M,0);

      for(int i=0;i<m;i++)
      a[i+n]=A[i];

      for(int i=1;i<N+M;i++)
      {
        g[i].pb(P[i]);
        g[P[i]].pb(i);
      }
      build(0);
    }
     
    int count_ways(int L, int R) 
    {
      for(int i=L;i<=R;i++)
        a[i]=1-a[i];
      
      update(0,n,L-n,0);
      //cout<<tree[0].F<<' '<<tree[0].S;
      return tree[0].F;
    }
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 475 ms 6204 KB 1st lines differ - on the 1st token, expected: '431985922', found: '394586018'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 475 ms 6204 KB 1st lines differ - on the 1st token, expected: '431985922', found: '394586018'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -