답안 #1079653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079653 2024-08-28T20:09:06 Z kl0989e 디지털 회로 (IOI22_circuit) C++17
100 / 100
820 ms 39856 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()

const int maxn=2e5+10;
const int maxm=1e5+10;
const int mod=1000002022;

int n,m;
vector<vi> graph(maxn);
vl mul(maxn,1);
vl vals(maxm,0);

void dfs(int cur) {
    mul[cur]=max(1,(int)graph[cur].size());
    for (auto to:graph[cur]) {
        dfs(to);
        mul[cur]=(mul[cur]*mul[to])%mod;
    }
}

void dfs2(int cur, ll mult=1) {
    if (graph[cur].size()==0) {
        vals[cur-n]=mult;
        return;
    }
    vl pref(graph[cur].size()+1,1),suff(graph[cur].size()+1,1);
    for (int i=0; i<graph[cur].size(); i++) {
        pref[i+1]=mul[graph[cur][i]]*pref[i]%mod;
        suff[graph[cur].size()-i-1]=mul[graph[cur][graph[cur].size()-i-1]]*suff[graph[cur].size()-i]%mod;
    }
    for (int i=0; i<graph[cur].size(); i++) {
        dfs2(graph[cur][i],(mult*pref[i]%mod)*suff[i+1]%mod);
    }
}

struct SegTree {
    struct Node {
        ll sum=0,actsum=0;
        bool flip=0;

        Node(ll _sum=0, ll _actsum=0): sum(_sum),actsum(_actsum) {}
    };

    Node unite(Node a, Node b) {
        return {(a.sum+b.sum)%mod,(a.actsum+b.actsum)%mod};
    }

    vector<Node> tree;
    int sze;

    void push(int v, int tl, int tr) {
        if (tree[v].flip) {
            tree[v].actsum=(tree[v].sum-tree[v].actsum+mod)%mod;
            if (tl!=tr) {
                tree[v*2].flip^=1;
                tree[v*2+1].flip^=1;
            }
            tree[v].flip=0;
        }
    }

    void init(int _sze, vl& vals, vi& onoff) {
        sze=_sze;
        tree.resize(4*sze);
        build(vals,onoff,1,0,sze-1);
    }

    void build(vl& vals, vi& onoff, int v, int tl, int tr) {
        if (tl==tr) {
            if (onoff[tl]) {
                tree[v]={vals[tl],vals[tl]};
            }
            else {
                tree[v]={vals[tl],0};
            }
            return;
        }
        int tm=tl+(tr-tl)/2;
        build(vals,onoff,v*2,tl,tm);
        build(vals,onoff,v*2+1,tm+1,tr);
        tree[v]=unite(tree[v*2],tree[v*2+1]);
    }

    void flip(int l, int r, int v, int tl, int tr) {
        push(v,tl,tr);
        if (r<tl || l>tr) {
            return;
        }
        if (l<=tl && tr<=r) {
            tree[v].flip=1;
            push(v,tl,tr);
            return;
        }
        int tm=tl+(tr-tl)/2;
        flip(l,r,v*2,tl,tm);
        flip(l,r,v*2+1,tm+1,tr);
        tree[v]=unite(tree[v*2],tree[v*2+1]);
    }
    void flip(int l, int r) {
        flip(l,r,1,0,sze-1);
    }

    ll get() {
        return tree[1].actsum;
    }
};

SegTree dat;

void init(int nn, int mm, vi parent, vi onoff) {
    n=nn;
    m=mm;
    for (int i=1; i<n+m; i++) {
        graph[parent[i]].pb(i);
    }
    dfs(0);
    dfs2(0);
    dat.init(m,vals,onoff);
}

int count_ways(int l, int r) {
    dat.flip(l-n,r-n);
    return dat.get();
}

Compilation message

circuit.cpp: In function 'void dfs2(int, long long int)':
circuit.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i=0; i<graph[cur].size(); i++) {
      |                   ~^~~~~~~~~~~~~~~~~~
circuit.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i=0; i<graph[cur].size(); i++) {
      |                   ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7256 KB Output is correct
2 Correct 4 ms 7256 KB Output is correct
3 Correct 4 ms 7512 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7512 KB Output is correct
7 Correct 5 ms 7512 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7256 KB Output is correct
2 Correct 4 ms 7512 KB Output is correct
3 Correct 3 ms 7512 KB Output is correct
4 Correct 3 ms 7512 KB Output is correct
5 Correct 3 ms 7532 KB Output is correct
6 Correct 4 ms 7512 KB Output is correct
7 Correct 3 ms 7512 KB Output is correct
8 Correct 4 ms 7512 KB Output is correct
9 Correct 4 ms 7564 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
11 Correct 4 ms 7712 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7256 KB Output is correct
2 Correct 4 ms 7256 KB Output is correct
3 Correct 4 ms 7512 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7512 KB Output is correct
7 Correct 5 ms 7512 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 4 ms 7256 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7532 KB Output is correct
14 Correct 4 ms 7512 KB Output is correct
15 Correct 3 ms 7512 KB Output is correct
16 Correct 4 ms 7512 KB Output is correct
17 Correct 4 ms 7564 KB Output is correct
18 Correct 4 ms 7768 KB Output is correct
19 Correct 4 ms 7712 KB Output is correct
20 Correct 3 ms 7512 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 3 ms 7356 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7520 KB Output is correct
25 Correct 4 ms 7512 KB Output is correct
26 Correct 4 ms 7512 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 3 ms 7512 KB Output is correct
29 Correct 4 ms 7512 KB Output is correct
30 Correct 4 ms 7512 KB Output is correct
31 Correct 3 ms 7512 KB Output is correct
32 Correct 3 ms 7512 KB Output is correct
33 Correct 4 ms 7512 KB Output is correct
34 Correct 4 ms 7512 KB Output is correct
35 Correct 3 ms 7512 KB Output is correct
36 Correct 4 ms 7724 KB Output is correct
37 Correct 4 ms 7768 KB Output is correct
38 Correct 3 ms 7768 KB Output is correct
39 Correct 3 ms 7512 KB Output is correct
40 Correct 4 ms 7512 KB Output is correct
41 Correct 4 ms 7512 KB Output is correct
42 Correct 4 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 12376 KB Output is correct
2 Correct 674 ms 17240 KB Output is correct
3 Correct 712 ms 16976 KB Output is correct
4 Correct 686 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 12376 KB Output is correct
2 Correct 674 ms 17240 KB Output is correct
3 Correct 712 ms 16976 KB Output is correct
4 Correct 686 ms 17232 KB Output is correct
5 Correct 585 ms 12376 KB Output is correct
6 Correct 739 ms 17240 KB Output is correct
7 Correct 799 ms 17244 KB Output is correct
8 Correct 681 ms 17240 KB Output is correct
9 Correct 318 ms 7780 KB Output is correct
10 Correct 641 ms 8084 KB Output is correct
11 Correct 631 ms 8088 KB Output is correct
12 Correct 573 ms 8084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7256 KB Output is correct
2 Correct 4 ms 7512 KB Output is correct
3 Correct 3 ms 7512 KB Output is correct
4 Correct 3 ms 7512 KB Output is correct
5 Correct 3 ms 7532 KB Output is correct
6 Correct 4 ms 7512 KB Output is correct
7 Correct 3 ms 7512 KB Output is correct
8 Correct 4 ms 7512 KB Output is correct
9 Correct 4 ms 7564 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
11 Correct 4 ms 7712 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 472 ms 12376 KB Output is correct
14 Correct 674 ms 17240 KB Output is correct
15 Correct 712 ms 16976 KB Output is correct
16 Correct 686 ms 17232 KB Output is correct
17 Correct 585 ms 12376 KB Output is correct
18 Correct 739 ms 17240 KB Output is correct
19 Correct 799 ms 17244 KB Output is correct
20 Correct 681 ms 17240 KB Output is correct
21 Correct 318 ms 7780 KB Output is correct
22 Correct 641 ms 8084 KB Output is correct
23 Correct 631 ms 8088 KB Output is correct
24 Correct 573 ms 8084 KB Output is correct
25 Correct 699 ms 21840 KB Output is correct
26 Correct 820 ms 22168 KB Output is correct
27 Correct 782 ms 22148 KB Output is correct
28 Correct 474 ms 22256 KB Output is correct
29 Correct 780 ms 39484 KB Output is correct
30 Correct 668 ms 39480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7256 KB Output is correct
2 Correct 4 ms 7256 KB Output is correct
3 Correct 4 ms 7512 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7512 KB Output is correct
7 Correct 5 ms 7512 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 4 ms 7256 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7532 KB Output is correct
14 Correct 4 ms 7512 KB Output is correct
15 Correct 3 ms 7512 KB Output is correct
16 Correct 4 ms 7512 KB Output is correct
17 Correct 4 ms 7564 KB Output is correct
18 Correct 4 ms 7768 KB Output is correct
19 Correct 4 ms 7712 KB Output is correct
20 Correct 3 ms 7512 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 3 ms 7356 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7520 KB Output is correct
25 Correct 4 ms 7512 KB Output is correct
26 Correct 4 ms 7512 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 3 ms 7512 KB Output is correct
29 Correct 4 ms 7512 KB Output is correct
30 Correct 4 ms 7512 KB Output is correct
31 Correct 3 ms 7512 KB Output is correct
32 Correct 3 ms 7512 KB Output is correct
33 Correct 4 ms 7512 KB Output is correct
34 Correct 4 ms 7512 KB Output is correct
35 Correct 3 ms 7512 KB Output is correct
36 Correct 4 ms 7724 KB Output is correct
37 Correct 4 ms 7768 KB Output is correct
38 Correct 3 ms 7768 KB Output is correct
39 Correct 3 ms 7512 KB Output is correct
40 Correct 4 ms 7512 KB Output is correct
41 Correct 4 ms 7512 KB Output is correct
42 Correct 4 ms 7512 KB Output is correct
43 Correct 469 ms 7896 KB Output is correct
44 Correct 666 ms 7904 KB Output is correct
45 Correct 665 ms 7916 KB Output is correct
46 Correct 619 ms 8220 KB Output is correct
47 Correct 671 ms 8232 KB Output is correct
48 Correct 716 ms 8228 KB Output is correct
49 Correct 652 ms 8232 KB Output is correct
50 Correct 703 ms 8224 KB Output is correct
51 Correct 676 ms 8152 KB Output is correct
52 Correct 670 ms 8164 KB Output is correct
53 Correct 605 ms 8536 KB Output is correct
54 Correct 689 ms 8224 KB Output is correct
55 Correct 683 ms 8112 KB Output is correct
56 Correct 717 ms 8112 KB Output is correct
57 Correct 669 ms 8064 KB Output is correct
58 Correct 654 ms 9072 KB Output is correct
59 Correct 660 ms 9180 KB Output is correct
60 Correct 626 ms 9180 KB Output is correct
61 Correct 687 ms 8276 KB Output is correct
62 Correct 724 ms 7944 KB Output is correct
63 Correct 718 ms 7940 KB Output is correct
64 Correct 682 ms 8096 KB Output is correct
65 Correct 317 ms 7772 KB Output is correct
66 Correct 627 ms 8084 KB Output is correct
67 Correct 518 ms 8080 KB Output is correct
68 Correct 634 ms 8088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7256 KB Output is correct
2 Correct 4 ms 7256 KB Output is correct
3 Correct 4 ms 7512 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7512 KB Output is correct
7 Correct 5 ms 7512 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 4 ms 7256 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7512 KB Output is correct
13 Correct 3 ms 7532 KB Output is correct
14 Correct 4 ms 7512 KB Output is correct
15 Correct 3 ms 7512 KB Output is correct
16 Correct 4 ms 7512 KB Output is correct
17 Correct 4 ms 7564 KB Output is correct
18 Correct 4 ms 7768 KB Output is correct
19 Correct 4 ms 7712 KB Output is correct
20 Correct 3 ms 7512 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 3 ms 7356 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7520 KB Output is correct
25 Correct 4 ms 7512 KB Output is correct
26 Correct 4 ms 7512 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 3 ms 7512 KB Output is correct
29 Correct 4 ms 7512 KB Output is correct
30 Correct 4 ms 7512 KB Output is correct
31 Correct 3 ms 7512 KB Output is correct
32 Correct 3 ms 7512 KB Output is correct
33 Correct 4 ms 7512 KB Output is correct
34 Correct 4 ms 7512 KB Output is correct
35 Correct 3 ms 7512 KB Output is correct
36 Correct 4 ms 7724 KB Output is correct
37 Correct 4 ms 7768 KB Output is correct
38 Correct 3 ms 7768 KB Output is correct
39 Correct 3 ms 7512 KB Output is correct
40 Correct 4 ms 7512 KB Output is correct
41 Correct 4 ms 7512 KB Output is correct
42 Correct 4 ms 7512 KB Output is correct
43 Correct 472 ms 12376 KB Output is correct
44 Correct 674 ms 17240 KB Output is correct
45 Correct 712 ms 16976 KB Output is correct
46 Correct 686 ms 17232 KB Output is correct
47 Correct 585 ms 12376 KB Output is correct
48 Correct 739 ms 17240 KB Output is correct
49 Correct 799 ms 17244 KB Output is correct
50 Correct 681 ms 17240 KB Output is correct
51 Correct 318 ms 7780 KB Output is correct
52 Correct 641 ms 8084 KB Output is correct
53 Correct 631 ms 8088 KB Output is correct
54 Correct 573 ms 8084 KB Output is correct
55 Correct 699 ms 21840 KB Output is correct
56 Correct 820 ms 22168 KB Output is correct
57 Correct 782 ms 22148 KB Output is correct
58 Correct 474 ms 22256 KB Output is correct
59 Correct 780 ms 39484 KB Output is correct
60 Correct 668 ms 39480 KB Output is correct
61 Correct 469 ms 7896 KB Output is correct
62 Correct 666 ms 7904 KB Output is correct
63 Correct 665 ms 7916 KB Output is correct
64 Correct 619 ms 8220 KB Output is correct
65 Correct 671 ms 8232 KB Output is correct
66 Correct 716 ms 8228 KB Output is correct
67 Correct 652 ms 8232 KB Output is correct
68 Correct 703 ms 8224 KB Output is correct
69 Correct 676 ms 8152 KB Output is correct
70 Correct 670 ms 8164 KB Output is correct
71 Correct 605 ms 8536 KB Output is correct
72 Correct 689 ms 8224 KB Output is correct
73 Correct 683 ms 8112 KB Output is correct
74 Correct 717 ms 8112 KB Output is correct
75 Correct 669 ms 8064 KB Output is correct
76 Correct 654 ms 9072 KB Output is correct
77 Correct 660 ms 9180 KB Output is correct
78 Correct 626 ms 9180 KB Output is correct
79 Correct 687 ms 8276 KB Output is correct
80 Correct 724 ms 7944 KB Output is correct
81 Correct 718 ms 7940 KB Output is correct
82 Correct 682 ms 8096 KB Output is correct
83 Correct 317 ms 7772 KB Output is correct
84 Correct 627 ms 8084 KB Output is correct
85 Correct 518 ms 8080 KB Output is correct
86 Correct 634 ms 8088 KB Output is correct
87 Correct 3 ms 7256 KB Output is correct
88 Correct 452 ms 19992 KB Output is correct
89 Correct 770 ms 15860 KB Output is correct
90 Correct 662 ms 16208 KB Output is correct
91 Correct 638 ms 22348 KB Output is correct
92 Correct 724 ms 22228 KB Output is correct
93 Correct 771 ms 22284 KB Output is correct
94 Correct 751 ms 22352 KB Output is correct
95 Correct 710 ms 22352 KB Output is correct
96 Correct 628 ms 18852 KB Output is correct
97 Correct 708 ms 18860 KB Output is correct
98 Correct 666 ms 28448 KB Output is correct
99 Correct 743 ms 22224 KB Output is correct
100 Correct 758 ms 20304 KB Output is correct
101 Correct 741 ms 19864 KB Output is correct
102 Correct 792 ms 18900 KB Output is correct
103 Correct 788 ms 39504 KB Output is correct
104 Correct 770 ms 39732 KB Output is correct
105 Correct 709 ms 39856 KB Output is correct
106 Correct 727 ms 18776 KB Output is correct
107 Correct 708 ms 16216 KB Output is correct
108 Correct 744 ms 16976 KB Output is correct
109 Correct 770 ms 19032 KB Output is correct