답안 #640373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640373 2022-09-14T11:45:32 Z arnold518 디지털 회로 (IOI22_circuit) C++17
22 / 100
3000 ms 30920 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3e5;
const ll MOD = 1e9+2022;

int N, M;
vector<int> adj[MAXN+10];
ll phi[MAXN+10];
vector<ll> PV[MAXN+10], SV[MAXN+10];
int S[MAXN+10];
ll A[MAXN+10];

void dfs(int now)
{
    if(adj[now].empty())
    {
        phi[now]=1;
        return;
    }
    phi[now]=adj[now].size();
    for(auto nxt : adj[now])
    {
        dfs(nxt);
        PV[now].push_back(phi[nxt]);
        SV[now].push_back(phi[nxt]);
        phi[now]=phi[now]*phi[nxt]%MOD;
    }
    for(int i=1; i<PV[now].size(); i++) PV[now][i]=PV[now][i-1]*PV[now][i]%MOD;
    for(int i=SV[now].size()-2; i>=0; i--) SV[now][i]=SV[now][i+1]*SV[now][i]%MOD;
}

void dfs2(int now, ll val)
{
    if(adj[now].empty())
    {
        A[now]=val;
        return;
    }
    for(int i=0; i<adj[now].size(); i++)
    {
        int nxt=adj[now][i];
        ll t=1;
        if(i-1>=0) t=t*PV[now][i-1]%MOD;
        if(i+1<SV[now].size()) t=t*SV[now][i+1]%MOD;
        dfs2(nxt, val*t%MOD);
    }
}

ll ans=0;

void init(int _N, int _M, vector<int> _P, vector<int> _Q)
{
    N=_N; M=_M;
    for(int i=1; i<N+M; i++) adj[_P[i]].push_back(i);
    for(int i=N; i<N+M; i++) S[i]=_Q[i-N];

    dfs(0);
    dfs2(0, 1);
    
    for(int i=N; i<N+M; i++) if(S[i]) ans=(ans+A[i])%MOD;
    //for(int i=N; i<N+M; i++) printf("%lld ", A[i]); printf("\n");
}

int count_ways(int L, int R)
{
    for(int i=L; i<=R; i++)
    {
        if(S[i]) ans=(ans-A[i])%MOD;
        else ans=(ans+A[i])%MOD;
        if(ans<0) ans+=MOD;
        S[i]=!S[i];
    }
    return ans;
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=1; i<PV[now].size(); i++) PV[now][i]=PV[now][i-1]*PV[now][i]%MOD;
      |                  ~^~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, ll)':
circuit.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0; i<adj[now].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~
circuit.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(i+1<SV[now].size()) t=t*SV[now][i+1]%MOD;
      |            ~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21456 KB Output is correct
2 Correct 12 ms 21456 KB Output is correct
3 Correct 13 ms 21456 KB Output is correct
4 Correct 13 ms 21472 KB Output is correct
5 Correct 13 ms 21408 KB Output is correct
6 Correct 12 ms 21424 KB Output is correct
7 Correct 14 ms 21456 KB Output is correct
8 Correct 12 ms 21436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 21456 KB Output is correct
2 Correct 12 ms 21456 KB Output is correct
3 Correct 13 ms 21456 KB Output is correct
4 Correct 12 ms 21456 KB Output is correct
5 Correct 12 ms 21456 KB Output is correct
6 Correct 12 ms 21456 KB Output is correct
7 Correct 12 ms 21584 KB Output is correct
8 Correct 12 ms 21584 KB Output is correct
9 Correct 14 ms 21504 KB Output is correct
10 Correct 16 ms 21604 KB Output is correct
11 Correct 12 ms 21676 KB Output is correct
12 Correct 12 ms 21544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21456 KB Output is correct
2 Correct 12 ms 21456 KB Output is correct
3 Correct 13 ms 21456 KB Output is correct
4 Correct 13 ms 21472 KB Output is correct
5 Correct 13 ms 21408 KB Output is correct
6 Correct 12 ms 21424 KB Output is correct
7 Correct 14 ms 21456 KB Output is correct
8 Correct 12 ms 21436 KB Output is correct
9 Correct 15 ms 21456 KB Output is correct
10 Correct 12 ms 21456 KB Output is correct
11 Correct 13 ms 21456 KB Output is correct
12 Correct 12 ms 21456 KB Output is correct
13 Correct 12 ms 21456 KB Output is correct
14 Correct 12 ms 21456 KB Output is correct
15 Correct 12 ms 21584 KB Output is correct
16 Correct 12 ms 21584 KB Output is correct
17 Correct 14 ms 21504 KB Output is correct
18 Correct 16 ms 21604 KB Output is correct
19 Correct 12 ms 21676 KB Output is correct
20 Correct 12 ms 21544 KB Output is correct
21 Correct 13 ms 21488 KB Output is correct
22 Correct 15 ms 21464 KB Output is correct
23 Correct 12 ms 21456 KB Output is correct
24 Correct 13 ms 21512 KB Output is correct
25 Correct 12 ms 21584 KB Output is correct
26 Correct 13 ms 21584 KB Output is correct
27 Correct 12 ms 21584 KB Output is correct
28 Correct 15 ms 21588 KB Output is correct
29 Correct 13 ms 21484 KB Output is correct
30 Correct 13 ms 21408 KB Output is correct
31 Correct 13 ms 21584 KB Output is correct
32 Correct 12 ms 21584 KB Output is correct
33 Correct 14 ms 21524 KB Output is correct
34 Correct 12 ms 21456 KB Output is correct
35 Correct 12 ms 21376 KB Output is correct
36 Correct 12 ms 21584 KB Output is correct
37 Correct 12 ms 21656 KB Output is correct
38 Correct 12 ms 21712 KB Output is correct
39 Correct 12 ms 21456 KB Output is correct
40 Correct 12 ms 21476 KB Output is correct
41 Correct 13 ms 21456 KB Output is correct
42 Correct 12 ms 21456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 655 ms 26184 KB Output is correct
2 Correct 813 ms 30908 KB Output is correct
3 Correct 755 ms 30920 KB Output is correct
4 Correct 801 ms 30908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 655 ms 26184 KB Output is correct
2 Correct 813 ms 30908 KB Output is correct
3 Correct 755 ms 30920 KB Output is correct
4 Correct 801 ms 30908 KB Output is correct
5 Execution timed out 3042 ms 26188 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 21456 KB Output is correct
2 Correct 12 ms 21456 KB Output is correct
3 Correct 13 ms 21456 KB Output is correct
4 Correct 12 ms 21456 KB Output is correct
5 Correct 12 ms 21456 KB Output is correct
6 Correct 12 ms 21456 KB Output is correct
7 Correct 12 ms 21584 KB Output is correct
8 Correct 12 ms 21584 KB Output is correct
9 Correct 14 ms 21504 KB Output is correct
10 Correct 16 ms 21604 KB Output is correct
11 Correct 12 ms 21676 KB Output is correct
12 Correct 12 ms 21544 KB Output is correct
13 Correct 655 ms 26184 KB Output is correct
14 Correct 813 ms 30908 KB Output is correct
15 Correct 755 ms 30920 KB Output is correct
16 Correct 801 ms 30908 KB Output is correct
17 Execution timed out 3042 ms 26188 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21456 KB Output is correct
2 Correct 12 ms 21456 KB Output is correct
3 Correct 13 ms 21456 KB Output is correct
4 Correct 13 ms 21472 KB Output is correct
5 Correct 13 ms 21408 KB Output is correct
6 Correct 12 ms 21424 KB Output is correct
7 Correct 14 ms 21456 KB Output is correct
8 Correct 12 ms 21436 KB Output is correct
9 Correct 15 ms 21456 KB Output is correct
10 Correct 12 ms 21456 KB Output is correct
11 Correct 13 ms 21456 KB Output is correct
12 Correct 12 ms 21456 KB Output is correct
13 Correct 12 ms 21456 KB Output is correct
14 Correct 12 ms 21456 KB Output is correct
15 Correct 12 ms 21584 KB Output is correct
16 Correct 12 ms 21584 KB Output is correct
17 Correct 14 ms 21504 KB Output is correct
18 Correct 16 ms 21604 KB Output is correct
19 Correct 12 ms 21676 KB Output is correct
20 Correct 12 ms 21544 KB Output is correct
21 Correct 13 ms 21488 KB Output is correct
22 Correct 15 ms 21464 KB Output is correct
23 Correct 12 ms 21456 KB Output is correct
24 Correct 13 ms 21512 KB Output is correct
25 Correct 12 ms 21584 KB Output is correct
26 Correct 13 ms 21584 KB Output is correct
27 Correct 12 ms 21584 KB Output is correct
28 Correct 15 ms 21588 KB Output is correct
29 Correct 13 ms 21484 KB Output is correct
30 Correct 13 ms 21408 KB Output is correct
31 Correct 13 ms 21584 KB Output is correct
32 Correct 12 ms 21584 KB Output is correct
33 Correct 14 ms 21524 KB Output is correct
34 Correct 12 ms 21456 KB Output is correct
35 Correct 12 ms 21376 KB Output is correct
36 Correct 12 ms 21584 KB Output is correct
37 Correct 12 ms 21656 KB Output is correct
38 Correct 12 ms 21712 KB Output is correct
39 Correct 12 ms 21456 KB Output is correct
40 Correct 12 ms 21476 KB Output is correct
41 Correct 13 ms 21456 KB Output is correct
42 Correct 12 ms 21456 KB Output is correct
43 Correct 855 ms 21840 KB Output is correct
44 Correct 1255 ms 21968 KB Output is correct
45 Correct 1297 ms 21840 KB Output is correct
46 Correct 698 ms 22224 KB Output is correct
47 Correct 1589 ms 22224 KB Output is correct
48 Correct 1755 ms 22224 KB Output is correct
49 Correct 1521 ms 22224 KB Output is correct
50 Correct 2858 ms 22224 KB Output is correct
51 Execution timed out 3033 ms 21712 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21456 KB Output is correct
2 Correct 12 ms 21456 KB Output is correct
3 Correct 13 ms 21456 KB Output is correct
4 Correct 13 ms 21472 KB Output is correct
5 Correct 13 ms 21408 KB Output is correct
6 Correct 12 ms 21424 KB Output is correct
7 Correct 14 ms 21456 KB Output is correct
8 Correct 12 ms 21436 KB Output is correct
9 Correct 15 ms 21456 KB Output is correct
10 Correct 12 ms 21456 KB Output is correct
11 Correct 13 ms 21456 KB Output is correct
12 Correct 12 ms 21456 KB Output is correct
13 Correct 12 ms 21456 KB Output is correct
14 Correct 12 ms 21456 KB Output is correct
15 Correct 12 ms 21584 KB Output is correct
16 Correct 12 ms 21584 KB Output is correct
17 Correct 14 ms 21504 KB Output is correct
18 Correct 16 ms 21604 KB Output is correct
19 Correct 12 ms 21676 KB Output is correct
20 Correct 12 ms 21544 KB Output is correct
21 Correct 13 ms 21488 KB Output is correct
22 Correct 15 ms 21464 KB Output is correct
23 Correct 12 ms 21456 KB Output is correct
24 Correct 13 ms 21512 KB Output is correct
25 Correct 12 ms 21584 KB Output is correct
26 Correct 13 ms 21584 KB Output is correct
27 Correct 12 ms 21584 KB Output is correct
28 Correct 15 ms 21588 KB Output is correct
29 Correct 13 ms 21484 KB Output is correct
30 Correct 13 ms 21408 KB Output is correct
31 Correct 13 ms 21584 KB Output is correct
32 Correct 12 ms 21584 KB Output is correct
33 Correct 14 ms 21524 KB Output is correct
34 Correct 12 ms 21456 KB Output is correct
35 Correct 12 ms 21376 KB Output is correct
36 Correct 12 ms 21584 KB Output is correct
37 Correct 12 ms 21656 KB Output is correct
38 Correct 12 ms 21712 KB Output is correct
39 Correct 12 ms 21456 KB Output is correct
40 Correct 12 ms 21476 KB Output is correct
41 Correct 13 ms 21456 KB Output is correct
42 Correct 12 ms 21456 KB Output is correct
43 Correct 655 ms 26184 KB Output is correct
44 Correct 813 ms 30908 KB Output is correct
45 Correct 755 ms 30920 KB Output is correct
46 Correct 801 ms 30908 KB Output is correct
47 Execution timed out 3042 ms 26188 KB Time limit exceeded
48 Halted 0 ms 0 KB -