Submission #1359406

#TimeUsernameProblemLanguageResultExecution timeMemory
1359406opeleklanosDigital Circuit (IOI22_circuit)C++20
0 / 100
165 ms5264 KiB
#include <iostream>
#include <vector>
using namespace std;

#define ll long long
#define MOD (ll)1000002022

vector<int> a;

struct segTree{
    int l, r;
    segTree* lc, *rc;
    int lazy;

    ll way0;
    ll way1;

    segTree(int st){
        l = r = st;
        lc = rc = nullptr;
        lazy = 0;
        way0 = (a[st] == 0);
        way1 = (a[st] == 1);
    }
    
    segTree(segTree*le, segTree*ri){
        lc = le; rc = ri;
        l = lc->l;
        r = rc->r;
        way0 = (((lc->way1 * rc->way0)%MOD) + ((lc->way0 * rc->way1)%MOD) + (2*(lc->way0 * rc->way0)%MOD))%MOD;
        way1 = (((lc->way1 * rc->way0)%MOD) + ((lc->way0 * rc->way1)%MOD) + (2*(lc->way1 * rc->way1)%MOD))%MOD;
    }
};

segTree * build(int l, int r){
    if(l == r) return new segTree(l);
    int mid = (l+r)/2;
    return new segTree(build(l, mid), build(mid+1, r));
}

int update(segTree * st, int l, int r){

    if(st->lazy){
        swap(st->way0, st->way1);
        if(l!=r){
            st->rc->lazy = !st->rc->lazy;
            st->lc->lazy = !st->lc->lazy;
        }
        st->lazy = 0;
    }

    if(st->l == l && st->r == r){
        st->lazy = !st->lazy;
        if(st->lazy){
            swap(st->way0, st->way1);
            if(l!=r){
                st->rc->lazy = !st->rc->lazy;
                st->lc->lazy = !st->lc->lazy;
            }
            st->lazy = 0;
        }
        return st->way1;
    }

    int mid = (st->l + st->r)/2;

    if(l <= mid) update(st->lc, l, min(r, mid));
    if(r > mid) update(st->rc, max(l, mid+1), r);

    int l0, l1, r0, r1;
    l0 = st->lc->way0;
    l1 = st->lc->way1;
    r0 = st->rc->way0;
    r1 = st->rc->way1;
    if(st->lc->lazy) swap(l0, l1);
    if(st->rc->lazy) swap(r0, r1);

    st->way0 = (((l1*r0)%MOD) + ((l0*r1)%MOD) + ((2*(r0*l0))%MOD))%MOD;
    st->way1 = (((l1*r0)%MOD) + ((l0*r1)%MOD) + ((2*(r1*l1))%MOD))%MOD;

    return st->way1;
}

int n, m;
segTree*sg;

void init(int N, int M, vector<int> p, vector<int> A){
    a = A;
    n = N;
    m = M;
    sg = build(0, m-1);
    return;
}

int count_ways(int L, int R){
    return update(sg, L-n, R-n);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...