답안 #826247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826247 2023-08-15T11:32:02 Z alvingogo 디지털 회로 (IOI22_circuit) C++17
52 / 100
891 ms 26912 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
using namespace std;

const int mod=1000002022;
void add(int& x,int y){
    x+=y;
    x-=mod*(x>=mod);
}
int mul(int x,int y){
    return 1ll*x*y%mod;
}
int po(int x,int y){
    int z=1;
    while(y){
        if(y&1){
            z=mul(z,x);
        }
        x=mul(x,x);
        y>>=1;
    }
    return z;
}
const int mod2=2242157;
int inv(int x){
    return x==1?1:(int)(1ll*(mod2-mod2/x)*inv(mod2%x)%mod2);
}
int mul2(int x,int y){
    return 1ll*x*y%mod2;
}
vector<int> g,a;
struct ST{
    struct no{
        int sum=0,ans=0,tag=0;
    };
    vector<no> st;
    void init(int x){
        st.resize(4*x);
    }
    void upd(int v){
        st[v].ans=(st[v].sum-st[v].ans+mod)%mod;
        st[v].tag^=1;
    }
    void pudo(int v){
        if(st[v].tag){
            upd(2*v+1);
            upd(2*v+2);
            st[v].tag=0;
        }
    }
    void pull(int v){
        st[v].ans=(st[2*v+1].ans+st[2*v+2].ans)%mod;
    }
    void build(int v,int L,int R){
        if(L==R){
            st[v].sum=g[L];
            st[v].ans=st[v].sum*a[L];
            return;
        }
        int m=(L+R)/2;
        build(2*v+1,L,m);
        build(2*v+2,m+1,R);
        pull(v);
        st[v].sum=(st[2*v+1].sum+st[2*v+2].sum)%mod;
    }
    void toggle(int v,int L,int R,int l,int r){
        if(L==l && r==R){
            upd(v);
            return;
        }
        pudo(v);
        int m=(L+R)/2;
        if(r<=m){
            toggle(2*v+1,L,m,l,r);
        }
        else if(l>m){
            toggle(2*v+2,m+1,R,l,r);
        }
        else{
            toggle(2*v+1,L,m,l,m);
            toggle(2*v+2,m+1,R,m+1,r);
        }
        pull(v);
    }
    int query(){
        return st[0].ans; 
    }
}st;

const int x[2]={2,223};
int cnt[2]={0};
int pe=1;
int n,m;
struct tn{
    vector<int> ch;
    int deg=0;
    int cs[2]={0};
    int dx=1;
};
vector<tn> v;
void dfs(int r,int a,int b,int c){
    if(r>=n){
        int z=mul2(pe,inv(c));
        z=mul(z,po(2,cnt[0]-a));
        z=mul(z,po(223,cnt[1]-b));
        g[r-n]=z;
        return;
    }
    for(auto h:v[r].ch){
        dfs(h,a+v[r].cs[0],b+v[r].cs[1],mul2(c,v[r].dx));
    }
}
void init(int N, int M, vector<int> p, vector<int> A) {
    n=N;
    m=M;
    a=A;
    st.init(m);
    g.resize(m);
    v.resize(n+m);
    for(int i=1;i<n+m;i++){
        v[p[i]].ch.push_back(i);
        v[p[i]].deg++;
    }
    for(int i=0;i<n;i++){
        int s=v[i].deg;
        while(s%2==0){
            s/=2;
            v[i].cs[0]++;
            cnt[0]++;
        }
        while(s%223==0){
            s/=223;
            v[i].cs[1]++;
            cnt[1]++;
        }
        v[i].dx=s;
        pe=mul2(pe,s);
    }
    dfs(0,0,0,1);
    st.build(0,0,m-1);
}

int count_ways(int L, int R) {
    st.toggle(0,0,m-1,L-n,R-n);
    return st.query();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 372 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '759476520', found: '844678486'
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 6436 KB Output is correct
2 Correct 805 ms 12616 KB Output is correct
3 Correct 782 ms 12592 KB Output is correct
4 Correct 781 ms 12572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 6436 KB Output is correct
2 Correct 805 ms 12616 KB Output is correct
3 Correct 782 ms 12592 KB Output is correct
4 Correct 781 ms 12572 KB Output is correct
5 Correct 533 ms 6436 KB Output is correct
6 Correct 621 ms 12628 KB Output is correct
7 Correct 864 ms 12572 KB Output is correct
8 Correct 776 ms 12616 KB Output is correct
9 Correct 443 ms 592 KB Output is correct
10 Correct 687 ms 1060 KB Output is correct
11 Correct 634 ms 1060 KB Output is correct
12 Correct 614 ms 1064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 372 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 556 ms 6436 KB Output is correct
14 Correct 805 ms 12616 KB Output is correct
15 Correct 782 ms 12592 KB Output is correct
16 Correct 781 ms 12572 KB Output is correct
17 Correct 533 ms 6436 KB Output is correct
18 Correct 621 ms 12628 KB Output is correct
19 Correct 864 ms 12572 KB Output is correct
20 Correct 776 ms 12616 KB Output is correct
21 Correct 443 ms 592 KB Output is correct
22 Correct 687 ms 1060 KB Output is correct
23 Correct 634 ms 1060 KB Output is correct
24 Correct 614 ms 1064 KB Output is correct
25 Correct 748 ms 18632 KB Output is correct
26 Correct 671 ms 19168 KB Output is correct
27 Correct 891 ms 19048 KB Output is correct
28 Correct 622 ms 19052 KB Output is correct
29 Correct 502 ms 26912 KB Output is correct
30 Correct 841 ms 26912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '759476520', found: '844678486'
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '759476520', found: '844678486'
22 Halted 0 ms 0 KB -