제출 #711341

#제출 시각아이디문제언어결과실행 시간메모리
711341Jarif_Rahman디지털 회로 (IOI22_circuit)C++17
16 / 100
1027 ms3500 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const ll md = 1000002022;

struct segtree{
    struct node{
        int sum = 0, sz = 1;
        bool rev = 0;
        node(){
        }
        node operator+(node X){
            node rt;
            rt.sz = sz+X.sz;
            rt.sum = sum+X.sum;
            return rt;
        }
        void pushdown(node &X){
            if(!rev) return;
            X.rev^=rev;
            X.sum = X.sz-X.sum;
        }
    };
    int k;
    vector<node> v;
    segtree(int n){
        k = 1;
        while(k < n) k*=2;
        v.resize(2*k, node());
        for(int i = k-1; i > 0; i--) v[i] = v[2*i]+v[2*i+1];
    }
    void update(int l, int r, int nd, int a, int b){
        if(a > r || b < l) return;
        if(a >= l && b <= r){
            v[nd].rev^=1;
            v[nd].sum = v[nd].sz-v[nd].sum;
            return;
        }
        int mid = (a+b)/2;
        v[nd].pushdown(v[2*nd]);
        v[nd].pushdown(v[2*nd+1]);
        v[nd].rev = 0;
        update(l, r, 2*nd, a, mid);
        update(l, r, 2*nd+1, mid+1, b);
        v[nd] = v[2*nd]+v[2*nd+1];
    }
    void update(int l, int r){
        update(l, r, 1, 0, k-1);
    }
    int get(){
        return v[1].sum;
    }
};

int n, m;
vector<int> P, A;
segtree s(0);
ll pw = 1;

void init(int _n, int _m, vector<int> _P, vector<int> _A){
    swap(n, _n), swap(m, _m), swap(P, _P), swap(A, _A);
    s = segtree(m);
    for(int i = 0; i < m; i++) if(A[i]) s.update(i, i);
    for(int i = 0; i < n-__builtin_ctz(m); i++) pw*=2, pw%=md;
}

int count_ways(int L, int R){
    s.update(L-n, R-n);
    return (s.get()*pw)%md;
}
#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...