답안 #1110084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110084 2024-11-08T16:45:46 Z ASN49K 디지털 회로 (IOI22_circuit) C++17
34 / 100
3000 ms 17992 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

const int N=100'000,mod=1e9+2022;
int add(int x,int y)
{
    return (x+y)%mod;
}
void add_self(int& x,int y)
{
    x+=y;
    if(x>=mod)
    {
        x-=mod;
    }
    if(x<0)
    {
        x+=mod;
    }
}
int prod(int x,int y)
{
    return (1LL*x*y)%mod;
}
int n,m;
vector<int>g[2*N],a;
bool lazy[2*N];
int dp[2*N][2];
bool test_mare;


void push_down(int nod)
{
    if(lazy[nod])
    {
        swap(dp[2*nod+1][0] , dp[2*nod+1][1]);
        swap(dp[2*nod+2][0] , dp[2*nod+2][1]);
        lazy[2*nod+1]^=true;
        lazy[2*nod+2]^=true;
        lazy[nod]=false;
    }
}
void recalc(int nod)
{
    int l=2*nod+1,r=2*nod+2;
    //dp[nod][0]=dp[nod][1]=0;
    dp[nod][1]=add(add(prod(dp[l][0],dp[r][1]) , prod(dp[l][1],dp[r][0])) , prod(2,prod(dp[l][1],dp[r][1])));
    dp[nod][0]=add(add(prod(dp[l][0],dp[r][1]) , prod(dp[l][1],dp[r][0])) , prod(2,prod(dp[l][0],dp[r][0])));
}
void update(int nod,int st,int dr,int l,int r)
{
    if(st>r || dr<l)
    {
        return;
    }
    if(l<=st && dr<=r)
    {
        lazy[nod]^=true;
        swap(dp[nod][0] , dp[nod][1]);
        return;
    }
    int m=(st+dr)/2;
    push_down(nod);
    update(2*nod+1,st,m,l,r);
    update(2*nod+2,m+1,dr,l,r);
    recalc(nod);
}
void init(int nn, int mm, std::vector<int> pp, std::vector<int> init_a)
{
    n=nn;
    m=mm;
    //schimbat n mare
    test_mare=(__builtin_popcount(m)==1 && n==m-1);
    for(int i=1;i<n+m;i++)
    {
        test_mare&=(pp[i]==(i-1)/2);
    }
    assert(test_mare  || max(n,m)<=5000);
    if(test_mare)
    {
        for(int i=0;i<m;i++)
        {
            dp[n+i][0]=(init_a[i]==0);
            dp[n+i][1]=(init_a[i]==1);
        }

        for(int i=n-1;i>=0;i--)
        {
            recalc(i);
        }
        return;
    }
    for(int i=1;i<n+m;i++)
    {
        g[pp[i]].push_back(i);
    }
    a=init_a;
}

void dfs(int nod)
{
    for(auto &c:g[nod])
    {
        dfs(c);
    }
    int sz=(int)g[nod].size();
    if(g[nod].empty())
    {
        dp[nod][0]=(a[nod-n]==0);
        dp[nod][1]=(a[nod-n]==1);
        return;
    }
    vector<int>choose(sz+1,0);
    choose[0]=1;
    for(auto &c:g[nod])
    {
        for(int i=sz;i>=0;i--)
        {
            choose[i]=prod(choose[i] , dp[c][0]);
            if(i>0)
            {
                add_self(choose[i] , prod(choose[i-1] , dp[c][1]));
            }
        }
    }
    dp[nod][0]=dp[nod][1]=0;
    for(int i=1;i<=sz;i++)
    {
        add_self(dp[nod][0] , prod(choose[i],sz-i));
        add_self(dp[nod][1] , prod(choose[i],i));
    }
    add_self(dp[nod][0],prod(choose[0],sz));
}
int count_ways(int l, int r)
{
    l-=n;
    r-=n;
    if(test_mare)
    {
        if(l<=r)
        {
            update(0,0,m-1,l,r);
        }
    }
    else
    {
        for(int i=l;i<=r;i++)
        {
            a[i]^=1;
        }
        dfs(0);
    }

    return dp[0][1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 24 ms 6904 KB Output is correct
4 Correct 19 ms 6736 KB Output is correct
5 Correct 19 ms 6736 KB Output is correct
6 Correct 19 ms 6736 KB Output is correct
7 Correct 19 ms 6736 KB Output is correct
8 Correct 19 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 3 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 3 ms 6736 KB Output is correct
8 Correct 3 ms 6736 KB Output is correct
9 Correct 3 ms 6736 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 3 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 24 ms 6904 KB Output is correct
4 Correct 19 ms 6736 KB Output is correct
5 Correct 19 ms 6736 KB Output is correct
6 Correct 19 ms 6736 KB Output is correct
7 Correct 19 ms 6736 KB Output is correct
8 Correct 19 ms 6736 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 3 ms 6736 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 3 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 3 ms 6736 KB Output is correct
19 Correct 3 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 2 ms 6736 KB Output is correct
23 Correct 3 ms 6752 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 3 ms 6736 KB Output is correct
27 Correct 3 ms 6736 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 19 ms 6908 KB Output is correct
30 Correct 18 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 3 ms 6736 KB Output is correct
33 Correct 3 ms 6736 KB Output is correct
34 Correct 3 ms 6736 KB Output is correct
35 Correct 6 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 22 ms 6736 KB Output is correct
38 Correct 19 ms 6736 KB Output is correct
39 Correct 2 ms 6736 KB Output is correct
40 Correct 2 ms 6736 KB Output is correct
41 Correct 2 ms 6736 KB Output is correct
42 Correct 2 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1390 ms 7504 KB Output is correct
2 Correct 2001 ms 8276 KB Output is correct
3 Correct 1900 ms 8272 KB Output is correct
4 Correct 1992 ms 8272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1390 ms 7504 KB Output is correct
2 Correct 2001 ms 8276 KB Output is correct
3 Correct 1900 ms 8272 KB Output is correct
4 Correct 1992 ms 8272 KB Output is correct
5 Correct 1669 ms 7504 KB Output is correct
6 Correct 2118 ms 8272 KB Output is correct
7 Correct 1985 ms 8272 KB Output is correct
8 Correct 2025 ms 8272 KB Output is correct
9 Correct 982 ms 6736 KB Output is correct
10 Correct 1990 ms 6736 KB Output is correct
11 Correct 2054 ms 6736 KB Output is correct
12 Correct 2001 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 3 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 3 ms 6736 KB Output is correct
8 Correct 3 ms 6736 KB Output is correct
9 Correct 3 ms 6736 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 3 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 1390 ms 7504 KB Output is correct
14 Correct 2001 ms 8276 KB Output is correct
15 Correct 1900 ms 8272 KB Output is correct
16 Correct 1992 ms 8272 KB Output is correct
17 Correct 1669 ms 7504 KB Output is correct
18 Correct 2118 ms 8272 KB Output is correct
19 Correct 1985 ms 8272 KB Output is correct
20 Correct 2025 ms 8272 KB Output is correct
21 Correct 982 ms 6736 KB Output is correct
22 Correct 1990 ms 6736 KB Output is correct
23 Correct 2054 ms 6736 KB Output is correct
24 Correct 2001 ms 6736 KB Output is correct
25 Runtime error 45 ms 17992 KB Execution killed with signal 6
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 24 ms 6904 KB Output is correct
4 Correct 19 ms 6736 KB Output is correct
5 Correct 19 ms 6736 KB Output is correct
6 Correct 19 ms 6736 KB Output is correct
7 Correct 19 ms 6736 KB Output is correct
8 Correct 19 ms 6736 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 3 ms 6736 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 3 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 3 ms 6736 KB Output is correct
19 Correct 3 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 2 ms 6736 KB Output is correct
23 Correct 3 ms 6752 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 3 ms 6736 KB Output is correct
27 Correct 3 ms 6736 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 19 ms 6908 KB Output is correct
30 Correct 18 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 3 ms 6736 KB Output is correct
33 Correct 3 ms 6736 KB Output is correct
34 Correct 3 ms 6736 KB Output is correct
35 Correct 6 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 22 ms 6736 KB Output is correct
38 Correct 19 ms 6736 KB Output is correct
39 Correct 2 ms 6736 KB Output is correct
40 Correct 2 ms 6736 KB Output is correct
41 Correct 2 ms 6736 KB Output is correct
42 Correct 2 ms 6736 KB Output is correct
43 Execution timed out 3040 ms 6736 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 24 ms 6904 KB Output is correct
4 Correct 19 ms 6736 KB Output is correct
5 Correct 19 ms 6736 KB Output is correct
6 Correct 19 ms 6736 KB Output is correct
7 Correct 19 ms 6736 KB Output is correct
8 Correct 19 ms 6736 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 3 ms 6736 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 3 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 3 ms 6736 KB Output is correct
19 Correct 3 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 2 ms 6736 KB Output is correct
23 Correct 3 ms 6752 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 3 ms 6736 KB Output is correct
27 Correct 3 ms 6736 KB Output is correct
28 Correct 3 ms 6736 KB Output is correct
29 Correct 19 ms 6908 KB Output is correct
30 Correct 18 ms 6736 KB Output is correct
31 Correct 2 ms 6736 KB Output is correct
32 Correct 3 ms 6736 KB Output is correct
33 Correct 3 ms 6736 KB Output is correct
34 Correct 3 ms 6736 KB Output is correct
35 Correct 6 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 22 ms 6736 KB Output is correct
38 Correct 19 ms 6736 KB Output is correct
39 Correct 2 ms 6736 KB Output is correct
40 Correct 2 ms 6736 KB Output is correct
41 Correct 2 ms 6736 KB Output is correct
42 Correct 2 ms 6736 KB Output is correct
43 Correct 1390 ms 7504 KB Output is correct
44 Correct 2001 ms 8276 KB Output is correct
45 Correct 1900 ms 8272 KB Output is correct
46 Correct 1992 ms 8272 KB Output is correct
47 Correct 1669 ms 7504 KB Output is correct
48 Correct 2118 ms 8272 KB Output is correct
49 Correct 1985 ms 8272 KB Output is correct
50 Correct 2025 ms 8272 KB Output is correct
51 Correct 982 ms 6736 KB Output is correct
52 Correct 1990 ms 6736 KB Output is correct
53 Correct 2054 ms 6736 KB Output is correct
54 Correct 2001 ms 6736 KB Output is correct
55 Runtime error 45 ms 17992 KB Execution killed with signal 6
56 Halted 0 ms 0 KB -