Submission #629958

# Submission time Handle Problem Language Result Execution time Memory
629958 2022-08-15T12:24:28 Z jeff252 Digital Circuit (IOI22_circuit) C++17
100 / 100
1090 ms 52068 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<18;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1000002022;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int t[N],n;
vi graf[N];
ll dp[N],il[N],seg[(SS<<1)+10][2];
bool lazy[(SS<<1)+10],wl[N];
void dfs1(int v){
    il[v]=graf[v].size();
    if(graf[v].size()==0) il[v]=1;
    for(auto u:graf[v]){
        dfs1(u);
        (il[v]*=il[u])%=mod;
    }
}
void dfs2(int v,ll val){
    vector<ll> xd(graf[v].size()+1);
    dp[v]=val;
    xd[graf[v].size()]=1;
    for(int i2=graf[v].size()-1;i2>=0;i2--){
        xd[i2]=xd[i2+1]*il[graf[v][i2]]; 
        xd[i2]%=mod;
    }
    ll curr=1;
    for(int i2=0;i2<graf[v].size();i2++){
        auto u=graf[v][i2];
        dfs2(u,(((val*curr)%mod)*xd[i2+1])%mod);
        (curr=curr*il[u])%=mod;
    }
}
void push(int v){
    if(lazy[v]){
        lazy[v]=0;
        lazy[(v<<1)]^=1,lazy[(v<<1)+1]^=1;
        swap(seg[(v<<1)+1][0],seg[(v<<1)+1][1]);
        swap(seg[(v<<1)][0],seg[(v<<1)][1]);
    }
}
void upd(int a,int b,int p=0,int k=SS-1,int v=1){
    if(p>b or k<a) return;
    if(p>=a and k<=b){
        lazy[v]^=1;
        swap(seg[v][0],seg[v][1]);
        return;
    }
    push(v);
    int sr=(p+k)>>1;
    upd(a,b,p,sr,(v<<1)),upd(a,b,sr+1,k,(v<<1)+1);
    (seg[v][0]=seg[(v<<1)][0]+seg[(v<<1)+1][0])%=mod;
    (seg[v][1]=seg[(v<<1)][1]+seg[(v<<1)+1][1])%=mod;
}
void uzu(int v){
    if(v>=SS){
        if(wl[v-SS]) seg[v][1]=dp[v-SS+n];
        else seg[v][0]=dp[v-SS+n];
        return; 
    }
    uzu((v<<1)),uzu((v<<1)+1);
    (seg[v][0]=seg[(v<<1)][0]+seg[(v<<1)+1][0])%=mod;
    (seg[v][1]=seg[(v<<1)][1]+seg[(v<<1)+1][1])%=mod;
}
void init(int n2,int m,vi p,vi a){
    n=n2;
    for(int i=1;i<n+m;i++) graf[p[i]+1].push_back(i+1);
    dfs1(1);
    dfs2(1,1);
    for(int i=0;i<a.size();i++) wl[i+1]=a[i];
    uzu(1);
}
int count_ways(int l,int r){
    l++,r++;
    l-=n,r-=n;
    upd(l,r);
    return seg[1][1];
}
/*int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int n2,m2,q;
    cin>>n2>>m2>>q;
    vi p,a;
    for(int i=0;i<n2+m2;i++){
        int d;
        cin>>d;
        p.push_back(d);
    }
    for(int i=0;i<m2;i++){
        int d;
        cin>>d;
        a.push_back(d);  
    }
    init(n2,m2,p,a);
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<count_ways(l,r)<<"\n";
    }
}*/

Compilation message

circuit.cpp: In function 'void dfs2(int, ll)':
circuit.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i2=0;i2<graf[v].size();i2++){
      |                  ~~^~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, vi, vi)':
circuit.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i=0;i<a.size();i++) wl[i+1]=a[i];
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31996 KB Output is correct
2 Correct 20 ms 31932 KB Output is correct
3 Correct 18 ms 32104 KB Output is correct
4 Correct 25 ms 32008 KB Output is correct
5 Correct 24 ms 32080 KB Output is correct
6 Correct 20 ms 32080 KB Output is correct
7 Correct 20 ms 32032 KB Output is correct
8 Correct 24 ms 32040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 31952 KB Output is correct
2 Correct 20 ms 31952 KB Output is correct
3 Correct 21 ms 32080 KB Output is correct
4 Correct 18 ms 31992 KB Output is correct
5 Correct 19 ms 32112 KB Output is correct
6 Correct 24 ms 32008 KB Output is correct
7 Correct 21 ms 32132 KB Output is correct
8 Correct 23 ms 32080 KB Output is correct
9 Correct 19 ms 32172 KB Output is correct
10 Correct 24 ms 32208 KB Output is correct
11 Correct 18 ms 32208 KB Output is correct
12 Correct 19 ms 32080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31996 KB Output is correct
2 Correct 20 ms 31932 KB Output is correct
3 Correct 18 ms 32104 KB Output is correct
4 Correct 25 ms 32008 KB Output is correct
5 Correct 24 ms 32080 KB Output is correct
6 Correct 20 ms 32080 KB Output is correct
7 Correct 20 ms 32032 KB Output is correct
8 Correct 24 ms 32040 KB Output is correct
9 Correct 22 ms 31952 KB Output is correct
10 Correct 20 ms 31952 KB Output is correct
11 Correct 21 ms 32080 KB Output is correct
12 Correct 18 ms 31992 KB Output is correct
13 Correct 19 ms 32112 KB Output is correct
14 Correct 24 ms 32008 KB Output is correct
15 Correct 21 ms 32132 KB Output is correct
16 Correct 23 ms 32080 KB Output is correct
17 Correct 19 ms 32172 KB Output is correct
18 Correct 24 ms 32208 KB Output is correct
19 Correct 18 ms 32208 KB Output is correct
20 Correct 19 ms 32080 KB Output is correct
21 Correct 24 ms 32056 KB Output is correct
22 Correct 23 ms 32080 KB Output is correct
23 Correct 19 ms 32040 KB Output is correct
24 Correct 19 ms 32064 KB Output is correct
25 Correct 21 ms 32136 KB Output is correct
26 Correct 18 ms 32080 KB Output is correct
27 Correct 18 ms 32080 KB Output is correct
28 Correct 19 ms 32080 KB Output is correct
29 Correct 20 ms 32080 KB Output is correct
30 Correct 20 ms 32100 KB Output is correct
31 Correct 23 ms 32124 KB Output is correct
32 Correct 19 ms 32136 KB Output is correct
33 Correct 21 ms 32080 KB Output is correct
34 Correct 25 ms 31964 KB Output is correct
35 Correct 24 ms 32008 KB Output is correct
36 Correct 25 ms 32224 KB Output is correct
37 Correct 20 ms 32256 KB Output is correct
38 Correct 20 ms 32208 KB Output is correct
39 Correct 24 ms 32036 KB Output is correct
40 Correct 24 ms 32108 KB Output is correct
41 Correct 19 ms 32028 KB Output is correct
42 Correct 23 ms 31992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 34816 KB Output is correct
2 Correct 889 ms 37620 KB Output is correct
3 Correct 1039 ms 37700 KB Output is correct
4 Correct 947 ms 37680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 34816 KB Output is correct
2 Correct 889 ms 37620 KB Output is correct
3 Correct 1039 ms 37700 KB Output is correct
4 Correct 947 ms 37680 KB Output is correct
5 Correct 744 ms 34812 KB Output is correct
6 Correct 818 ms 37640 KB Output is correct
7 Correct 961 ms 37612 KB Output is correct
8 Correct 932 ms 37632 KB Output is correct
9 Correct 454 ms 32208 KB Output is correct
10 Correct 903 ms 32372 KB Output is correct
11 Correct 842 ms 32360 KB Output is correct
12 Correct 912 ms 32296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 31952 KB Output is correct
2 Correct 20 ms 31952 KB Output is correct
3 Correct 21 ms 32080 KB Output is correct
4 Correct 18 ms 31992 KB Output is correct
5 Correct 19 ms 32112 KB Output is correct
6 Correct 24 ms 32008 KB Output is correct
7 Correct 21 ms 32132 KB Output is correct
8 Correct 23 ms 32080 KB Output is correct
9 Correct 19 ms 32172 KB Output is correct
10 Correct 24 ms 32208 KB Output is correct
11 Correct 18 ms 32208 KB Output is correct
12 Correct 19 ms 32080 KB Output is correct
13 Correct 557 ms 34816 KB Output is correct
14 Correct 889 ms 37620 KB Output is correct
15 Correct 1039 ms 37700 KB Output is correct
16 Correct 947 ms 37680 KB Output is correct
17 Correct 744 ms 34812 KB Output is correct
18 Correct 818 ms 37640 KB Output is correct
19 Correct 961 ms 37612 KB Output is correct
20 Correct 932 ms 37632 KB Output is correct
21 Correct 454 ms 32208 KB Output is correct
22 Correct 903 ms 32372 KB Output is correct
23 Correct 842 ms 32360 KB Output is correct
24 Correct 912 ms 32296 KB Output is correct
25 Correct 961 ms 40536 KB Output is correct
26 Correct 925 ms 40712 KB Output is correct
27 Correct 862 ms 40688 KB Output is correct
28 Correct 844 ms 40684 KB Output is correct
29 Correct 847 ms 51656 KB Output is correct
30 Correct 912 ms 51656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31996 KB Output is correct
2 Correct 20 ms 31932 KB Output is correct
3 Correct 18 ms 32104 KB Output is correct
4 Correct 25 ms 32008 KB Output is correct
5 Correct 24 ms 32080 KB Output is correct
6 Correct 20 ms 32080 KB Output is correct
7 Correct 20 ms 32032 KB Output is correct
8 Correct 24 ms 32040 KB Output is correct
9 Correct 22 ms 31952 KB Output is correct
10 Correct 20 ms 31952 KB Output is correct
11 Correct 21 ms 32080 KB Output is correct
12 Correct 18 ms 31992 KB Output is correct
13 Correct 19 ms 32112 KB Output is correct
14 Correct 24 ms 32008 KB Output is correct
15 Correct 21 ms 32132 KB Output is correct
16 Correct 23 ms 32080 KB Output is correct
17 Correct 19 ms 32172 KB Output is correct
18 Correct 24 ms 32208 KB Output is correct
19 Correct 18 ms 32208 KB Output is correct
20 Correct 19 ms 32080 KB Output is correct
21 Correct 24 ms 32056 KB Output is correct
22 Correct 23 ms 32080 KB Output is correct
23 Correct 19 ms 32040 KB Output is correct
24 Correct 19 ms 32064 KB Output is correct
25 Correct 21 ms 32136 KB Output is correct
26 Correct 18 ms 32080 KB Output is correct
27 Correct 18 ms 32080 KB Output is correct
28 Correct 19 ms 32080 KB Output is correct
29 Correct 20 ms 32080 KB Output is correct
30 Correct 20 ms 32100 KB Output is correct
31 Correct 23 ms 32124 KB Output is correct
32 Correct 19 ms 32136 KB Output is correct
33 Correct 21 ms 32080 KB Output is correct
34 Correct 25 ms 31964 KB Output is correct
35 Correct 24 ms 32008 KB Output is correct
36 Correct 25 ms 32224 KB Output is correct
37 Correct 20 ms 32256 KB Output is correct
38 Correct 20 ms 32208 KB Output is correct
39 Correct 24 ms 32036 KB Output is correct
40 Correct 24 ms 32108 KB Output is correct
41 Correct 19 ms 32028 KB Output is correct
42 Correct 23 ms 31992 KB Output is correct
43 Correct 638 ms 32336 KB Output is correct
44 Correct 908 ms 32440 KB Output is correct
45 Correct 900 ms 32336 KB Output is correct
46 Correct 743 ms 32464 KB Output is correct
47 Correct 895 ms 32464 KB Output is correct
48 Correct 833 ms 32456 KB Output is correct
49 Correct 830 ms 32484 KB Output is correct
50 Correct 856 ms 32452 KB Output is correct
51 Correct 852 ms 32228 KB Output is correct
52 Correct 804 ms 32296 KB Output is correct
53 Correct 876 ms 32720 KB Output is correct
54 Correct 855 ms 32480 KB Output is correct
55 Correct 913 ms 32336 KB Output is correct
56 Correct 914 ms 32208 KB Output is correct
57 Correct 781 ms 32208 KB Output is correct
58 Correct 876 ms 33020 KB Output is correct
59 Correct 983 ms 33104 KB Output is correct
60 Correct 752 ms 33104 KB Output is correct
61 Correct 879 ms 32464 KB Output is correct
62 Correct 846 ms 32208 KB Output is correct
63 Correct 909 ms 32208 KB Output is correct
64 Correct 753 ms 32208 KB Output is correct
65 Correct 393 ms 32116 KB Output is correct
66 Correct 794 ms 32400 KB Output is correct
67 Correct 884 ms 32336 KB Output is correct
68 Correct 897 ms 32408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31996 KB Output is correct
2 Correct 20 ms 31932 KB Output is correct
3 Correct 18 ms 32104 KB Output is correct
4 Correct 25 ms 32008 KB Output is correct
5 Correct 24 ms 32080 KB Output is correct
6 Correct 20 ms 32080 KB Output is correct
7 Correct 20 ms 32032 KB Output is correct
8 Correct 24 ms 32040 KB Output is correct
9 Correct 22 ms 31952 KB Output is correct
10 Correct 20 ms 31952 KB Output is correct
11 Correct 21 ms 32080 KB Output is correct
12 Correct 18 ms 31992 KB Output is correct
13 Correct 19 ms 32112 KB Output is correct
14 Correct 24 ms 32008 KB Output is correct
15 Correct 21 ms 32132 KB Output is correct
16 Correct 23 ms 32080 KB Output is correct
17 Correct 19 ms 32172 KB Output is correct
18 Correct 24 ms 32208 KB Output is correct
19 Correct 18 ms 32208 KB Output is correct
20 Correct 19 ms 32080 KB Output is correct
21 Correct 24 ms 32056 KB Output is correct
22 Correct 23 ms 32080 KB Output is correct
23 Correct 19 ms 32040 KB Output is correct
24 Correct 19 ms 32064 KB Output is correct
25 Correct 21 ms 32136 KB Output is correct
26 Correct 18 ms 32080 KB Output is correct
27 Correct 18 ms 32080 KB Output is correct
28 Correct 19 ms 32080 KB Output is correct
29 Correct 20 ms 32080 KB Output is correct
30 Correct 20 ms 32100 KB Output is correct
31 Correct 23 ms 32124 KB Output is correct
32 Correct 19 ms 32136 KB Output is correct
33 Correct 21 ms 32080 KB Output is correct
34 Correct 25 ms 31964 KB Output is correct
35 Correct 24 ms 32008 KB Output is correct
36 Correct 25 ms 32224 KB Output is correct
37 Correct 20 ms 32256 KB Output is correct
38 Correct 20 ms 32208 KB Output is correct
39 Correct 24 ms 32036 KB Output is correct
40 Correct 24 ms 32108 KB Output is correct
41 Correct 19 ms 32028 KB Output is correct
42 Correct 23 ms 31992 KB Output is correct
43 Correct 557 ms 34816 KB Output is correct
44 Correct 889 ms 37620 KB Output is correct
45 Correct 1039 ms 37700 KB Output is correct
46 Correct 947 ms 37680 KB Output is correct
47 Correct 744 ms 34812 KB Output is correct
48 Correct 818 ms 37640 KB Output is correct
49 Correct 961 ms 37612 KB Output is correct
50 Correct 932 ms 37632 KB Output is correct
51 Correct 454 ms 32208 KB Output is correct
52 Correct 903 ms 32372 KB Output is correct
53 Correct 842 ms 32360 KB Output is correct
54 Correct 912 ms 32296 KB Output is correct
55 Correct 961 ms 40536 KB Output is correct
56 Correct 925 ms 40712 KB Output is correct
57 Correct 862 ms 40688 KB Output is correct
58 Correct 844 ms 40684 KB Output is correct
59 Correct 847 ms 51656 KB Output is correct
60 Correct 912 ms 51656 KB Output is correct
61 Correct 638 ms 32336 KB Output is correct
62 Correct 908 ms 32440 KB Output is correct
63 Correct 900 ms 32336 KB Output is correct
64 Correct 743 ms 32464 KB Output is correct
65 Correct 895 ms 32464 KB Output is correct
66 Correct 833 ms 32456 KB Output is correct
67 Correct 830 ms 32484 KB Output is correct
68 Correct 856 ms 32452 KB Output is correct
69 Correct 852 ms 32228 KB Output is correct
70 Correct 804 ms 32296 KB Output is correct
71 Correct 876 ms 32720 KB Output is correct
72 Correct 855 ms 32480 KB Output is correct
73 Correct 913 ms 32336 KB Output is correct
74 Correct 914 ms 32208 KB Output is correct
75 Correct 781 ms 32208 KB Output is correct
76 Correct 876 ms 33020 KB Output is correct
77 Correct 983 ms 33104 KB Output is correct
78 Correct 752 ms 33104 KB Output is correct
79 Correct 879 ms 32464 KB Output is correct
80 Correct 846 ms 32208 KB Output is correct
81 Correct 909 ms 32208 KB Output is correct
82 Correct 753 ms 32208 KB Output is correct
83 Correct 393 ms 32116 KB Output is correct
84 Correct 794 ms 32400 KB Output is correct
85 Correct 884 ms 32336 KB Output is correct
86 Correct 897 ms 32408 KB Output is correct
87 Correct 17 ms 31952 KB Output is correct
88 Correct 627 ms 39788 KB Output is correct
89 Correct 966 ms 37832 KB Output is correct
90 Correct 940 ms 37480 KB Output is correct
91 Correct 1090 ms 40800 KB Output is correct
92 Correct 995 ms 40808 KB Output is correct
93 Correct 839 ms 40748 KB Output is correct
94 Correct 942 ms 40768 KB Output is correct
95 Correct 898 ms 40784 KB Output is correct
96 Correct 827 ms 35656 KB Output is correct
97 Correct 810 ms 35672 KB Output is correct
98 Correct 838 ms 48424 KB Output is correct
99 Correct 1004 ms 40708 KB Output is correct
100 Correct 1016 ms 37980 KB Output is correct
101 Correct 856 ms 37084 KB Output is correct
102 Correct 834 ms 35656 KB Output is correct
103 Correct 943 ms 51596 KB Output is correct
104 Correct 913 ms 52068 KB Output is correct
105 Correct 936 ms 51976 KB Output is correct
106 Correct 942 ms 40040 KB Output is correct
107 Correct 899 ms 36424 KB Output is correct
108 Correct 900 ms 36296 KB Output is correct
109 Correct 984 ms 35924 KB Output is correct