Submission #817353

# Submission time Handle Problem Language Result Execution time Memory
817353 2023-08-09T11:54:18 Z Boomyday Digital Circuit (IOI22_circuit) C++17
100 / 100
1008 ms 41824 KB
//
// Created by adavy on 8/8/2023.
//
#include <vector>





//
// Created by adavy on 2/11/2023.
//
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using ii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U


// pairs
#define mp make_pair
#define f first
#define s second

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define len(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

const int MOD = 1e9+2022; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!


struct Modular {
    int value;
    static const int MOD_value = MOD;

    Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}

    Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
    Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
    Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}


    friend Modular operator+(Modular a, Modular const b) { return a += b; }
    friend Modular operator-(Modular a, Modular const b) { return a -= b; }
    friend Modular operator-(Modular const a) { return 0 - a; }
    friend Modular operator*(Modular a, Modular const b) { return a *= b; }
    friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
    friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
    friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
#include "circuit.h"

vector<vi> cd;
int n, m;

vector<Modular> V,W; //values, weights


void dfs1(int nd){
    // calculate node weights
    if (nd >= n){
        W[nd] = 1;
        return;
    }
    W[nd]=1;
    trav(nei, cd[nd]){
        dfs1(nei);
        W[nd]*=W[nei];
    }
    W[nd]*=cd[nd].size();
}

void dfs2(int nd, Modular mpl){
    if (nd>=n){
        V[nd] = mpl; return;
    }
    vector<Modular> weights;
    trav(nei, cd[nd]) weights.pb(W[nei]);
    vector<Modular> left = {1}, right = {1};
    F0R(i, weights.size()) left.pb(left.back()*weights[i]);
    R0F(i, weights.size()) right.pb(right.back()*weights[i]);
    F0R(i, cd[nd].size())
        dfs2(cd[nd][i], mpl*left[i]*right[(cd[nd].size()-1)-i]);



}

vector<Modular> prefs = {0};
int ssz = 131072;
vector<Modular> seg(2*ssz,0); vi lz(2*ssz,0);



void pushdown(int rt, int tl, int tr){
    if (lz[rt]){
        seg[rt] = (prefs[tr+1]-prefs[tl])-seg[rt];
        lz[rt] = 0;
        if (tl!=tr){
            lz[2*rt]^=1;
            lz[2*rt+1]^=1;
        }
    }
}


void flip(int l, int r, int rt, int tl, int tr){
    pushdown(rt, tl, tr);
    if (r<tl || l > tr ) return;
    if (l<=tl && tr<=r) {
        lz[rt]^=1;
        pushdown(rt, tl, tr);
        return;
    }

    int tm = (tl+tr)>>1;
    flip(l, r, rt<<1, tl, tm);
    flip(l, r, (rt<<1)+1,tm+1,tr);
    seg[rt] = seg[rt<<1]+seg[(rt<<1)+1];
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    cd.rsz(N);
    V.rsz(N + M);
    W.rsz(N + M);
    n = N;
    m = M;


    F0R(i, n + m) {
        if (i != 0) cd[P[i]].pb(i);
    }

    // calculate node values, node weights

    dfs1(0);
    dfs2(0, 1);

    FOR(i, n, n + m) {
        prefs.pb(prefs.back() + V[i]);
    }
    while(prefs.size()<=ssz){
        prefs.pb(prefs.back());
    }

    //trav(i, prefs) cout << i << " "; cout << endl;



    F0R(i, A.size()){
        if (A[i]) flip(i, i, 1, 0, ssz-1);
    }
   // cout << seg[1].value << endl;



}



int count_ways(int L, int R) {
    L-=n; R-=n;
    flip(L,R,1,0,ssz-1);
    return seg[1].value;

}


/*
#include <cassert>
#include <cstdio>

#include <vector>

int main() {
    int N, M, Q;
    assert(3 == scanf("%d %d %d", &N, &M, &Q));
    std::vector<int> P(N + M), A(M);
    for (int i = 0; i < N + M; ++i) {
        assert(1 == scanf("%d", &P[i]));
    }
    for (int j = 0; j < M; ++j) {
        assert(1 == scanf("%d", &A[j]));
    }
    init(N, M, P, A);

    for (int i = 0; i < Q; ++i) {
        int L, R;
        assert(2 == scanf("%d %d", &L, &R));
        printf("%d\n", count_ways(L, R));
    }
    return 0;
}

*/

Compilation message

circuit.cpp: In function 'void dfs2(int, Modular)':
circuit.cpp:50:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Modular>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
circuit.cpp:51:18: note: in expansion of macro 'FOR'
   51 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
circuit.cpp:124:5: note: in expansion of macro 'F0R'
  124 |     F0R(i, weights.size()) left.pb(left.back()*weights[i]);
      |     ^~~
circuit.cpp:50:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
circuit.cpp:51:18: note: in expansion of macro 'FOR'
   51 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
circuit.cpp:126:5: note: in expansion of macro 'F0R'
  126 |     F0R(i, cd[nd].size())
      |     ^~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:186:23: warning: comparison of integer expressions of different signedness: 'std::vector<Modular>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  186 |     while(prefs.size()<=ssz){
      |           ~~~~~~~~~~~~^~~~~
circuit.cpp:50:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
circuit.cpp:51:18: note: in expansion of macro 'FOR'
   51 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
circuit.cpp:194:5: note: in expansion of macro 'F0R'
  194 |     F0R(i, A.size()){
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3400 KB Output is correct
2 Correct 2 ms 3400 KB Output is correct
3 Correct 2 ms 3528 KB Output is correct
4 Correct 2 ms 3528 KB Output is correct
5 Correct 2 ms 3528 KB Output is correct
6 Correct 2 ms 3528 KB Output is correct
7 Correct 2 ms 3528 KB Output is correct
8 Correct 2 ms 3528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3400 KB Output is correct
2 Correct 2 ms 3528 KB Output is correct
3 Correct 2 ms 3528 KB Output is correct
4 Correct 2 ms 3528 KB Output is correct
5 Correct 2 ms 3528 KB Output is correct
6 Correct 2 ms 3532 KB Output is correct
7 Correct 3 ms 3532 KB Output is correct
8 Correct 2 ms 3532 KB Output is correct
9 Correct 2 ms 3532 KB Output is correct
10 Correct 3 ms 3852 KB Output is correct
11 Correct 3 ms 3852 KB Output is correct
12 Correct 2 ms 3536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3400 KB Output is correct
2 Correct 2 ms 3400 KB Output is correct
3 Correct 2 ms 3528 KB Output is correct
4 Correct 2 ms 3528 KB Output is correct
5 Correct 2 ms 3528 KB Output is correct
6 Correct 2 ms 3528 KB Output is correct
7 Correct 2 ms 3528 KB Output is correct
8 Correct 2 ms 3528 KB Output is correct
9 Correct 2 ms 3400 KB Output is correct
10 Correct 2 ms 3528 KB Output is correct
11 Correct 2 ms 3528 KB Output is correct
12 Correct 2 ms 3528 KB Output is correct
13 Correct 2 ms 3528 KB Output is correct
14 Correct 2 ms 3532 KB Output is correct
15 Correct 3 ms 3532 KB Output is correct
16 Correct 2 ms 3532 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 3 ms 3852 KB Output is correct
19 Correct 3 ms 3852 KB Output is correct
20 Correct 2 ms 3536 KB Output is correct
21 Correct 2 ms 3532 KB Output is correct
22 Correct 2 ms 3532 KB Output is correct
23 Correct 2 ms 3492 KB Output is correct
24 Correct 3 ms 3620 KB Output is correct
25 Correct 3 ms 3532 KB Output is correct
26 Correct 2 ms 3536 KB Output is correct
27 Correct 3 ms 3536 KB Output is correct
28 Correct 3 ms 3536 KB Output is correct
29 Correct 2 ms 3528 KB Output is correct
30 Correct 2 ms 3528 KB Output is correct
31 Correct 2 ms 3852 KB Output is correct
32 Correct 2 ms 3532 KB Output is correct
33 Correct 3 ms 3528 KB Output is correct
34 Correct 3 ms 3528 KB Output is correct
35 Correct 2 ms 3528 KB Output is correct
36 Correct 3 ms 3852 KB Output is correct
37 Correct 2 ms 3784 KB Output is correct
38 Correct 3 ms 3784 KB Output is correct
39 Correct 3 ms 3540 KB Output is correct
40 Correct 3 ms 3528 KB Output is correct
41 Correct 3 ms 3536 KB Output is correct
42 Correct 2 ms 3528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 456 ms 6592 KB Output is correct
2 Correct 788 ms 9652 KB Output is correct
3 Correct 712 ms 9656 KB Output is correct
4 Correct 783 ms 9644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 456 ms 6592 KB Output is correct
2 Correct 788 ms 9652 KB Output is correct
3 Correct 712 ms 9656 KB Output is correct
4 Correct 783 ms 9644 KB Output is correct
5 Correct 553 ms 6612 KB Output is correct
6 Correct 815 ms 9672 KB Output is correct
7 Correct 642 ms 9652 KB Output is correct
8 Correct 641 ms 9688 KB Output is correct
9 Correct 337 ms 3656 KB Output is correct
10 Correct 725 ms 3904 KB Output is correct
11 Correct 753 ms 3792 KB Output is correct
12 Correct 725 ms 3896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3400 KB Output is correct
2 Correct 2 ms 3528 KB Output is correct
3 Correct 2 ms 3528 KB Output is correct
4 Correct 2 ms 3528 KB Output is correct
5 Correct 2 ms 3528 KB Output is correct
6 Correct 2 ms 3532 KB Output is correct
7 Correct 3 ms 3532 KB Output is correct
8 Correct 2 ms 3532 KB Output is correct
9 Correct 2 ms 3532 KB Output is correct
10 Correct 3 ms 3852 KB Output is correct
11 Correct 3 ms 3852 KB Output is correct
12 Correct 2 ms 3536 KB Output is correct
13 Correct 456 ms 6592 KB Output is correct
14 Correct 788 ms 9652 KB Output is correct
15 Correct 712 ms 9656 KB Output is correct
16 Correct 783 ms 9644 KB Output is correct
17 Correct 553 ms 6612 KB Output is correct
18 Correct 815 ms 9672 KB Output is correct
19 Correct 642 ms 9652 KB Output is correct
20 Correct 641 ms 9688 KB Output is correct
21 Correct 337 ms 3656 KB Output is correct
22 Correct 725 ms 3904 KB Output is correct
23 Correct 753 ms 3792 KB Output is correct
24 Correct 725 ms 3896 KB Output is correct
25 Correct 799 ms 12732 KB Output is correct
26 Correct 863 ms 12908 KB Output is correct
27 Correct 937 ms 12860 KB Output is correct
28 Correct 692 ms 12836 KB Output is correct
29 Correct 845 ms 39860 KB Output is correct
30 Correct 867 ms 39872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3400 KB Output is correct
2 Correct 2 ms 3400 KB Output is correct
3 Correct 2 ms 3528 KB Output is correct
4 Correct 2 ms 3528 KB Output is correct
5 Correct 2 ms 3528 KB Output is correct
6 Correct 2 ms 3528 KB Output is correct
7 Correct 2 ms 3528 KB Output is correct
8 Correct 2 ms 3528 KB Output is correct
9 Correct 2 ms 3400 KB Output is correct
10 Correct 2 ms 3528 KB Output is correct
11 Correct 2 ms 3528 KB Output is correct
12 Correct 2 ms 3528 KB Output is correct
13 Correct 2 ms 3528 KB Output is correct
14 Correct 2 ms 3532 KB Output is correct
15 Correct 3 ms 3532 KB Output is correct
16 Correct 2 ms 3532 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 3 ms 3852 KB Output is correct
19 Correct 3 ms 3852 KB Output is correct
20 Correct 2 ms 3536 KB Output is correct
21 Correct 2 ms 3532 KB Output is correct
22 Correct 2 ms 3532 KB Output is correct
23 Correct 2 ms 3492 KB Output is correct
24 Correct 3 ms 3620 KB Output is correct
25 Correct 3 ms 3532 KB Output is correct
26 Correct 2 ms 3536 KB Output is correct
27 Correct 3 ms 3536 KB Output is correct
28 Correct 3 ms 3536 KB Output is correct
29 Correct 2 ms 3528 KB Output is correct
30 Correct 2 ms 3528 KB Output is correct
31 Correct 2 ms 3852 KB Output is correct
32 Correct 2 ms 3532 KB Output is correct
33 Correct 3 ms 3528 KB Output is correct
34 Correct 3 ms 3528 KB Output is correct
35 Correct 2 ms 3528 KB Output is correct
36 Correct 3 ms 3852 KB Output is correct
37 Correct 2 ms 3784 KB Output is correct
38 Correct 3 ms 3784 KB Output is correct
39 Correct 3 ms 3540 KB Output is correct
40 Correct 3 ms 3528 KB Output is correct
41 Correct 3 ms 3536 KB Output is correct
42 Correct 2 ms 3528 KB Output is correct
43 Correct 451 ms 3684 KB Output is correct
44 Correct 717 ms 3756 KB Output is correct
45 Correct 771 ms 3760 KB Output is correct
46 Correct 755 ms 3888 KB Output is correct
47 Correct 687 ms 3912 KB Output is correct
48 Correct 648 ms 3952 KB Output is correct
49 Correct 760 ms 3884 KB Output is correct
50 Correct 537 ms 3912 KB Output is correct
51 Correct 676 ms 3656 KB Output is correct
52 Correct 684 ms 3656 KB Output is correct
53 Correct 550 ms 5068 KB Output is correct
54 Correct 577 ms 3892 KB Output is correct
55 Correct 764 ms 3740 KB Output is correct
56 Correct 620 ms 3664 KB Output is correct
57 Correct 667 ms 3636 KB Output is correct
58 Correct 635 ms 5196 KB Output is correct
59 Correct 638 ms 5300 KB Output is correct
60 Correct 735 ms 5320 KB Output is correct
61 Correct 598 ms 4084 KB Output is correct
62 Correct 781 ms 3664 KB Output is correct
63 Correct 780 ms 3636 KB Output is correct
64 Correct 717 ms 3656 KB Output is correct
65 Correct 393 ms 3656 KB Output is correct
66 Correct 705 ms 3792 KB Output is correct
67 Correct 885 ms 3900 KB Output is correct
68 Correct 618 ms 3904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3400 KB Output is correct
2 Correct 2 ms 3400 KB Output is correct
3 Correct 2 ms 3528 KB Output is correct
4 Correct 2 ms 3528 KB Output is correct
5 Correct 2 ms 3528 KB Output is correct
6 Correct 2 ms 3528 KB Output is correct
7 Correct 2 ms 3528 KB Output is correct
8 Correct 2 ms 3528 KB Output is correct
9 Correct 2 ms 3400 KB Output is correct
10 Correct 2 ms 3528 KB Output is correct
11 Correct 2 ms 3528 KB Output is correct
12 Correct 2 ms 3528 KB Output is correct
13 Correct 2 ms 3528 KB Output is correct
14 Correct 2 ms 3532 KB Output is correct
15 Correct 3 ms 3532 KB Output is correct
16 Correct 2 ms 3532 KB Output is correct
17 Correct 2 ms 3532 KB Output is correct
18 Correct 3 ms 3852 KB Output is correct
19 Correct 3 ms 3852 KB Output is correct
20 Correct 2 ms 3536 KB Output is correct
21 Correct 2 ms 3532 KB Output is correct
22 Correct 2 ms 3532 KB Output is correct
23 Correct 2 ms 3492 KB Output is correct
24 Correct 3 ms 3620 KB Output is correct
25 Correct 3 ms 3532 KB Output is correct
26 Correct 2 ms 3536 KB Output is correct
27 Correct 3 ms 3536 KB Output is correct
28 Correct 3 ms 3536 KB Output is correct
29 Correct 2 ms 3528 KB Output is correct
30 Correct 2 ms 3528 KB Output is correct
31 Correct 2 ms 3852 KB Output is correct
32 Correct 2 ms 3532 KB Output is correct
33 Correct 3 ms 3528 KB Output is correct
34 Correct 3 ms 3528 KB Output is correct
35 Correct 2 ms 3528 KB Output is correct
36 Correct 3 ms 3852 KB Output is correct
37 Correct 2 ms 3784 KB Output is correct
38 Correct 3 ms 3784 KB Output is correct
39 Correct 3 ms 3540 KB Output is correct
40 Correct 3 ms 3528 KB Output is correct
41 Correct 3 ms 3536 KB Output is correct
42 Correct 2 ms 3528 KB Output is correct
43 Correct 456 ms 6592 KB Output is correct
44 Correct 788 ms 9652 KB Output is correct
45 Correct 712 ms 9656 KB Output is correct
46 Correct 783 ms 9644 KB Output is correct
47 Correct 553 ms 6612 KB Output is correct
48 Correct 815 ms 9672 KB Output is correct
49 Correct 642 ms 9652 KB Output is correct
50 Correct 641 ms 9688 KB Output is correct
51 Correct 337 ms 3656 KB Output is correct
52 Correct 725 ms 3904 KB Output is correct
53 Correct 753 ms 3792 KB Output is correct
54 Correct 725 ms 3896 KB Output is correct
55 Correct 799 ms 12732 KB Output is correct
56 Correct 863 ms 12908 KB Output is correct
57 Correct 937 ms 12860 KB Output is correct
58 Correct 692 ms 12836 KB Output is correct
59 Correct 845 ms 39860 KB Output is correct
60 Correct 867 ms 39872 KB Output is correct
61 Correct 451 ms 3684 KB Output is correct
62 Correct 717 ms 3756 KB Output is correct
63 Correct 771 ms 3760 KB Output is correct
64 Correct 755 ms 3888 KB Output is correct
65 Correct 687 ms 3912 KB Output is correct
66 Correct 648 ms 3952 KB Output is correct
67 Correct 760 ms 3884 KB Output is correct
68 Correct 537 ms 3912 KB Output is correct
69 Correct 676 ms 3656 KB Output is correct
70 Correct 684 ms 3656 KB Output is correct
71 Correct 550 ms 5068 KB Output is correct
72 Correct 577 ms 3892 KB Output is correct
73 Correct 764 ms 3740 KB Output is correct
74 Correct 620 ms 3664 KB Output is correct
75 Correct 667 ms 3636 KB Output is correct
76 Correct 635 ms 5196 KB Output is correct
77 Correct 638 ms 5300 KB Output is correct
78 Correct 735 ms 5320 KB Output is correct
79 Correct 598 ms 4084 KB Output is correct
80 Correct 781 ms 3664 KB Output is correct
81 Correct 780 ms 3636 KB Output is correct
82 Correct 717 ms 3656 KB Output is correct
83 Correct 393 ms 3656 KB Output is correct
84 Correct 705 ms 3792 KB Output is correct
85 Correct 885 ms 3900 KB Output is correct
86 Correct 618 ms 3904 KB Output is correct
87 Correct 2 ms 3528 KB Output is correct
88 Correct 578 ms 12080 KB Output is correct
89 Correct 765 ms 10196 KB Output is correct
90 Correct 816 ms 9536 KB Output is correct
91 Correct 705 ms 12968 KB Output is correct
92 Correct 802 ms 12992 KB Output is correct
93 Correct 717 ms 12980 KB Output is correct
94 Correct 923 ms 12984 KB Output is correct
95 Correct 773 ms 12988 KB Output is correct
96 Correct 770 ms 6580 KB Output is correct
97 Correct 1008 ms 6576 KB Output is correct
98 Correct 670 ms 37496 KB Output is correct
99 Correct 723 ms 12904 KB Output is correct
100 Correct 987 ms 9396 KB Output is correct
101 Correct 844 ms 8096 KB Output is correct
102 Correct 745 ms 6336 KB Output is correct
103 Correct 993 ms 39976 KB Output is correct
104 Correct 978 ms 41824 KB Output is correct
105 Correct 639 ms 41784 KB Output is correct
106 Correct 631 ms 14932 KB Output is correct
107 Correct 760 ms 7884 KB Output is correct
108 Correct 890 ms 7628 KB Output is correct
109 Correct 869 ms 6396 KB Output is correct