Submission #636056

# Submission time Handle Problem Language Result Execution time Memory
636056 2022-08-27T20:28:55 Z k_balint31415 Digital Circuit (IOI22_circuit) C++17
52 / 100
1172 ms 38136 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000002022; //2*223*2242157
const ll mod=2242157;
const int c=2e5+5;

struct num{
    ll _2,_223,_rest;
};

ll power(ll a, ll b, ll m){
    ll res=1;
    while(b){
        if(b&1){
            res*=a;
            res%=m;
        }
        a*=a; a%=m; b>>=1;
    }
    return res;
}

num div(num a, num b){
    num res;
    res._2=a._2-b._2;
    res._223=a._223-b._223;
    res._rest=a._rest*power(b._rest,mod-2,mod)%mod;
    return res;
}

num mul(num a, num b){
    num res;
    res._2=a._2+b._2;
    res._223=a._223+b._223;
    res._rest=a._rest*b._rest%mod;
    return res;
}

num valt(ll a){
    num res;
    res._2=0;
    while(a%2==0){
        ++res._2; a/=2;
    }
    res._223=0;
    while(a%223==0){
        ++res._223; a/=223;
    }
    res._rest=a%mod;
    return res;
}

ll vissza(num a){
    return power(2,a._2,MOD)*power(223,a._223,MOD)%MOD*a._rest%MOD;
}

int n,m;
vector<int> adj[c];
num db[c];
num arr[c];
num all;
bool szin[c];
int _N,_M;

void dfs(int v, int p, num cur){
    db[v]=cur;
    cur=div(cur,arr[v]);
    for(int x: adj[v]){
        if(x != p){
            dfs(x,v,cur);
        }
    }
}

pair<ll,ll> add(pair<ll,ll> a, pair<ll,ll> b){
    return make_pair((a.first+b.first)%MOD,(a.second+b.second)%MOD);
}

pair<ll,ll> tree[4*c];
bool lazy[4*c];

void build(int v, int l, int r){
    if(l==r){
        if(!szin[l+_N]) tree[v]=make_pair(vissza(db[l+_N]),0);
        else tree[v]=make_pair(0,vissza(db[l+_N]));
        return;
    }

    int mid=l+r>>1;
    build(2*v,l,mid); build(2*v+1,mid+1,r);
    tree[v]=add(tree[2*v],tree[2*v+1]);
}

void update(int v, int l, int r, int x, int y){
    if(lazy[v]){
        swap(tree[v].first,tree[v].second);
        if(l != r){
            lazy[2*v]=lazy[2*v]^1;
            lazy[2*v+1]=lazy[2*v+1]^1;
        }
        lazy[v]=0;
    }

    if(l>r || l>y || x>r || x>y) return;

    if(x<=l && r<=y){
        swap(tree[v].first,tree[v].second);
        if(l != r){
            lazy[2*v]=lazy[2*v]^1;
            lazy[2*v+1]=lazy[2*v+1]^1;
        }
        return;
    }

    int mid=l+r>>1;
    update(2*v,l,mid,x,y); update(2*v+1,mid+1,r,x,y);
    tree[v]=add(tree[2*v],tree[2*v+1]);
}

void init(int N, int M, vector<int> P, vector<int> A){
    int n=N+M;
    _N=N; _M=M;
    all._2=0; all._223=0; all._rest=1;
    for(int i=1;i<=n;i++){
        if(i>N) szin[i]=A[i-N-1];
        if(i != 1){
            adj[i].push_back(P[i-1]+1);
            adj[P[i-1]+1].push_back(i);
        }
    }

    for(int i=1;i<=n;i++){
        if(i==1){
            arr[i]=valt(adj[i].size());
            all=mul(all,arr[i]);
        }
        else if(i<=N){
            arr[i]=valt(adj[i].size()-1);
            all=mul(all,arr[i]);
        }
        else arr[i]=valt(1);
    }

    dfs(1,0,all);

    build(1,1,M);
}

int count_ways(int L, int R){
    L=L-_N+1; R=R-_N+1;
    update(1,1,_M,L,R);
    return tree[1].second;
}

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

Compilation message

circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:90:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |     int mid=l+r>>1;
      |             ~^~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:116:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  116 |     int mid=l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5128 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5116 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5128 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5044 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5116 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Incorrect 4 ms 5200 KB 1st lines differ - on the 1st token, expected: '759476520', found: '844678486'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 362 ms 11904 KB Output is correct
2 Correct 851 ms 18944 KB Output is correct
3 Correct 752 ms 18912 KB Output is correct
4 Correct 946 ms 18872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 11904 KB Output is correct
2 Correct 851 ms 18944 KB Output is correct
3 Correct 752 ms 18912 KB Output is correct
4 Correct 946 ms 18872 KB Output is correct
5 Correct 710 ms 11900 KB Output is correct
6 Correct 872 ms 18940 KB Output is correct
7 Correct 972 ms 18888 KB Output is correct
8 Correct 894 ms 18944 KB Output is correct
9 Correct 419 ms 5456 KB Output is correct
10 Correct 644 ms 5812 KB Output is correct
11 Correct 789 ms 5872 KB Output is correct
12 Correct 798 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5116 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
9 Correct 3 ms 5200 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
13 Correct 362 ms 11904 KB Output is correct
14 Correct 851 ms 18944 KB Output is correct
15 Correct 752 ms 18912 KB Output is correct
16 Correct 946 ms 18872 KB Output is correct
17 Correct 710 ms 11900 KB Output is correct
18 Correct 872 ms 18940 KB Output is correct
19 Correct 972 ms 18888 KB Output is correct
20 Correct 894 ms 18944 KB Output is correct
21 Correct 419 ms 5456 KB Output is correct
22 Correct 644 ms 5812 KB Output is correct
23 Correct 789 ms 5872 KB Output is correct
24 Correct 798 ms 5840 KB Output is correct
25 Correct 1054 ms 26888 KB Output is correct
26 Correct 1172 ms 27160 KB Output is correct
27 Correct 927 ms 27196 KB Output is correct
28 Correct 768 ms 27128 KB Output is correct
29 Correct 1060 ms 38136 KB Output is correct
30 Correct 963 ms 38076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5128 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5044 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5116 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Incorrect 4 ms 5200 KB 1st lines differ - on the 1st token, expected: '759476520', found: '844678486'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5128 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5044 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5116 KB Output is correct
16 Correct 3 ms 5200 KB Output is correct
17 Correct 3 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Incorrect 4 ms 5200 KB 1st lines differ - on the 1st token, expected: '759476520', found: '844678486'
22 Halted 0 ms 0 KB -