Submission #628060

# Submission time Handle Problem Language Result Execution time Memory
628060 2022-08-13T04:09:08 Z MarkBcc168 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 14644 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<ll> w(100005);

const ll mod = 1e9+2022;

struct Node{
    Node *l_child, *r_child;
    int l,r; bool lazy, flipped;
    Node(){}
    Node(int _l, int _r){
        l = _l; r = _r; lazy = false;
        int m = (l+r)/2;
        if(r-l > 1){
            l_child = new Node(l,m);
            r_child = new Node(m,r);
        }
        //cout << l << " " << r << "\n";
    }
    void push(){
        if(!lazy || r-l == 1) return;
        else{
            lazy = false;
            l_child->lazy = !l_child->lazy;
            r_child->lazy = !r_child->lazy;
        }
    }
    void flip(int L, int R){
        if(R <= l || L >= r) return; //not intersect
        else if(L <= l && r <= R) lazy = !lazy;
        else if(r-l == 1) lazy = !lazy;
        else{
            l_child->flip(L,R);
            r_child->flip(L,R);
        }
    }
    ll query(){
        if(r-l == 1) return (lazy?1:0) * ((w[r] - w[l] + mod) % mod);
        else{
            push();
            return (l_child->query() + r_child->query()) % mod;
        }
    }
};

ll exp(ll a, ll n){
    if(n==0) return 1;
    if(n==1) return a%mod;
    ll x = exp(a, n/2);
    if(n%2==0) return (x*x)%mod;
    else return (((x*x)%mod)*a)%mod;
} 

const ll p = 2;
const ll q = 223;
const ll r = 2242157;
const ll phi = (p-1)*(q-1)*(r-1);

struct mint{
    int vp, vq; ll n;
    mint(ll _n){
        vp = 0; vq = 0;
        n = _n;
        while(n%p==0){vp++; n/=p;}
        while(n%q==0){vq++; n/=q;}
        n = n%mod;
    }
    mint(int _vp, int _vq, ll _n){
        vp = _vp; vq = _vq; n = _n%mod;
    }
    friend mint operator *(mint a, mint b){
        return mint(a.vp+b.vp, a.vq+b.vq, a.n*b.n);
    }
    mint inv(){
        return mint(-vp, -vq, exp(n,phi-1));
    }
    friend mint operator /(mint a, mint b){
        return a * b.inv();
    }
    ll to_int(){
        assert(vp >= 0 && vq >= 0);
        ll m=n;
        m = (m*exp(p,vp)) % mod;
        m = (m*exp(q,vq)) % mod;
        return m;
    }
};

int n,m;
Node tr(0,100005);

void init(int _n, int _m, std::vector<int> p, std::vector<int> a){
    n = _n; m = _m;
    //step 1: compute degree
    vector<int> adj[n];
    vector<int> d(n,0);
    vector<mint> d_mod(n,1);
    mint prod(1);
    for(int i=1; i<n+m; ++i){
        adj[p[i]].push_back(i);
        d[p[i]]++;
    }
    for(int i=0; i<n; ++i){
        d_mod[i] = mint(d[i]);
        prod = prod * d_mod[i];
    }
    //step 2: dfs to find weight of each leaf
    vector<mint> node_w(n+m, mint(1));
    node_w[0] = prod;

    vector<int> st(1,0);
    while(!st.empty()){
        int v = st[st.size()-1];
        st.pop_back();
        //cout << v << "\n";
        for(int u : adj[v]){
            node_w[u] = node_w[v] / d_mod[v];
            if(u < n) st.push_back(u);
        }
    }
    //step 3: build the tree
    w[0] = 0;
    for(int i=0; i<m; ++i){
        w[i+1] = w[i] + node_w[i+n].to_int();
    }
    for(int i=0; i<m; ++i){
        if(a[i] == 1) tr.flip(i,i+1);
    }
}
int count_ways(int l, int r){
    tr.flip(l-n,r-n+1);
    return tr.query();
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10448 KB Output is correct
2 Correct 13 ms 10448 KB Output is correct
3 Correct 16 ms 10436 KB Output is correct
4 Correct 14 ms 10448 KB Output is correct
5 Correct 13 ms 10448 KB Output is correct
6 Correct 14 ms 10504 KB Output is correct
7 Correct 14 ms 10500 KB Output is correct
8 Correct 14 ms 10460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 10380 KB Output is correct
2 Correct 11 ms 10412 KB Output is correct
3 Correct 17 ms 10484 KB Output is correct
4 Correct 15 ms 10544 KB Output is correct
5 Correct 14 ms 10468 KB Output is correct
6 Correct 13 ms 10572 KB Output is correct
7 Correct 16 ms 10552 KB Output is correct
8 Correct 19 ms 10576 KB Output is correct
9 Correct 13 ms 10552 KB Output is correct
10 Correct 15 ms 10572 KB Output is correct
11 Correct 15 ms 10576 KB Output is correct
12 Correct 15 ms 10520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10448 KB Output is correct
2 Correct 13 ms 10448 KB Output is correct
3 Correct 16 ms 10436 KB Output is correct
4 Correct 14 ms 10448 KB Output is correct
5 Correct 13 ms 10448 KB Output is correct
6 Correct 14 ms 10504 KB Output is correct
7 Correct 14 ms 10500 KB Output is correct
8 Correct 14 ms 10460 KB Output is correct
9 Correct 16 ms 10380 KB Output is correct
10 Correct 11 ms 10412 KB Output is correct
11 Correct 17 ms 10484 KB Output is correct
12 Correct 15 ms 10544 KB Output is correct
13 Correct 14 ms 10468 KB Output is correct
14 Correct 13 ms 10572 KB Output is correct
15 Correct 16 ms 10552 KB Output is correct
16 Correct 19 ms 10576 KB Output is correct
17 Correct 13 ms 10552 KB Output is correct
18 Correct 15 ms 10572 KB Output is correct
19 Correct 15 ms 10576 KB Output is correct
20 Correct 15 ms 10520 KB Output is correct
21 Correct 13 ms 10516 KB Output is correct
22 Correct 16 ms 10600 KB Output is correct
23 Correct 15 ms 10448 KB Output is correct
24 Correct 17 ms 10536 KB Output is correct
25 Correct 17 ms 10576 KB Output is correct
26 Correct 14 ms 10576 KB Output is correct
27 Correct 18 ms 10560 KB Output is correct
28 Correct 17 ms 10576 KB Output is correct
29 Correct 17 ms 10404 KB Output is correct
30 Correct 14 ms 10492 KB Output is correct
31 Correct 18 ms 10456 KB Output is correct
32 Correct 20 ms 10576 KB Output is correct
33 Correct 14 ms 10448 KB Output is correct
34 Correct 14 ms 10448 KB Output is correct
35 Correct 15 ms 10444 KB Output is correct
36 Correct 16 ms 10576 KB Output is correct
37 Correct 16 ms 10560 KB Output is correct
38 Correct 18 ms 10576 KB Output is correct
39 Correct 13 ms 10568 KB Output is correct
40 Correct 14 ms 10556 KB Output is correct
41 Correct 14 ms 10544 KB Output is correct
42 Correct 14 ms 10408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 14644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 14644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 10380 KB Output is correct
2 Correct 11 ms 10412 KB Output is correct
3 Correct 17 ms 10484 KB Output is correct
4 Correct 15 ms 10544 KB Output is correct
5 Correct 14 ms 10468 KB Output is correct
6 Correct 13 ms 10572 KB Output is correct
7 Correct 16 ms 10552 KB Output is correct
8 Correct 19 ms 10576 KB Output is correct
9 Correct 13 ms 10552 KB Output is correct
10 Correct 15 ms 10572 KB Output is correct
11 Correct 15 ms 10576 KB Output is correct
12 Correct 15 ms 10520 KB Output is correct
13 Execution timed out 3073 ms 14644 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10448 KB Output is correct
2 Correct 13 ms 10448 KB Output is correct
3 Correct 16 ms 10436 KB Output is correct
4 Correct 14 ms 10448 KB Output is correct
5 Correct 13 ms 10448 KB Output is correct
6 Correct 14 ms 10504 KB Output is correct
7 Correct 14 ms 10500 KB Output is correct
8 Correct 14 ms 10460 KB Output is correct
9 Correct 16 ms 10380 KB Output is correct
10 Correct 11 ms 10412 KB Output is correct
11 Correct 17 ms 10484 KB Output is correct
12 Correct 15 ms 10544 KB Output is correct
13 Correct 14 ms 10468 KB Output is correct
14 Correct 13 ms 10572 KB Output is correct
15 Correct 16 ms 10552 KB Output is correct
16 Correct 19 ms 10576 KB Output is correct
17 Correct 13 ms 10552 KB Output is correct
18 Correct 15 ms 10572 KB Output is correct
19 Correct 15 ms 10576 KB Output is correct
20 Correct 15 ms 10520 KB Output is correct
21 Correct 13 ms 10516 KB Output is correct
22 Correct 16 ms 10600 KB Output is correct
23 Correct 15 ms 10448 KB Output is correct
24 Correct 17 ms 10536 KB Output is correct
25 Correct 17 ms 10576 KB Output is correct
26 Correct 14 ms 10576 KB Output is correct
27 Correct 18 ms 10560 KB Output is correct
28 Correct 17 ms 10576 KB Output is correct
29 Correct 17 ms 10404 KB Output is correct
30 Correct 14 ms 10492 KB Output is correct
31 Correct 18 ms 10456 KB Output is correct
32 Correct 20 ms 10576 KB Output is correct
33 Correct 14 ms 10448 KB Output is correct
34 Correct 14 ms 10448 KB Output is correct
35 Correct 15 ms 10444 KB Output is correct
36 Correct 16 ms 10576 KB Output is correct
37 Correct 16 ms 10560 KB Output is correct
38 Correct 18 ms 10576 KB Output is correct
39 Correct 13 ms 10568 KB Output is correct
40 Correct 14 ms 10556 KB Output is correct
41 Correct 14 ms 10544 KB Output is correct
42 Correct 14 ms 10408 KB Output is correct
43 Execution timed out 3082 ms 10832 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10448 KB Output is correct
2 Correct 13 ms 10448 KB Output is correct
3 Correct 16 ms 10436 KB Output is correct
4 Correct 14 ms 10448 KB Output is correct
5 Correct 13 ms 10448 KB Output is correct
6 Correct 14 ms 10504 KB Output is correct
7 Correct 14 ms 10500 KB Output is correct
8 Correct 14 ms 10460 KB Output is correct
9 Correct 16 ms 10380 KB Output is correct
10 Correct 11 ms 10412 KB Output is correct
11 Correct 17 ms 10484 KB Output is correct
12 Correct 15 ms 10544 KB Output is correct
13 Correct 14 ms 10468 KB Output is correct
14 Correct 13 ms 10572 KB Output is correct
15 Correct 16 ms 10552 KB Output is correct
16 Correct 19 ms 10576 KB Output is correct
17 Correct 13 ms 10552 KB Output is correct
18 Correct 15 ms 10572 KB Output is correct
19 Correct 15 ms 10576 KB Output is correct
20 Correct 15 ms 10520 KB Output is correct
21 Correct 13 ms 10516 KB Output is correct
22 Correct 16 ms 10600 KB Output is correct
23 Correct 15 ms 10448 KB Output is correct
24 Correct 17 ms 10536 KB Output is correct
25 Correct 17 ms 10576 KB Output is correct
26 Correct 14 ms 10576 KB Output is correct
27 Correct 18 ms 10560 KB Output is correct
28 Correct 17 ms 10576 KB Output is correct
29 Correct 17 ms 10404 KB Output is correct
30 Correct 14 ms 10492 KB Output is correct
31 Correct 18 ms 10456 KB Output is correct
32 Correct 20 ms 10576 KB Output is correct
33 Correct 14 ms 10448 KB Output is correct
34 Correct 14 ms 10448 KB Output is correct
35 Correct 15 ms 10444 KB Output is correct
36 Correct 16 ms 10576 KB Output is correct
37 Correct 16 ms 10560 KB Output is correct
38 Correct 18 ms 10576 KB Output is correct
39 Correct 13 ms 10568 KB Output is correct
40 Correct 14 ms 10556 KB Output is correct
41 Correct 14 ms 10544 KB Output is correct
42 Correct 14 ms 10408 KB Output is correct
43 Execution timed out 3073 ms 14644 KB Time limit exceeded
44 Halted 0 ms 0 KB -