답안 #722241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722241 2023-04-11T15:39:38 Z bin9638 디지털 회로 (IOI22_circuit) C++17
100 / 100
1321 ms 45424 KB
#include <bits/stdc++.h>

#ifndef SKY
#include "circuit.h"
#endif // SKY

using namespace std;

#define N 500010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back

int n,times;
vector<int>g[N];
ii cnt[N];
ll f[N],dp[N];

const ll mod=1000002022;

void selfmull(ll&u,ll v)
{
    v%=mod;
    u=u*v%mod;
}

struct IT_nhan
{
    ll ST[N*4]={};

    void init(int n)
    {
        for(int i=1;i<=n*4;i++)
            ST[i]=1;
    }

    void update(int id,int l,int r,int u,int v,ll val)
    {
        if(l>v||r<u)
            return;
      //  cout<<l<<" "<<r<<" "<<u<<" "<<v<<" "<<val<<endl;
        if(l>=u&&r<=v)
        {
            selfmull(ST[id],val);
            return;
        }
        int mid=(l+r)/2;
        update(id*2,l,mid,u,v,val);
        update(id*2+1,mid+1,r,u,v,val);
    }

    ll get(int id,int l,int r,int i)
    {
        //cout<<id<<" "<<l<<" "<<r<<" "<<i<<endl;
        if(l>i||r<i)
            return 1;
        ll res=ST[id];
        if(l==r)
            return res;
        int mid=(l+r)/2;
        selfmull(res,get(id*2,l,mid,i));
        selfmull(res,get(id*2+1,mid+1,r,i));
        return res;
    }
}nhan;

struct IT_cong
{
    struct node
    {
        ll sum=0,val=0;
        int t=0;
    }ST[N*4];

    void down(int id)
    {
        if(ST[id].t==0)
            return;
        ST[id*2].t^=1;
        ST[id*2+1].t^=1;
        ST[id*2].val=(ST[id*2].sum-ST[id*2].val);
        ST[id*2+1].val=(ST[id*2+1].sum-ST[id*2+1].val);
        ST[id].t=0;
    }

    void update(int id,int l,int r,int i,ll val)
    {
        if(l>i||r<i)
            return;
        if(l==r)
        {
        //    cout<<i<<" "<<val<<endl;
            ST[id].sum=val;
            return;
        }
        int mid=(l+r)/2;
        update(id*2,l,mid,i,val);
        update(id*2+1,mid+1,r,i,val);
        ST[id].sum=ST[id*2].sum+ST[id*2+1].sum;
    }

    void flip(int id,int l,int r,int u,int v)
    {
        if(l>v||r<u)
            return;
       // cout<<l<<" "<<r<<" "<<u<<" "<<v<<endl;
        if(l>=u&&r<=v)
        {
            ST[id].val=(ST[id].sum-ST[id].val);
            ST[id].t^=1;
            //cout<<ST[id].val<<endl;
            return;
        }
        down(id);
        int mid=(l+r)/2;
        flip(id*2,l,mid,u,v);
        flip(id*2+1,mid+1,r,u,v);
        ST[id].val=ST[id*2].val+ST[id*2+1].val;
    }
}cong;

void DFS(int u)
{
    f[u]=max(1,(int)g[u].size());
    cnt[u].fs=++times;
    for(auto v:g[u])
    {
        DFS(v);
        selfmull(f[u],f[v]);
    }
    cnt[u].sc=times;
    ll S=1;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        nhan.update(1,1,n,cnt[v].fs,cnt[v].sc,S);
        selfmull(S,f[v]);
    }
    S=1;
    for(int i=g[u].size()-1;i>=0;i--)
    {
        int v=g[u][i];
        nhan.update(1,1,n,cnt[v].fs,cnt[v].sc,S);
        selfmull(S,f[v]);
    }
}

void init(int NNN, int MMM, vector<int> P, vector<int> A)
{
    n=NNN+MMM;
    for(int i=1;i<n;i++)
        g[P[i]].pb(i);
    nhan.init(n);
    DFS(0);
    for(int i=NNN;i<n;i++)
    {
        dp[i]=nhan.get(1,1,n,cnt[i].fs);
       // cout<<i<<" "<<dp[i]<<endl;
       cong.update(1,1,n,i+1,dp[i]);
    }
    for(int i=0;i<MMM;i++)
        if(A[i]==1)
            cong.flip(1,1,n,NNN+i+1,NNN+i+1);
}

int count_ways(int L, int R)
{
    cong.flip(1,1,n,L+1,R+1);
    return (cong.ST[1].val%mod+mod*mod)%mod;
}


#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<int>P(n+m),A(m);
    for(int i=0;i<n+m;i++)
        cin>>P[i];
    for(int i=0;i<m;i++)
        cin>>A[i];
    init(n,m,P,A);
    int q;
    cin>>q;
    while(q--)
    {
        int L,R;
        cin>>L>>R;
        cout<<count_ways(L,R)<<endl;
    }
    return 0;
}
#endif

Compilation message

circuit.cpp: In function 'void DFS(int)':
circuit.cpp:135:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |     for(int i=0;i<g[u].size();i++)
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11984 KB Output is correct
2 Correct 7 ms 11984 KB Output is correct
3 Correct 7 ms 12132 KB Output is correct
4 Correct 7 ms 12112 KB Output is correct
5 Correct 7 ms 12112 KB Output is correct
6 Correct 7 ms 12112 KB Output is correct
7 Correct 9 ms 12112 KB Output is correct
8 Correct 8 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11984 KB Output is correct
2 Correct 6 ms 12052 KB Output is correct
3 Correct 7 ms 12112 KB Output is correct
4 Correct 8 ms 12136 KB Output is correct
5 Correct 8 ms 12128 KB Output is correct
6 Correct 7 ms 12240 KB Output is correct
7 Correct 8 ms 12240 KB Output is correct
8 Correct 8 ms 12240 KB Output is correct
9 Correct 11 ms 12172 KB Output is correct
10 Correct 7 ms 12368 KB Output is correct
11 Correct 10 ms 12308 KB Output is correct
12 Correct 8 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11984 KB Output is correct
2 Correct 7 ms 11984 KB Output is correct
3 Correct 7 ms 12132 KB Output is correct
4 Correct 7 ms 12112 KB Output is correct
5 Correct 7 ms 12112 KB Output is correct
6 Correct 7 ms 12112 KB Output is correct
7 Correct 9 ms 12112 KB Output is correct
8 Correct 8 ms 12112 KB Output is correct
9 Correct 6 ms 11984 KB Output is correct
10 Correct 6 ms 12052 KB Output is correct
11 Correct 7 ms 12112 KB Output is correct
12 Correct 8 ms 12136 KB Output is correct
13 Correct 8 ms 12128 KB Output is correct
14 Correct 7 ms 12240 KB Output is correct
15 Correct 8 ms 12240 KB Output is correct
16 Correct 8 ms 12240 KB Output is correct
17 Correct 11 ms 12172 KB Output is correct
18 Correct 7 ms 12368 KB Output is correct
19 Correct 10 ms 12308 KB Output is correct
20 Correct 8 ms 12240 KB Output is correct
21 Correct 7 ms 12240 KB Output is correct
22 Correct 7 ms 12196 KB Output is correct
23 Correct 8 ms 12112 KB Output is correct
24 Correct 7 ms 12240 KB Output is correct
25 Correct 8 ms 12196 KB Output is correct
26 Correct 9 ms 12240 KB Output is correct
27 Correct 8 ms 12264 KB Output is correct
28 Correct 8 ms 12240 KB Output is correct
29 Correct 7 ms 12112 KB Output is correct
30 Correct 7 ms 12112 KB Output is correct
31 Correct 7 ms 12240 KB Output is correct
32 Correct 7 ms 12240 KB Output is correct
33 Correct 8 ms 12240 KB Output is correct
34 Correct 7 ms 12240 KB Output is correct
35 Correct 7 ms 12112 KB Output is correct
36 Correct 7 ms 12368 KB Output is correct
37 Correct 8 ms 12368 KB Output is correct
38 Correct 9 ms 12368 KB Output is correct
39 Correct 7 ms 12112 KB Output is correct
40 Correct 8 ms 12240 KB Output is correct
41 Correct 7 ms 12240 KB Output is correct
42 Correct 7 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 713 ms 18696 KB Output is correct
2 Correct 846 ms 25416 KB Output is correct
3 Correct 775 ms 25576 KB Output is correct
4 Correct 968 ms 25396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 713 ms 18696 KB Output is correct
2 Correct 846 ms 25416 KB Output is correct
3 Correct 775 ms 25576 KB Output is correct
4 Correct 968 ms 25396 KB Output is correct
5 Correct 746 ms 18688 KB Output is correct
6 Correct 915 ms 25344 KB Output is correct
7 Correct 990 ms 25344 KB Output is correct
8 Correct 938 ms 25400 KB Output is correct
9 Correct 386 ms 12496 KB Output is correct
10 Correct 834 ms 12880 KB Output is correct
11 Correct 779 ms 12880 KB Output is correct
12 Correct 908 ms 12880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11984 KB Output is correct
2 Correct 6 ms 12052 KB Output is correct
3 Correct 7 ms 12112 KB Output is correct
4 Correct 8 ms 12136 KB Output is correct
5 Correct 8 ms 12128 KB Output is correct
6 Correct 7 ms 12240 KB Output is correct
7 Correct 8 ms 12240 KB Output is correct
8 Correct 8 ms 12240 KB Output is correct
9 Correct 11 ms 12172 KB Output is correct
10 Correct 7 ms 12368 KB Output is correct
11 Correct 10 ms 12308 KB Output is correct
12 Correct 8 ms 12240 KB Output is correct
13 Correct 713 ms 18696 KB Output is correct
14 Correct 846 ms 25416 KB Output is correct
15 Correct 775 ms 25576 KB Output is correct
16 Correct 968 ms 25396 KB Output is correct
17 Correct 746 ms 18688 KB Output is correct
18 Correct 915 ms 25344 KB Output is correct
19 Correct 990 ms 25344 KB Output is correct
20 Correct 938 ms 25400 KB Output is correct
21 Correct 386 ms 12496 KB Output is correct
22 Correct 834 ms 12880 KB Output is correct
23 Correct 779 ms 12880 KB Output is correct
24 Correct 908 ms 12880 KB Output is correct
25 Correct 986 ms 33720 KB Output is correct
26 Correct 1265 ms 33920 KB Output is correct
27 Correct 1267 ms 33860 KB Output is correct
28 Correct 932 ms 33940 KB Output is correct
29 Correct 1269 ms 44900 KB Output is correct
30 Correct 1085 ms 44892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11984 KB Output is correct
2 Correct 7 ms 11984 KB Output is correct
3 Correct 7 ms 12132 KB Output is correct
4 Correct 7 ms 12112 KB Output is correct
5 Correct 7 ms 12112 KB Output is correct
6 Correct 7 ms 12112 KB Output is correct
7 Correct 9 ms 12112 KB Output is correct
8 Correct 8 ms 12112 KB Output is correct
9 Correct 6 ms 11984 KB Output is correct
10 Correct 6 ms 12052 KB Output is correct
11 Correct 7 ms 12112 KB Output is correct
12 Correct 8 ms 12136 KB Output is correct
13 Correct 8 ms 12128 KB Output is correct
14 Correct 7 ms 12240 KB Output is correct
15 Correct 8 ms 12240 KB Output is correct
16 Correct 8 ms 12240 KB Output is correct
17 Correct 11 ms 12172 KB Output is correct
18 Correct 7 ms 12368 KB Output is correct
19 Correct 10 ms 12308 KB Output is correct
20 Correct 8 ms 12240 KB Output is correct
21 Correct 7 ms 12240 KB Output is correct
22 Correct 7 ms 12196 KB Output is correct
23 Correct 8 ms 12112 KB Output is correct
24 Correct 7 ms 12240 KB Output is correct
25 Correct 8 ms 12196 KB Output is correct
26 Correct 9 ms 12240 KB Output is correct
27 Correct 8 ms 12264 KB Output is correct
28 Correct 8 ms 12240 KB Output is correct
29 Correct 7 ms 12112 KB Output is correct
30 Correct 7 ms 12112 KB Output is correct
31 Correct 7 ms 12240 KB Output is correct
32 Correct 7 ms 12240 KB Output is correct
33 Correct 8 ms 12240 KB Output is correct
34 Correct 7 ms 12240 KB Output is correct
35 Correct 7 ms 12112 KB Output is correct
36 Correct 7 ms 12368 KB Output is correct
37 Correct 8 ms 12368 KB Output is correct
38 Correct 9 ms 12368 KB Output is correct
39 Correct 7 ms 12112 KB Output is correct
40 Correct 8 ms 12240 KB Output is correct
41 Correct 7 ms 12240 KB Output is correct
42 Correct 7 ms 12112 KB Output is correct
43 Correct 681 ms 12624 KB Output is correct
44 Correct 1062 ms 12748 KB Output is correct
45 Correct 1016 ms 12752 KB Output is correct
46 Correct 1062 ms 13264 KB Output is correct
47 Correct 1020 ms 13264 KB Output is correct
48 Correct 1146 ms 13208 KB Output is correct
49 Correct 1034 ms 13264 KB Output is correct
50 Correct 1058 ms 13264 KB Output is correct
51 Correct 853 ms 12752 KB Output is correct
52 Correct 984 ms 12752 KB Output is correct
53 Correct 948 ms 13008 KB Output is correct
54 Correct 889 ms 13264 KB Output is correct
55 Correct 989 ms 12880 KB Output is correct
56 Correct 656 ms 12808 KB Output is correct
57 Correct 951 ms 12812 KB Output is correct
58 Correct 903 ms 13776 KB Output is correct
59 Correct 742 ms 13856 KB Output is correct
60 Correct 939 ms 13852 KB Output is correct
61 Correct 861 ms 12752 KB Output is correct
62 Correct 773 ms 12676 KB Output is correct
63 Correct 937 ms 12688 KB Output is correct
64 Correct 723 ms 12752 KB Output is correct
65 Correct 437 ms 12496 KB Output is correct
66 Correct 851 ms 12828 KB Output is correct
67 Correct 644 ms 12896 KB Output is correct
68 Correct 740 ms 12880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11984 KB Output is correct
2 Correct 7 ms 11984 KB Output is correct
3 Correct 7 ms 12132 KB Output is correct
4 Correct 7 ms 12112 KB Output is correct
5 Correct 7 ms 12112 KB Output is correct
6 Correct 7 ms 12112 KB Output is correct
7 Correct 9 ms 12112 KB Output is correct
8 Correct 8 ms 12112 KB Output is correct
9 Correct 6 ms 11984 KB Output is correct
10 Correct 6 ms 12052 KB Output is correct
11 Correct 7 ms 12112 KB Output is correct
12 Correct 8 ms 12136 KB Output is correct
13 Correct 8 ms 12128 KB Output is correct
14 Correct 7 ms 12240 KB Output is correct
15 Correct 8 ms 12240 KB Output is correct
16 Correct 8 ms 12240 KB Output is correct
17 Correct 11 ms 12172 KB Output is correct
18 Correct 7 ms 12368 KB Output is correct
19 Correct 10 ms 12308 KB Output is correct
20 Correct 8 ms 12240 KB Output is correct
21 Correct 7 ms 12240 KB Output is correct
22 Correct 7 ms 12196 KB Output is correct
23 Correct 8 ms 12112 KB Output is correct
24 Correct 7 ms 12240 KB Output is correct
25 Correct 8 ms 12196 KB Output is correct
26 Correct 9 ms 12240 KB Output is correct
27 Correct 8 ms 12264 KB Output is correct
28 Correct 8 ms 12240 KB Output is correct
29 Correct 7 ms 12112 KB Output is correct
30 Correct 7 ms 12112 KB Output is correct
31 Correct 7 ms 12240 KB Output is correct
32 Correct 7 ms 12240 KB Output is correct
33 Correct 8 ms 12240 KB Output is correct
34 Correct 7 ms 12240 KB Output is correct
35 Correct 7 ms 12112 KB Output is correct
36 Correct 7 ms 12368 KB Output is correct
37 Correct 8 ms 12368 KB Output is correct
38 Correct 9 ms 12368 KB Output is correct
39 Correct 7 ms 12112 KB Output is correct
40 Correct 8 ms 12240 KB Output is correct
41 Correct 7 ms 12240 KB Output is correct
42 Correct 7 ms 12112 KB Output is correct
43 Correct 713 ms 18696 KB Output is correct
44 Correct 846 ms 25416 KB Output is correct
45 Correct 775 ms 25576 KB Output is correct
46 Correct 968 ms 25396 KB Output is correct
47 Correct 746 ms 18688 KB Output is correct
48 Correct 915 ms 25344 KB Output is correct
49 Correct 990 ms 25344 KB Output is correct
50 Correct 938 ms 25400 KB Output is correct
51 Correct 386 ms 12496 KB Output is correct
52 Correct 834 ms 12880 KB Output is correct
53 Correct 779 ms 12880 KB Output is correct
54 Correct 908 ms 12880 KB Output is correct
55 Correct 986 ms 33720 KB Output is correct
56 Correct 1265 ms 33920 KB Output is correct
57 Correct 1267 ms 33860 KB Output is correct
58 Correct 932 ms 33940 KB Output is correct
59 Correct 1269 ms 44900 KB Output is correct
60 Correct 1085 ms 44892 KB Output is correct
61 Correct 681 ms 12624 KB Output is correct
62 Correct 1062 ms 12748 KB Output is correct
63 Correct 1016 ms 12752 KB Output is correct
64 Correct 1062 ms 13264 KB Output is correct
65 Correct 1020 ms 13264 KB Output is correct
66 Correct 1146 ms 13208 KB Output is correct
67 Correct 1034 ms 13264 KB Output is correct
68 Correct 1058 ms 13264 KB Output is correct
69 Correct 853 ms 12752 KB Output is correct
70 Correct 984 ms 12752 KB Output is correct
71 Correct 948 ms 13008 KB Output is correct
72 Correct 889 ms 13264 KB Output is correct
73 Correct 989 ms 12880 KB Output is correct
74 Correct 656 ms 12808 KB Output is correct
75 Correct 951 ms 12812 KB Output is correct
76 Correct 903 ms 13776 KB Output is correct
77 Correct 742 ms 13856 KB Output is correct
78 Correct 939 ms 13852 KB Output is correct
79 Correct 861 ms 12752 KB Output is correct
80 Correct 773 ms 12676 KB Output is correct
81 Correct 937 ms 12688 KB Output is correct
82 Correct 723 ms 12752 KB Output is correct
83 Correct 437 ms 12496 KB Output is correct
84 Correct 851 ms 12828 KB Output is correct
85 Correct 644 ms 12896 KB Output is correct
86 Correct 740 ms 12880 KB Output is correct
87 Correct 7 ms 11984 KB Output is correct
88 Correct 632 ms 31716 KB Output is correct
89 Correct 927 ms 24704 KB Output is correct
90 Correct 996 ms 24688 KB Output is correct
91 Correct 948 ms 33940 KB Output is correct
92 Correct 932 ms 34224 KB Output is correct
93 Correct 987 ms 34012 KB Output is correct
94 Correct 899 ms 34076 KB Output is correct
95 Correct 861 ms 34016 KB Output is correct
96 Correct 847 ms 25760 KB Output is correct
97 Correct 1095 ms 25784 KB Output is correct
98 Correct 719 ms 31624 KB Output is correct
99 Correct 1114 ms 33880 KB Output is correct
100 Correct 991 ms 31572 KB Output is correct
101 Correct 990 ms 26696 KB Output is correct
102 Correct 1167 ms 25772 KB Output is correct
103 Correct 1076 ms 44784 KB Output is correct
104 Correct 1022 ms 45328 KB Output is correct
105 Correct 1321 ms 45424 KB Output is correct
106 Correct 1012 ms 26232 KB Output is correct
107 Correct 984 ms 24136 KB Output is correct
108 Correct 880 ms 24648 KB Output is correct
109 Correct 1046 ms 25800 KB Output is correct