Submission #855918

# Submission time Handle Problem Language Result Execution time Memory
855918 2023-10-02T09:17:47 Z onepunchac168 Digital Circuit (IOI22_circuit) C++17
100 / 100
688 ms 49168 KB
//------------------------------------\\
//   ------------------------------   \\
//  |  created by Dinh Manh Hung   |  \\
//  |      tht.onepunchac168       |  \\
//  |     THPT CHUYEN HA TINH      |  \\
//  |      HA TINH, VIET NAM       |  \\
//  |           Siuuu              |  \\
//   ------------------------------   \\
//------------------------------------\\

#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;

#define            task     ""
#define       file(name)    if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define             ldb     long double
#define              pb     push_back
#define              eb     emplace_back
#define              fi     first
#define              se     second
#define           all(x)    begin(x),end(x)
#define       uniquev(v)    v.resize(unique(all(v))-v.begin())
#define       rep(i,a,b)    for (int i=a;i<=b;i++)
#define        cntbit(v)    __builtin_popcountll(v)
#define         gcd(a,b)    __gcd(a,b)
#define         lcm(a,b)    ((1LL*a*b)/__gcd(a,b))
#define          mask(x)    (1LL<<(x))
#define     readbit(x,i)    ((x>>i)&1)
#define             Yes     cout << "Yes"
#define             YES     cout << "YES"
#define              No     cout << "No"
#define              NO     cout << "NO"

typedef long long ll;
typedef pair <ll,ll> ii;
typedef pair <ll,ii> iii;
typedef pair <ii,ii> iiii;

ll dx[]= {1,-1,0,0,1,-1,1,-1};
ll dy[]= {0,0,-1,1,1,-1,-1,1};

const ldb PI = acos (-1);
//const ll mod=978846151;
//const ll base=29;
const ll mod=1000002022;
const char nl = '\n';

inline int ReadInt()
{
    char co;
    for (co = getchar(); co < '0' || co > '9'; co = getchar());
    int xo = co - '0';
    for (co = getchar(); co >= '0' && co <= '9'; co = getchar())
        xo = (xo<<1) + (xo<<3) + co - '0';
    return xo;
}

void WriteInt(int xo)
{
    if (xo > 9)
        WriteInt(xo / 10);
    putchar(xo % 10 + '0');
}

// DEBUG
/*
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
*/

/* END OF TEMPLATE*/

// ================= Solution =================//

/*
void onepunchac168();

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    file(task);
    int tests;
    tests=1;
    //cin>>tests;
    while (tests--)
    {
        onepunchac168();
    }
}

void onepunchac168()
{

}
*/
const int Na=1e5+5;
int n,m,q;
int p[Na*2];
int a[Na];
vector <int> vt[Na*2];
ll dp[2*Na];
void dfs(int u)
{
    dp[u]=1;
    if (vt[u].empty())
    {
        return;
    }
    for (auto v:vt[u])
    {
        dfs(v);
        dp[u]=(dp[u]*dp[v])%mod;
    }
    dp[u]=(dp[u]*ll((vt[u]).size()))%mod;
}
ll dpa[Na];
ll T[Na*8];
ll sum[Na*8];
ll lazy[Na*8];
void dfsa(int u,ll val)
{
    if (u>n)
    {
        dpa[u-n]=val;
        return;
    }
    vector <ll> pref(int(vt[u].size())+2),suff(int(vt[u].size())+2);
    pref[0]=1;
    suff[int(vt[u].size())+1]=1;
    for (int i=1;i<=int(vt[u].size());i++)
    {
        pref[i]=(pref[i-1]*dp[vt[u][i-1]])%mod;
    }
    for (int i=int(vt[u].size());i>=1;i--)
    {
        suff[i]=(suff[i+1]*dp[vt[u][i-1]])%mod;
    }
    for (int i=1;i<=int(vt[u].size());i++)
    {
        ll cost=val;
        cost=(cost*pref[i-1])%mod;
        cost=(cost*suff[i+1])%mod;
        dfsa(vt[u][i-1],cost);
    }
}
bool check[Na];
void build(int node,int l,int r)
{
    lazy[node]=0;
    if (l==r)
    {
        sum[node]=dpa[l];
        if (check[l]==1)
        {
            T[node]=dpa[l];
        }
        return;
    }
    build(node*2,l,(l+r)/2);
    build(node*2+1,(l+r)/2+1,r);
    T[node]=T[node*2]+T[node*2+1];
    sum[node]=sum[node*2]+sum[node*2+1];
}
void updatelazy(int node)
{
    if (lazy[node]==1)
    {
        lazy[node*2]^=1;
        lazy[node*2+1]^=1;
        lazy[node]=0;
        T[node]=sum[node]-T[node];
    }
}
void update(int node,int l,int r,int u,int v)
{
    updatelazy(node);
    if (l>v||r<u)
    {
        return;
    }
    if (l>=u&&r<=v)
    {
        lazy[node]^=1;
        updatelazy(node);
        return;
    }
    update(node*2,l,(l+r)/2,u,v);
    update(node*2+1,(l+r)/2+1,r,u,v);
    T[node]=T[node*2]+T[node*2+1];
}
void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
    n=N;
    m=M;
    for (int i=0;i<P.size();i++)
    {
        p[i+1]=P[i]+1;
    }
    for (int i=0;i<A.size();i++)
    {
        a[i+1]=A[i];
    }
    for (int i=1;i<=m;i++)
    {
        check[i]=a[i];
    }
    for (int i=1;i<=n+m;i++)
    {
        if (p[i]==0)
        {
            continue;
        }
        vt[p[i]].pb(i);
    }
    dfs(1);
    dfsa(1,1);
    build(1,1,m);
}

int count_ways(int L, int R)
{
    L++;
    R++;
    L-=n;
    R-=n;
    update(1,1,m,L,R);
    return T[1]%mod;
}

// goodbye see ya

Compilation message

circuit.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //------------------------------------\\
      | ^
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:223:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  223 |     for (int i=0;i<P.size();i++)
      |                  ~^~~~~~~~~
circuit.cpp:227:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  227 |     for (int i=0;i<A.size();i++)
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10836 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 3 ms 12888 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10836 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12632 KB Output is correct
26 Correct 2 ms 10840 KB Output is correct
27 Correct 2 ms 12632 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10780 KB Output is correct
36 Correct 2 ms 10952 KB Output is correct
37 Correct 2 ms 10840 KB Output is correct
38 Correct 2 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 2 ms 12888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 15184 KB Output is correct
2 Correct 594 ms 18512 KB Output is correct
3 Correct 604 ms 18512 KB Output is correct
4 Correct 582 ms 17088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 15184 KB Output is correct
2 Correct 594 ms 18512 KB Output is correct
3 Correct 604 ms 18512 KB Output is correct
4 Correct 582 ms 17088 KB Output is correct
5 Correct 498 ms 16720 KB Output is correct
6 Correct 628 ms 18468 KB Output is correct
7 Correct 634 ms 18372 KB Output is correct
8 Correct 601 ms 17436 KB Output is correct
9 Correct 288 ms 12888 KB Output is correct
10 Correct 624 ms 13144 KB Output is correct
11 Correct 598 ms 15188 KB Output is correct
12 Correct 567 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 10584 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 3 ms 12888 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 402 ms 15184 KB Output is correct
14 Correct 594 ms 18512 KB Output is correct
15 Correct 604 ms 18512 KB Output is correct
16 Correct 582 ms 17088 KB Output is correct
17 Correct 498 ms 16720 KB Output is correct
18 Correct 628 ms 18468 KB Output is correct
19 Correct 634 ms 18372 KB Output is correct
20 Correct 601 ms 17436 KB Output is correct
21 Correct 288 ms 12888 KB Output is correct
22 Correct 624 ms 13144 KB Output is correct
23 Correct 598 ms 15188 KB Output is correct
24 Correct 567 ms 14936 KB Output is correct
25 Correct 625 ms 25468 KB Output is correct
26 Correct 679 ms 25692 KB Output is correct
27 Correct 688 ms 25700 KB Output is correct
28 Correct 511 ms 25696 KB Output is correct
29 Correct 669 ms 49028 KB Output is correct
30 Correct 640 ms 49156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10836 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12632 KB Output is correct
26 Correct 2 ms 10840 KB Output is correct
27 Correct 2 ms 12632 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10780 KB Output is correct
36 Correct 2 ms 10952 KB Output is correct
37 Correct 2 ms 10840 KB Output is correct
38 Correct 2 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 2 ms 12888 KB Output is correct
43 Correct 424 ms 13144 KB Output is correct
44 Correct 563 ms 14936 KB Output is correct
45 Correct 555 ms 14936 KB Output is correct
46 Correct 570 ms 14936 KB Output is correct
47 Correct 545 ms 14936 KB Output is correct
48 Correct 547 ms 13400 KB Output is correct
49 Correct 557 ms 14936 KB Output is correct
50 Correct 506 ms 15136 KB Output is correct
51 Correct 534 ms 13156 KB Output is correct
52 Correct 500 ms 15072 KB Output is correct
53 Correct 472 ms 11864 KB Output is correct
54 Correct 547 ms 13144 KB Output is correct
55 Correct 513 ms 13144 KB Output is correct
56 Correct 534 ms 14932 KB Output is correct
57 Correct 543 ms 14936 KB Output is correct
58 Correct 513 ms 16216 KB Output is correct
59 Correct 514 ms 16216 KB Output is correct
60 Correct 525 ms 16216 KB Output is correct
61 Correct 544 ms 15192 KB Output is correct
62 Correct 564 ms 14936 KB Output is correct
63 Correct 522 ms 14936 KB Output is correct
64 Correct 522 ms 14936 KB Output is correct
65 Correct 251 ms 12888 KB Output is correct
66 Correct 527 ms 12888 KB Output is correct
67 Correct 521 ms 15024 KB Output is correct
68 Correct 511 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10836 KB Output is correct
2 Correct 1 ms 10584 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 ms 12632 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 3 ms 12888 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12632 KB Output is correct
26 Correct 2 ms 10840 KB Output is correct
27 Correct 2 ms 12632 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12632 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 2 ms 12632 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 10780 KB Output is correct
36 Correct 2 ms 10952 KB Output is correct
37 Correct 2 ms 10840 KB Output is correct
38 Correct 2 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12632 KB Output is correct
42 Correct 2 ms 12888 KB Output is correct
43 Correct 402 ms 15184 KB Output is correct
44 Correct 594 ms 18512 KB Output is correct
45 Correct 604 ms 18512 KB Output is correct
46 Correct 582 ms 17088 KB Output is correct
47 Correct 498 ms 16720 KB Output is correct
48 Correct 628 ms 18468 KB Output is correct
49 Correct 634 ms 18372 KB Output is correct
50 Correct 601 ms 17436 KB Output is correct
51 Correct 288 ms 12888 KB Output is correct
52 Correct 624 ms 13144 KB Output is correct
53 Correct 598 ms 15188 KB Output is correct
54 Correct 567 ms 14936 KB Output is correct
55 Correct 625 ms 25468 KB Output is correct
56 Correct 679 ms 25692 KB Output is correct
57 Correct 688 ms 25700 KB Output is correct
58 Correct 511 ms 25696 KB Output is correct
59 Correct 669 ms 49028 KB Output is correct
60 Correct 640 ms 49156 KB Output is correct
61 Correct 424 ms 13144 KB Output is correct
62 Correct 563 ms 14936 KB Output is correct
63 Correct 555 ms 14936 KB Output is correct
64 Correct 570 ms 14936 KB Output is correct
65 Correct 545 ms 14936 KB Output is correct
66 Correct 547 ms 13400 KB Output is correct
67 Correct 557 ms 14936 KB Output is correct
68 Correct 506 ms 15136 KB Output is correct
69 Correct 534 ms 13156 KB Output is correct
70 Correct 500 ms 15072 KB Output is correct
71 Correct 472 ms 11864 KB Output is correct
72 Correct 547 ms 13144 KB Output is correct
73 Correct 513 ms 13144 KB Output is correct
74 Correct 534 ms 14932 KB Output is correct
75 Correct 543 ms 14936 KB Output is correct
76 Correct 513 ms 16216 KB Output is correct
77 Correct 514 ms 16216 KB Output is correct
78 Correct 525 ms 16216 KB Output is correct
79 Correct 544 ms 15192 KB Output is correct
80 Correct 564 ms 14936 KB Output is correct
81 Correct 522 ms 14936 KB Output is correct
82 Correct 522 ms 14936 KB Output is correct
83 Correct 251 ms 12888 KB Output is correct
84 Correct 527 ms 12888 KB Output is correct
85 Correct 521 ms 15024 KB Output is correct
86 Correct 511 ms 14936 KB Output is correct
87 Correct 2 ms 12632 KB Output is correct
88 Correct 360 ms 25292 KB Output is correct
89 Correct 603 ms 18700 KB Output is correct
90 Correct 602 ms 18320 KB Output is correct
91 Correct 577 ms 25808 KB Output is correct
92 Correct 615 ms 25804 KB Output is correct
93 Correct 646 ms 24092 KB Output is correct
94 Correct 609 ms 25808 KB Output is correct
95 Correct 606 ms 25804 KB Output is correct
96 Correct 550 ms 22296 KB Output is correct
97 Correct 595 ms 22432 KB Output is correct
98 Correct 539 ms 34892 KB Output is correct
99 Correct 586 ms 25560 KB Output is correct
100 Correct 650 ms 21824 KB Output is correct
101 Correct 602 ms 21384 KB Output is correct
102 Correct 624 ms 22432 KB Output is correct
103 Correct 638 ms 49168 KB Output is correct
104 Correct 610 ms 46528 KB Output is correct
105 Correct 558 ms 46432 KB Output is correct
106 Correct 568 ms 23364 KB Output is correct
107 Correct 567 ms 23104 KB Output is correct
108 Correct 596 ms 22888 KB Output is correct
109 Correct 581 ms 22600 KB Output is correct