Submission #629956

# Submission time Handle Problem Language Result Execution time Memory
629956 2022-08-15T12:24:02 Z jeff252 Digital Circuit (IOI22_circuit) C++17
52 / 100
1181 ms 51680 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){
    vi 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 19 ms 31972 KB Output is correct
2 Correct 22 ms 32028 KB Output is correct
3 Correct 23 ms 32080 KB Output is correct
4 Correct 24 ms 31988 KB Output is correct
5 Correct 24 ms 32084 KB Output is correct
6 Correct 21 ms 32080 KB Output is correct
7 Correct 22 ms 32040 KB Output is correct
8 Correct 21 ms 32044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 31952 KB Output is correct
2 Correct 22 ms 31996 KB Output is correct
3 Correct 22 ms 32116 KB Output is correct
4 Correct 21 ms 31980 KB Output is correct
5 Correct 18 ms 32004 KB Output is correct
6 Correct 22 ms 32044 KB Output is correct
7 Correct 20 ms 32128 KB Output is correct
8 Correct 19 ms 32108 KB Output is correct
9 Correct 22 ms 32072 KB Output is correct
10 Correct 19 ms 32224 KB Output is correct
11 Correct 23 ms 32208 KB Output is correct
12 Correct 22 ms 32104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31972 KB Output is correct
2 Correct 22 ms 32028 KB Output is correct
3 Correct 23 ms 32080 KB Output is correct
4 Correct 24 ms 31988 KB Output is correct
5 Correct 24 ms 32084 KB Output is correct
6 Correct 21 ms 32080 KB Output is correct
7 Correct 22 ms 32040 KB Output is correct
8 Correct 21 ms 32044 KB Output is correct
9 Correct 20 ms 31952 KB Output is correct
10 Correct 22 ms 31996 KB Output is correct
11 Correct 22 ms 32116 KB Output is correct
12 Correct 21 ms 31980 KB Output is correct
13 Correct 18 ms 32004 KB Output is correct
14 Correct 22 ms 32044 KB Output is correct
15 Correct 20 ms 32128 KB Output is correct
16 Correct 19 ms 32108 KB Output is correct
17 Correct 22 ms 32072 KB Output is correct
18 Correct 19 ms 32224 KB Output is correct
19 Correct 23 ms 32208 KB Output is correct
20 Correct 22 ms 32104 KB Output is correct
21 Incorrect 21 ms 32088 KB 1st lines differ - on the 1st token, expected: '759476520', found: '770368404'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 612 ms 34844 KB Output is correct
2 Correct 856 ms 37620 KB Output is correct
3 Correct 1092 ms 37620 KB Output is correct
4 Correct 1076 ms 37724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 612 ms 34844 KB Output is correct
2 Correct 856 ms 37620 KB Output is correct
3 Correct 1092 ms 37620 KB Output is correct
4 Correct 1076 ms 37724 KB Output is correct
5 Correct 766 ms 34760 KB Output is correct
6 Correct 941 ms 37636 KB Output is correct
7 Correct 1016 ms 37624 KB Output is correct
8 Correct 778 ms 37632 KB Output is correct
9 Correct 355 ms 32220 KB Output is correct
10 Correct 908 ms 32408 KB Output is correct
11 Correct 976 ms 32412 KB Output is correct
12 Correct 851 ms 32336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 31952 KB Output is correct
2 Correct 22 ms 31996 KB Output is correct
3 Correct 22 ms 32116 KB Output is correct
4 Correct 21 ms 31980 KB Output is correct
5 Correct 18 ms 32004 KB Output is correct
6 Correct 22 ms 32044 KB Output is correct
7 Correct 20 ms 32128 KB Output is correct
8 Correct 19 ms 32108 KB Output is correct
9 Correct 22 ms 32072 KB Output is correct
10 Correct 19 ms 32224 KB Output is correct
11 Correct 23 ms 32208 KB Output is correct
12 Correct 22 ms 32104 KB Output is correct
13 Correct 612 ms 34844 KB Output is correct
14 Correct 856 ms 37620 KB Output is correct
15 Correct 1092 ms 37620 KB Output is correct
16 Correct 1076 ms 37724 KB Output is correct
17 Correct 766 ms 34760 KB Output is correct
18 Correct 941 ms 37636 KB Output is correct
19 Correct 1016 ms 37624 KB Output is correct
20 Correct 778 ms 37632 KB Output is correct
21 Correct 355 ms 32220 KB Output is correct
22 Correct 908 ms 32408 KB Output is correct
23 Correct 976 ms 32412 KB Output is correct
24 Correct 851 ms 32336 KB Output is correct
25 Correct 1084 ms 40552 KB Output is correct
26 Correct 1120 ms 40676 KB Output is correct
27 Correct 1084 ms 40776 KB Output is correct
28 Correct 974 ms 40696 KB Output is correct
29 Correct 1165 ms 51656 KB Output is correct
30 Correct 1181 ms 51680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31972 KB Output is correct
2 Correct 22 ms 32028 KB Output is correct
3 Correct 23 ms 32080 KB Output is correct
4 Correct 24 ms 31988 KB Output is correct
5 Correct 24 ms 32084 KB Output is correct
6 Correct 21 ms 32080 KB Output is correct
7 Correct 22 ms 32040 KB Output is correct
8 Correct 21 ms 32044 KB Output is correct
9 Correct 20 ms 31952 KB Output is correct
10 Correct 22 ms 31996 KB Output is correct
11 Correct 22 ms 32116 KB Output is correct
12 Correct 21 ms 31980 KB Output is correct
13 Correct 18 ms 32004 KB Output is correct
14 Correct 22 ms 32044 KB Output is correct
15 Correct 20 ms 32128 KB Output is correct
16 Correct 19 ms 32108 KB Output is correct
17 Correct 22 ms 32072 KB Output is correct
18 Correct 19 ms 32224 KB Output is correct
19 Correct 23 ms 32208 KB Output is correct
20 Correct 22 ms 32104 KB Output is correct
21 Incorrect 21 ms 32088 KB 1st lines differ - on the 1st token, expected: '759476520', found: '770368404'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31972 KB Output is correct
2 Correct 22 ms 32028 KB Output is correct
3 Correct 23 ms 32080 KB Output is correct
4 Correct 24 ms 31988 KB Output is correct
5 Correct 24 ms 32084 KB Output is correct
6 Correct 21 ms 32080 KB Output is correct
7 Correct 22 ms 32040 KB Output is correct
8 Correct 21 ms 32044 KB Output is correct
9 Correct 20 ms 31952 KB Output is correct
10 Correct 22 ms 31996 KB Output is correct
11 Correct 22 ms 32116 KB Output is correct
12 Correct 21 ms 31980 KB Output is correct
13 Correct 18 ms 32004 KB Output is correct
14 Correct 22 ms 32044 KB Output is correct
15 Correct 20 ms 32128 KB Output is correct
16 Correct 19 ms 32108 KB Output is correct
17 Correct 22 ms 32072 KB Output is correct
18 Correct 19 ms 32224 KB Output is correct
19 Correct 23 ms 32208 KB Output is correct
20 Correct 22 ms 32104 KB Output is correct
21 Incorrect 21 ms 32088 KB 1st lines differ - on the 1st token, expected: '759476520', found: '770368404'
22 Halted 0 ms 0 KB -