답안 #777634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777634 2023-07-09T11:40:00 Z alexander707070 디지털 회로 (IOI22_circuit) C++17
52 / 100
902 ms 39040 KB
#include<bits/stdc++.h>
#define MAXN 800007
using namespace std;

const long long mod=1000002022;

int n,m,maxdep,pw;
long long st[MAXN],total,diff,zeros,ans,a[MAXN];
long long pref[MAXN],pr,sz[MAXN];
vector<int> v[MAXN];

long long power(long long x,int y){
    if(y==0)return 1;
    if(y==1)return x;
    if(y==2)return (x*x)%mod;
    if(y%2==0)return power(power(x,y/2),2);
    return (power(power(x,y/2),2)*x)%mod;
}

void calc(int x){
    if(v[x].size()==0){
        sz[x]=1; return;
    }

    sz[x]=int(v[x].size());
    for(int i=0;i<v[x].size();i++){
        calc(v[x][i]);
        sz[x]*=sz[v[x][i]]; 
        sz[x]%=mod;
    }
}

void dfs(int x,long long curr,int dep){
    if(v[x].size()==0){
        st[x]=power(2,n-dep);
        return;
    }

    long long t;
    for(int i=0;i<v[x].size();i++){
        t=1;
        for(int f=0;f<v[x].size();f++){
            if(i==f)continue;
            t*=sz[v[x][f]]; t%=mod;
        }
        dfs(v[x][i],curr*t,dep+1);
    }
}

long long tree[MAXN],lazy[MAXN];

long long sum(int l,int r){
    if(l==0)return pref[r];
    return (pref[r]-pref[l-1]+mod)%mod;
}

void psh(int v,int l,int r){
    if(lazy[v]==0)return;
    int tt=(l+r)/2;

    tree[2*v]=(sum(l,tt)-tree[2*v]+mod)%mod;
    lazy[2*v]^=1; 
    
    tree[2*v+1]=(sum(tt+1,r)-tree[2*v+1]+mod)%mod;
    lazy[2*v+1]^=1;

    lazy[v]=0;
}

void update(int v,int l,int r,int ll,int rr){
    if(ll>rr)return;
    if(l==ll and r==rr){
        tree[v]=(sum(l,r)-tree[v]+mod)%mod;
        lazy[v]^=1;
    }else{
        int tt=(l+r)/2;
        psh(v,l,r);

        update(2*v,l,tt,ll,min(tt,rr));
        update(2*v+1,tt+1,r,max(tt+1,ll),rr);

        tree[v]=(tree[2*v]+tree[2*v+1])%mod;
    }
}

void init(int N, int M,vector<int> P,vector<int> A){
    n=N; m=M;

    for(int i=1;i<N+M;i++){
        v[P[i]].push_back(i);
    }    

    calc(0);
    dfs(0,1,0);

    for(int i=0;i<m;i++){
        pref[i]=st[i+N];
        if(i>0)pref[i]+=pref[i-1];
        pref[i]%=mod;
    }

    for(int i=0;i<m;i++){
        if(A[i]==1)update(1,0,m-1,i,i);
    }
}

int count_ways(int L, int R){
    L-=n; R-=n;
    update(1,0,m-1,L,R);

    return tree[1];
}

/*
int main(){
    init(3,4, {-1,0,1,1,2,2,0}, {0,0,0,0});
    cout<<count_ways(3,5)<<"\n";
}
*/








Compilation message

circuit.cpp: In function 'void calc(int)':
circuit.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp: In function 'void dfs(int, long long int, int)':
circuit.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int f=0;f<v[x].size();f++){
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19116 KB Output is correct
2 Correct 13 ms 19084 KB Output is correct
3 Correct 13 ms 19136 KB Output is correct
4 Correct 13 ms 19152 KB Output is correct
5 Correct 14 ms 19152 KB Output is correct
6 Correct 15 ms 19196 KB Output is correct
7 Correct 16 ms 19124 KB Output is correct
8 Correct 16 ms 19156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19036 KB Output is correct
2 Correct 9 ms 19024 KB Output is correct
3 Correct 11 ms 19152 KB Output is correct
4 Correct 10 ms 19152 KB Output is correct
5 Correct 9 ms 19152 KB Output is correct
6 Correct 11 ms 19152 KB Output is correct
7 Correct 10 ms 19200 KB Output is correct
8 Correct 11 ms 19148 KB Output is correct
9 Correct 10 ms 19152 KB Output is correct
10 Correct 9 ms 19236 KB Output is correct
11 Correct 9 ms 19248 KB Output is correct
12 Correct 10 ms 19168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19116 KB Output is correct
2 Correct 13 ms 19084 KB Output is correct
3 Correct 13 ms 19136 KB Output is correct
4 Correct 13 ms 19152 KB Output is correct
5 Correct 14 ms 19152 KB Output is correct
6 Correct 15 ms 19196 KB Output is correct
7 Correct 16 ms 19124 KB Output is correct
8 Correct 16 ms 19156 KB Output is correct
9 Correct 9 ms 19036 KB Output is correct
10 Correct 9 ms 19024 KB Output is correct
11 Correct 11 ms 19152 KB Output is correct
12 Correct 10 ms 19152 KB Output is correct
13 Correct 9 ms 19152 KB Output is correct
14 Correct 11 ms 19152 KB Output is correct
15 Correct 10 ms 19200 KB Output is correct
16 Correct 11 ms 19148 KB Output is correct
17 Correct 10 ms 19152 KB Output is correct
18 Correct 9 ms 19236 KB Output is correct
19 Correct 9 ms 19248 KB Output is correct
20 Correct 10 ms 19168 KB Output is correct
21 Incorrect 12 ms 19152 KB 1st lines differ - on the 1st token, expected: '759476520', found: '833967706'
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 22604 KB Output is correct
2 Correct 729 ms 26300 KB Output is correct
3 Correct 878 ms 26220 KB Output is correct
4 Correct 710 ms 25544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 22604 KB Output is correct
2 Correct 729 ms 26300 KB Output is correct
3 Correct 878 ms 26220 KB Output is correct
4 Correct 710 ms 25544 KB Output is correct
5 Correct 628 ms 22600 KB Output is correct
6 Correct 853 ms 26252 KB Output is correct
7 Correct 779 ms 26184 KB Output is correct
8 Correct 762 ms 26260 KB Output is correct
9 Correct 322 ms 19408 KB Output is correct
10 Correct 860 ms 19584 KB Output is correct
11 Correct 776 ms 19532 KB Output is correct
12 Correct 694 ms 19536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19036 KB Output is correct
2 Correct 9 ms 19024 KB Output is correct
3 Correct 11 ms 19152 KB Output is correct
4 Correct 10 ms 19152 KB Output is correct
5 Correct 9 ms 19152 KB Output is correct
6 Correct 11 ms 19152 KB Output is correct
7 Correct 10 ms 19200 KB Output is correct
8 Correct 11 ms 19148 KB Output is correct
9 Correct 10 ms 19152 KB Output is correct
10 Correct 9 ms 19236 KB Output is correct
11 Correct 9 ms 19248 KB Output is correct
12 Correct 10 ms 19168 KB Output is correct
13 Correct 505 ms 22604 KB Output is correct
14 Correct 729 ms 26300 KB Output is correct
15 Correct 878 ms 26220 KB Output is correct
16 Correct 710 ms 25544 KB Output is correct
17 Correct 628 ms 22600 KB Output is correct
18 Correct 853 ms 26252 KB Output is correct
19 Correct 779 ms 26184 KB Output is correct
20 Correct 762 ms 26260 KB Output is correct
21 Correct 322 ms 19408 KB Output is correct
22 Correct 860 ms 19584 KB Output is correct
23 Correct 776 ms 19532 KB Output is correct
24 Correct 694 ms 19536 KB Output is correct
25 Correct 856 ms 31144 KB Output is correct
26 Correct 797 ms 31380 KB Output is correct
27 Correct 902 ms 31284 KB Output is correct
28 Correct 789 ms 31304 KB Output is correct
29 Correct 754 ms 39036 KB Output is correct
30 Correct 877 ms 39040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19116 KB Output is correct
2 Correct 13 ms 19084 KB Output is correct
3 Correct 13 ms 19136 KB Output is correct
4 Correct 13 ms 19152 KB Output is correct
5 Correct 14 ms 19152 KB Output is correct
6 Correct 15 ms 19196 KB Output is correct
7 Correct 16 ms 19124 KB Output is correct
8 Correct 16 ms 19156 KB Output is correct
9 Correct 9 ms 19036 KB Output is correct
10 Correct 9 ms 19024 KB Output is correct
11 Correct 11 ms 19152 KB Output is correct
12 Correct 10 ms 19152 KB Output is correct
13 Correct 9 ms 19152 KB Output is correct
14 Correct 11 ms 19152 KB Output is correct
15 Correct 10 ms 19200 KB Output is correct
16 Correct 11 ms 19148 KB Output is correct
17 Correct 10 ms 19152 KB Output is correct
18 Correct 9 ms 19236 KB Output is correct
19 Correct 9 ms 19248 KB Output is correct
20 Correct 10 ms 19168 KB Output is correct
21 Incorrect 12 ms 19152 KB 1st lines differ - on the 1st token, expected: '759476520', found: '833967706'
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19116 KB Output is correct
2 Correct 13 ms 19084 KB Output is correct
3 Correct 13 ms 19136 KB Output is correct
4 Correct 13 ms 19152 KB Output is correct
5 Correct 14 ms 19152 KB Output is correct
6 Correct 15 ms 19196 KB Output is correct
7 Correct 16 ms 19124 KB Output is correct
8 Correct 16 ms 19156 KB Output is correct
9 Correct 9 ms 19036 KB Output is correct
10 Correct 9 ms 19024 KB Output is correct
11 Correct 11 ms 19152 KB Output is correct
12 Correct 10 ms 19152 KB Output is correct
13 Correct 9 ms 19152 KB Output is correct
14 Correct 11 ms 19152 KB Output is correct
15 Correct 10 ms 19200 KB Output is correct
16 Correct 11 ms 19148 KB Output is correct
17 Correct 10 ms 19152 KB Output is correct
18 Correct 9 ms 19236 KB Output is correct
19 Correct 9 ms 19248 KB Output is correct
20 Correct 10 ms 19168 KB Output is correct
21 Incorrect 12 ms 19152 KB 1st lines differ - on the 1st token, expected: '759476520', found: '833967706'
22 Halted 0 ms 0 KB -