답안 #1085951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085951 2024-09-09T07:11:06 Z modwwe 디지털 회로 (IOI22_circuit) C++17
100 / 100
774 ms 22580 KB
#include "circuit.h"
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int2 long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while(c<'0'||c>'9')
    {
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf=1e9;
const int mod2=1e9 + 2022;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2,center;
int  i,s10,s12;
int kk;
int el=29;

vector<int> v[200001];
int2 dp[200001];
bool a[100001];
int2 dp2[200001];
int2 le[200001];
int2 ri[200001];
void dfs(int x)
{
    if(v[x].size()==0)dp[x]=1;
    else dp[x]=v[x].size();
    for(auto f:v[x])
    {
        dfs(f);
        dp[x]=dp[x]*dp[f]%mod2;
    }
}
void dfs2(int x)
{
    le[0]=1;
    if(x==1)dp2[x]=1;
    for(int i=0; i<v[x].size(); i++)
    {
        le[i+1]=le[i]*dp[v[x][i]]%mod2;
        dp2[v[x][i]]=dp2[x];
    }
    ri[v[x].size()+1]=1;
    for(int i=v[x].size()-1; i>=0; --i)
        ri[i+1]=ri[i+2]*dp[v[x][i]]%mod2;
    for(int i=0; i<v[x].size(); i++)
    { ///if(x==1) cout<<v[x][i],debug
        dp2[v[x][i]]=le[i]*ri[i+2]%mod2;
                dp2[v[x][i]]=dp2[v[x][i]]*dp2[x]%mod2;

    }
    for(auto f:v[x])
        dfs2(f);
}
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0) x+=mod2;
    return x+y;
}
struct IT
{
    int t[400001];
    int t2[400001];
    int t3[400001];
    void build(int node,int l,int r)
    {
        if(l==r)
        {
            if(a[l]==1)
                t[node]=dp2[l+n]%mod2;
            t2[node]=dp2[l+n];
            return;
        }
        int mid=l+r>>1;
        build(node<<1,l,mid);
        build(node<<1|1,mid+1,r);
        t[node]=add(t[node<<1],t[node<<1|1]);
        t2[node]=add(t2[node<<1],t2[node<<1|1]);
    }
    void ff(int x)
    {
        for(int i=x*2; i<=x*2+1; i++)
        {
            t3[i]=1-t3[i];
            t[i]=add(-t[i],t2[i]);
        }
        t3[x]=0;
    }
    void upd(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1) return;
        if(l>=l1&&r<=r1)
        {
            t3[node]=1-t3[node];
            t[node]=add(-t[node],t2[node]);
            return;
        }
        if(t3[node]!=0) ff(node);
        int mid=l+r>>1;
        upd(node<<1,l,mid,l1,r1);
        upd(node<<1|1,mid+1,r,l1,r1);
        t[node]=add(t[node<<1],t[node<<1|1]);
    }
} st;
int count_ways(int l, int r) {

        st.upd(1,1,m,l-n+1,r-n+1);
        return st.t[1];
}
void init(int N, int M, vector<int> P, vector<int> A)
{

    n=N;
    m=M;
    for(int i=1; i<=n+m; i++)
    {
        l=P[i-1];
        if(i>1)
        {
            v[l+1].pb(i);
        }
    }
    for(int i=1; i<=m; i++)
        a[i]=A[i-1];
    dp2[0]=1;
    dfs(1);
    dfs2(1);
    st.build(1,1,m);
}

/**
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
*/

Compilation message

circuit.cpp: In function 'void dfs2(int)':
circuit.cpp:89:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int i=0; i<v[x].size(); i++)
      |                  ~^~~~~~~~~~~~
circuit.cpp:97:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i=0; i<v[x].size(); i++)
      |                  ~^~~~~~~~~~~~
circuit.cpp: In member function 'void IT::build(int, int, int)':
circuit.cpp:126:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  126 |         int mid=l+r>>1;
      |                 ~^~
circuit.cpp: In member function 'void IT::upd(int, int, int, int, int)':
circuit.cpp:151:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  151 |         int mid=l+r>>1;
      |                 ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4988 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 4 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5232 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4988 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 4 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 2 ms 5208 KB Output is correct
20 Correct 2 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 2 ms 5232 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 2 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 2 ms 5148 KB Output is correct
32 Correct 2 ms 5208 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5208 KB Output is correct
35 Correct 2 ms 5144 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 2 ms 5208 KB Output is correct
38 Correct 2 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5124 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 430 ms 8536 KB Output is correct
2 Correct 663 ms 11864 KB Output is correct
3 Correct 689 ms 11864 KB Output is correct
4 Correct 647 ms 11608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 430 ms 8536 KB Output is correct
2 Correct 663 ms 11864 KB Output is correct
3 Correct 689 ms 11864 KB Output is correct
4 Correct 647 ms 11608 KB Output is correct
5 Correct 538 ms 8536 KB Output is correct
6 Correct 678 ms 11856 KB Output is correct
7 Correct 706 ms 11808 KB Output is correct
8 Correct 590 ms 11864 KB Output is correct
9 Correct 302 ms 5208 KB Output is correct
10 Correct 601 ms 5460 KB Output is correct
11 Correct 652 ms 5464 KB Output is correct
12 Correct 631 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4988 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 4 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 430 ms 8536 KB Output is correct
14 Correct 663 ms 11864 KB Output is correct
15 Correct 689 ms 11864 KB Output is correct
16 Correct 647 ms 11608 KB Output is correct
17 Correct 538 ms 8536 KB Output is correct
18 Correct 678 ms 11856 KB Output is correct
19 Correct 706 ms 11808 KB Output is correct
20 Correct 590 ms 11864 KB Output is correct
21 Correct 302 ms 5208 KB Output is correct
22 Correct 601 ms 5460 KB Output is correct
23 Correct 652 ms 5464 KB Output is correct
24 Correct 631 ms 5464 KB Output is correct
25 Correct 695 ms 15696 KB Output is correct
26 Correct 741 ms 15896 KB Output is correct
27 Correct 713 ms 15768 KB Output is correct
28 Correct 544 ms 15696 KB Output is correct
29 Correct 729 ms 20560 KB Output is correct
30 Correct 709 ms 20560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5232 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4988 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 4 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 2 ms 5208 KB Output is correct
20 Correct 2 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 2 ms 5232 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 2 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 2 ms 5148 KB Output is correct
32 Correct 2 ms 5208 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5208 KB Output is correct
35 Correct 2 ms 5144 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 2 ms 5208 KB Output is correct
38 Correct 2 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5124 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 498 ms 5464 KB Output is correct
44 Correct 608 ms 5464 KB Output is correct
45 Correct 647 ms 5464 KB Output is correct
46 Correct 593 ms 5720 KB Output is correct
47 Correct 662 ms 5864 KB Output is correct
48 Correct 662 ms 5720 KB Output is correct
49 Correct 610 ms 5720 KB Output is correct
50 Correct 591 ms 5720 KB Output is correct
51 Correct 629 ms 5464 KB Output is correct
52 Correct 672 ms 5660 KB Output is correct
53 Correct 590 ms 5464 KB Output is correct
54 Correct 615 ms 5720 KB Output is correct
55 Correct 687 ms 5464 KB Output is correct
56 Correct 688 ms 5464 KB Output is correct
57 Correct 654 ms 5464 KB Output is correct
58 Correct 650 ms 5976 KB Output is correct
59 Correct 679 ms 6156 KB Output is correct
60 Correct 575 ms 6108 KB Output is correct
61 Correct 629 ms 5464 KB Output is correct
62 Correct 665 ms 5464 KB Output is correct
63 Correct 625 ms 5464 KB Output is correct
64 Correct 628 ms 5560 KB Output is correct
65 Correct 305 ms 5208 KB Output is correct
66 Correct 686 ms 5464 KB Output is correct
67 Correct 624 ms 5464 KB Output is correct
68 Correct 583 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5232 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4988 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 4 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 2 ms 5208 KB Output is correct
20 Correct 2 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 2 ms 5232 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 2 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 2 ms 5148 KB Output is correct
32 Correct 2 ms 5208 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5208 KB Output is correct
35 Correct 2 ms 5144 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 2 ms 5208 KB Output is correct
38 Correct 2 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5124 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 430 ms 8536 KB Output is correct
44 Correct 663 ms 11864 KB Output is correct
45 Correct 689 ms 11864 KB Output is correct
46 Correct 647 ms 11608 KB Output is correct
47 Correct 538 ms 8536 KB Output is correct
48 Correct 678 ms 11856 KB Output is correct
49 Correct 706 ms 11808 KB Output is correct
50 Correct 590 ms 11864 KB Output is correct
51 Correct 302 ms 5208 KB Output is correct
52 Correct 601 ms 5460 KB Output is correct
53 Correct 652 ms 5464 KB Output is correct
54 Correct 631 ms 5464 KB Output is correct
55 Correct 695 ms 15696 KB Output is correct
56 Correct 741 ms 15896 KB Output is correct
57 Correct 713 ms 15768 KB Output is correct
58 Correct 544 ms 15696 KB Output is correct
59 Correct 729 ms 20560 KB Output is correct
60 Correct 709 ms 20560 KB Output is correct
61 Correct 498 ms 5464 KB Output is correct
62 Correct 608 ms 5464 KB Output is correct
63 Correct 647 ms 5464 KB Output is correct
64 Correct 593 ms 5720 KB Output is correct
65 Correct 662 ms 5864 KB Output is correct
66 Correct 662 ms 5720 KB Output is correct
67 Correct 610 ms 5720 KB Output is correct
68 Correct 591 ms 5720 KB Output is correct
69 Correct 629 ms 5464 KB Output is correct
70 Correct 672 ms 5660 KB Output is correct
71 Correct 590 ms 5464 KB Output is correct
72 Correct 615 ms 5720 KB Output is correct
73 Correct 687 ms 5464 KB Output is correct
74 Correct 688 ms 5464 KB Output is correct
75 Correct 654 ms 5464 KB Output is correct
76 Correct 650 ms 5976 KB Output is correct
77 Correct 679 ms 6156 KB Output is correct
78 Correct 575 ms 6108 KB Output is correct
79 Correct 629 ms 5464 KB Output is correct
80 Correct 665 ms 5464 KB Output is correct
81 Correct 625 ms 5464 KB Output is correct
82 Correct 628 ms 5560 KB Output is correct
83 Correct 305 ms 5208 KB Output is correct
84 Correct 686 ms 5464 KB Output is correct
85 Correct 624 ms 5464 KB Output is correct
86 Correct 583 ms 5464 KB Output is correct
87 Correct 2 ms 4952 KB Output is correct
88 Correct 464 ms 15084 KB Output is correct
89 Correct 731 ms 11940 KB Output is correct
90 Correct 686 ms 11600 KB Output is correct
91 Correct 669 ms 15952 KB Output is correct
92 Correct 767 ms 16012 KB Output is correct
93 Correct 732 ms 15884 KB Output is correct
94 Correct 774 ms 15952 KB Output is correct
95 Correct 695 ms 16012 KB Output is correct
96 Correct 636 ms 12496 KB Output is correct
97 Correct 690 ms 12768 KB Output is correct
98 Correct 598 ms 15184 KB Output is correct
99 Correct 750 ms 15772 KB Output is correct
100 Correct 698 ms 13228 KB Output is correct
101 Correct 706 ms 12464 KB Output is correct
102 Correct 709 ms 11324 KB Output is correct
103 Correct 753 ms 20560 KB Output is correct
104 Correct 693 ms 22580 KB Output is correct
105 Correct 661 ms 22480 KB Output is correct
106 Correct 691 ms 12692 KB Output is correct
107 Correct 722 ms 12152 KB Output is correct
108 Correct 747 ms 11804 KB Output is correct
109 Correct 711 ms 11268 KB Output is correct