Submission #1071769

# Submission time Handle Problem Language Result Execution time Memory
1071769 2024-08-23T11:05:06 Z Unforgettablepl Digital Circuit (IOI22_circuit) C++17
100 / 100
850 ms 33700 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

const long long modulo = 1e9+2022;

struct segtree {
    vector<pair<long long,long long>> tree;
    int N;
    vector<bool> lazy;
    segtree(){}
    void build(int x,int L,int R,vector<long long> &arr,vector<int> &A) {
        if(L==R) {
            if(A[L-1]) tree[x].first=arr[L-1];
            else tree[x].second=arr[L-1];
            return;
        }
        int mid = (L+R)/2;
        build(2*x,L,mid,arr,A);
        build(2*x+1,mid+1,R,arr,A);
        tree[x].first=(tree[2*x].first+tree[2*x+1].first)%modulo;
        tree[x].second=(tree[2*x].second+tree[2*x+1].second)%modulo;
    }
    segtree(int N,vector<long long> &arr,vector<int> &A):tree(4*N),N(N),lazy(4*N) {
        build(1,1,N,arr,A);
    }
    void update(int x,int L,int R,int qL,int qR) {
        if(lazy[x]) {
            swap(tree[x].first,tree[x].second);
            lazy[x]=false;
            if(L!=R) {
                lazy[2*x]=!lazy[2*x];
                lazy[2*x+1]=!lazy[2*x+1];
            }
        }
        if(qR<L or R<qL)return;
        if(qL<=L and R<=qR) {
            swap(tree[x].first,tree[x].second);
            if(L!=R) {
                lazy[2*x]=!lazy[2*x];
                lazy[2*x+1]=!lazy[2*x+1];
            }
            return;
        }
        int mid = (L+R)/2;
        update(2*x,L,mid,qL,qR);
        update(2*x+1,mid+1,R,qL,qR);
        tree[x].first=(tree[2*x].first+tree[2*x+1].first)%modulo;
        tree[x].second=(tree[2*x].second+tree[2*x+1].second)%modulo;
    }
    void update(int L,int R) {
        update(1,1,N,L+1,R+1);
    }
    long long get() {
        return tree[1].first;
    }
};

namespace {
    int N,M;
    vector<int> A;
    vector<long long> arr;
    segtree seg;
}

void init(int N,int M,vector<int> P,vector<int> A){
    ::N = N;
    ::M = M;
    ::A = A;
    arr = vector<long long>(M);
    vector<vector<int>> adj(N);
    vector<vector<pair<long long,long long>>> ways(N);
    for(int i=1;i<N+M;i++){adj[P[i]].emplace_back(i);ways[P[i]].emplace_back(1,1);}
    {
        function<long long(int)> dfs = [&](int x){
            if(x>=N)return 1ll;
            long long tot_ways = adj[x].size();
            for(int i=0;i<adj[x].size();i++) {
                ways[x][i].first=ways[x][i].second=dfs(adj[x][i]);
                tot_ways=(tot_ways*ways[x][i].first)%modulo;
                if(i)ways[x][i].first=(ways[x][i].first*ways[x][i-1].first)%modulo;
            }
            for(int i=adj[x].size()-2;i>=0;i--)ways[x][i].second=(ways[x][i].second*ways[x][i+1].second)%modulo;
            return tot_ways;
        };
        dfs(0);
    }
    {
        function<void(int,long long)> dfs = [&](int x,long long offset) {
            if(x>=N) {
                arr[x-N]=offset;
                return;
            }
            for(int i=0;i<adj[x].size();i++) {
                long long tot = offset;
                if(i)tot=(tot*ways[x][i-1].first)%modulo;
                if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
                dfs(adj[x][i],tot);
            }
        };
        dfs(0,1);
    }
    seg = segtree(M,arr,A);
}

int count_ways(int L,int R){
    L-=N;R-=N;
    seg.update(L,R);
    return seg.get();
}

Compilation message

circuit.cpp: In lambda function:
circuit.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             for(int i=0;i<adj[x].size();i++) {
      |                         ~^~~~~~~~~~~~~~
circuit.cpp: In lambda function:
circuit.cpp:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             for(int i=0;i<adj[x].size();i++) {
      |                         ~^~~~~~~~~~~~~~
circuit.cpp:97:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |                 if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
      |                    ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 552 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 552 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 502 ms 7768 KB Output is correct
2 Correct 665 ms 14928 KB Output is correct
3 Correct 726 ms 15120 KB Output is correct
4 Correct 723 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 502 ms 7768 KB Output is correct
2 Correct 665 ms 14928 KB Output is correct
3 Correct 726 ms 15120 KB Output is correct
4 Correct 723 ms 14936 KB Output is correct
5 Correct 626 ms 7764 KB Output is correct
6 Correct 733 ms 14936 KB Output is correct
7 Correct 688 ms 15004 KB Output is correct
8 Correct 665 ms 14928 KB Output is correct
9 Correct 363 ms 856 KB Output is correct
10 Correct 723 ms 1368 KB Output is correct
11 Correct 702 ms 1112 KB Output is correct
12 Correct 661 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 502 ms 7768 KB Output is correct
14 Correct 665 ms 14928 KB Output is correct
15 Correct 726 ms 15120 KB Output is correct
16 Correct 723 ms 14936 KB Output is correct
17 Correct 626 ms 7764 KB Output is correct
18 Correct 733 ms 14936 KB Output is correct
19 Correct 688 ms 15004 KB Output is correct
20 Correct 665 ms 14928 KB Output is correct
21 Correct 363 ms 856 KB Output is correct
22 Correct 723 ms 1368 KB Output is correct
23 Correct 702 ms 1112 KB Output is correct
24 Correct 661 ms 1112 KB Output is correct
25 Correct 754 ms 22212 KB Output is correct
26 Correct 772 ms 22608 KB Output is correct
27 Correct 755 ms 22608 KB Output is correct
28 Correct 611 ms 22712 KB Output is correct
29 Correct 779 ms 33616 KB Output is correct
30 Correct 796 ms 33700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 552 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 504 ms 856 KB Output is correct
44 Correct 649 ms 1112 KB Output is correct
45 Correct 650 ms 1112 KB Output is correct
46 Correct 673 ms 1368 KB Output is correct
47 Correct 659 ms 1368 KB Output is correct
48 Correct 650 ms 1368 KB Output is correct
49 Correct 647 ms 1368 KB Output is correct
50 Correct 623 ms 1368 KB Output is correct
51 Correct 642 ms 856 KB Output is correct
52 Correct 689 ms 856 KB Output is correct
53 Correct 568 ms 1368 KB Output is correct
54 Correct 671 ms 1368 KB Output is correct
55 Correct 719 ms 1300 KB Output is correct
56 Correct 659 ms 1204 KB Output is correct
57 Correct 689 ms 992 KB Output is correct
58 Correct 647 ms 1880 KB Output is correct
59 Correct 663 ms 2132 KB Output is correct
60 Correct 674 ms 1984 KB Output is correct
61 Correct 686 ms 1112 KB Output is correct
62 Correct 746 ms 856 KB Output is correct
63 Correct 653 ms 856 KB Output is correct
64 Correct 704 ms 856 KB Output is correct
65 Correct 314 ms 856 KB Output is correct
66 Correct 699 ms 1112 KB Output is correct
67 Correct 682 ms 1112 KB Output is correct
68 Correct 646 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 552 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 516 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 502 ms 7768 KB Output is correct
44 Correct 665 ms 14928 KB Output is correct
45 Correct 726 ms 15120 KB Output is correct
46 Correct 723 ms 14936 KB Output is correct
47 Correct 626 ms 7764 KB Output is correct
48 Correct 733 ms 14936 KB Output is correct
49 Correct 688 ms 15004 KB Output is correct
50 Correct 665 ms 14928 KB Output is correct
51 Correct 363 ms 856 KB Output is correct
52 Correct 723 ms 1368 KB Output is correct
53 Correct 702 ms 1112 KB Output is correct
54 Correct 661 ms 1112 KB Output is correct
55 Correct 754 ms 22212 KB Output is correct
56 Correct 772 ms 22608 KB Output is correct
57 Correct 755 ms 22608 KB Output is correct
58 Correct 611 ms 22712 KB Output is correct
59 Correct 779 ms 33616 KB Output is correct
60 Correct 796 ms 33700 KB Output is correct
61 Correct 504 ms 856 KB Output is correct
62 Correct 649 ms 1112 KB Output is correct
63 Correct 650 ms 1112 KB Output is correct
64 Correct 673 ms 1368 KB Output is correct
65 Correct 659 ms 1368 KB Output is correct
66 Correct 650 ms 1368 KB Output is correct
67 Correct 647 ms 1368 KB Output is correct
68 Correct 623 ms 1368 KB Output is correct
69 Correct 642 ms 856 KB Output is correct
70 Correct 689 ms 856 KB Output is correct
71 Correct 568 ms 1368 KB Output is correct
72 Correct 671 ms 1368 KB Output is correct
73 Correct 719 ms 1300 KB Output is correct
74 Correct 659 ms 1204 KB Output is correct
75 Correct 689 ms 992 KB Output is correct
76 Correct 647 ms 1880 KB Output is correct
77 Correct 663 ms 2132 KB Output is correct
78 Correct 674 ms 1984 KB Output is correct
79 Correct 686 ms 1112 KB Output is correct
80 Correct 746 ms 856 KB Output is correct
81 Correct 653 ms 856 KB Output is correct
82 Correct 704 ms 856 KB Output is correct
83 Correct 314 ms 856 KB Output is correct
84 Correct 699 ms 1112 KB Output is correct
85 Correct 682 ms 1112 KB Output is correct
86 Correct 646 ms 1112 KB Output is correct
87 Correct 1 ms 344 KB Output is correct
88 Correct 401 ms 20720 KB Output is correct
89 Correct 701 ms 14672 KB Output is correct
90 Correct 751 ms 14756 KB Output is correct
91 Correct 739 ms 23100 KB Output is correct
92 Correct 808 ms 23188 KB Output is correct
93 Correct 817 ms 23112 KB Output is correct
94 Correct 773 ms 23196 KB Output is correct
95 Correct 778 ms 23112 KB Output is correct
96 Correct 722 ms 11720 KB Output is correct
97 Correct 760 ms 11820 KB Output is correct
98 Correct 660 ms 19800 KB Output is correct
99 Correct 768 ms 22608 KB Output is correct
100 Correct 850 ms 17744 KB Output is correct
101 Correct 754 ms 15704 KB Output is correct
102 Correct 694 ms 11864 KB Output is correct
103 Correct 789 ms 33592 KB Output is correct
104 Correct 763 ms 31424 KB Output is correct
105 Correct 728 ms 31320 KB Output is correct
106 Correct 763 ms 15704 KB Output is correct
107 Correct 706 ms 12372 KB Output is correct
108 Correct 786 ms 12888 KB Output is correct
109 Correct 746 ms 12376 KB Output is correct