답안 #932578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932578 2024-02-23T18:13:35 Z velislavgarkov 디지털 회로 (IOI22_circuit) C++17
100 / 100
714 ms 49264 KB
#include "circuit.h"
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=2e5+10;
const long long mod=1e9+2022;
vector <int> v[MAXN];
vector <long long> pref[MAXN], suf[MAXN];
long long mult[MAXN];
long long tree[4*MAXN][2], val[MAXN];
int lazy[4*MAXN];
int start[MAXN];
int n, m;
void precomp(int x) {
    if (v[x].empty()) {
        mult[x]=1;
        return;
    }
    pref[x].resize(v[x].size());
    suf[x].resize(v[x].size());
    mult[x]=v[x].size();
    for (int i=0;i<v[x].size();i++) {
        precomp(v[x][i]);
        if (i==0) pref[x][i]=mult[v[x][i]];
        else pref[x][i]=(pref[x][i-1]*mult[v[x][i]])%mod;
        mult[x]=(mult[x]*mult[v[x][i]])%mod;
    }
    for (int i=v[x].size()-1;i>=0;i--) {
        if (i==v[x].size()-1) suf[x][i]=mult[v[x][i]];
        else suf[x][i]=(suf[x][i+1]*mult[v[x][i]])%mod;
    }
}
void dfs(int x, long long ways) {
    if (x>=n) {
        val[x-n]=ways;
        //cout << x << ' ' << ways << endl;
        return;
    }
    long long s;
    for (int i=0;i<v[x].size();i++) {
        s=1;
        if (i>0) s*=pref[x][i-1];
        if (i<v[x].size()-1) s*=suf[x][i+1];
        s%=mod;
        dfs(v[x][i],(ways*s)%mod);
    }
}
void build_tree(int node, int l, int r) {
    if (l==r) {
        tree[node][0]=tree[node][1]=0;
        tree[node][start[l]]=val[l];
        return;
    }
    int mid=(l+r)/2;
    build_tree(node*2,l,mid);
    build_tree(node*2+1,mid+1,r);
    tree[node][0]=(tree[node*2][0]+tree[node*2+1][0])%mod;
    tree[node][1]=(tree[node*2][1]+tree[node*2+1][1])%mod;
}
void push_lazy(int node, int l, int r) {
    if (l!=r && lazy[node]%2==1) {
        lazy[node*2]++;
        lazy[node*2+1]++;
        swap(tree[node*2][0],tree[node*2][1]);
        swap(tree[node*2+1][0],tree[node*2+1][1]);
    }
    lazy[node]=0;
}
void update(int node, int l, int r, int ql, int qr) {
    if (ql>r || qr<l) return;
    push_lazy(node,l,r);
    if (l>=ql && r<=qr) {
        swap(tree[node][0],tree[node][1]);
        lazy[node]++;
        return;
    }
    int mid=(l+r)/2;
    update(node*2,l,mid,ql,qr);
    update(node*2+1,mid+1,r,ql,qr);
    tree[node][0]=(tree[node*2][0]+tree[node*2+1][0])%mod;
    tree[node][1]=(tree[node*2][1]+tree[node*2+1][1])%mod;
}
void init(int N, int M, vector <int> p, vector <int> a) {
    n=N;
    m=M;
    for (int i=1;i<n+m;i++) v[p[i]].push_back(i);
    for (int i=0;i<m;i++) start[i]=a[i];
    precomp(0);
    dfs(0,1);
    build_tree(1,0,m-1);
}
int count_ways(int l, int r) {
    l-=n; r-=n;
    update(1,0,m-1,l,r);
    return tree[1][1];
}

Compilation message

circuit.cpp: In function 'void precomp(int)':
circuit.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i=0;i<v[x].size();i++) {
      |                  ~^~~~~~~~~~~~
circuit.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (i==v[x].size()-1) suf[x][i]=mult[v[x][i]];
      |             ~^~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfs(int, long long int)':
circuit.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i=0;i<v[x].size();i++) {
      |                  ~^~~~~~~~~~~~
circuit.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         if (i<v[x].size()-1) s*=suf[x][i+1];
      |             ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21592 KB Output is correct
2 Correct 4 ms 23640 KB Output is correct
3 Correct 5 ms 21592 KB Output is correct
4 Correct 5 ms 21640 KB Output is correct
5 Correct 4 ms 21592 KB Output is correct
6 Correct 4 ms 21564 KB Output is correct
7 Correct 4 ms 21592 KB Output is correct
8 Correct 5 ms 21592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21592 KB Output is correct
2 Correct 4 ms 21592 KB Output is correct
3 Correct 4 ms 21592 KB Output is correct
4 Correct 5 ms 21592 KB Output is correct
5 Correct 4 ms 21592 KB Output is correct
6 Correct 5 ms 21592 KB Output is correct
7 Correct 5 ms 21588 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 5 ms 21592 KB Output is correct
10 Correct 5 ms 21592 KB Output is correct
11 Correct 5 ms 21592 KB Output is correct
12 Correct 5 ms 21592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21592 KB Output is correct
2 Correct 4 ms 23640 KB Output is correct
3 Correct 5 ms 21592 KB Output is correct
4 Correct 5 ms 21640 KB Output is correct
5 Correct 4 ms 21592 KB Output is correct
6 Correct 4 ms 21564 KB Output is correct
7 Correct 4 ms 21592 KB Output is correct
8 Correct 5 ms 21592 KB Output is correct
9 Correct 4 ms 21592 KB Output is correct
10 Correct 4 ms 21592 KB Output is correct
11 Correct 4 ms 21592 KB Output is correct
12 Correct 5 ms 21592 KB Output is correct
13 Correct 4 ms 21592 KB Output is correct
14 Correct 5 ms 21592 KB Output is correct
15 Correct 5 ms 21588 KB Output is correct
16 Correct 4 ms 21592 KB Output is correct
17 Correct 5 ms 21592 KB Output is correct
18 Correct 5 ms 21592 KB Output is correct
19 Correct 5 ms 21592 KB Output is correct
20 Correct 5 ms 21592 KB Output is correct
21 Correct 5 ms 21588 KB Output is correct
22 Correct 4 ms 21592 KB Output is correct
23 Correct 4 ms 21684 KB Output is correct
24 Correct 5 ms 21592 KB Output is correct
25 Correct 5 ms 21608 KB Output is correct
26 Correct 5 ms 21592 KB Output is correct
27 Correct 5 ms 21576 KB Output is correct
28 Correct 6 ms 21844 KB Output is correct
29 Correct 5 ms 21592 KB Output is correct
30 Correct 4 ms 21576 KB Output is correct
31 Correct 5 ms 23640 KB Output is correct
32 Correct 5 ms 21592 KB Output is correct
33 Correct 4 ms 21592 KB Output is correct
34 Correct 6 ms 21592 KB Output is correct
35 Correct 4 ms 21656 KB Output is correct
36 Correct 5 ms 21592 KB Output is correct
37 Correct 6 ms 21592 KB Output is correct
38 Correct 5 ms 21592 KB Output is correct
39 Correct 5 ms 21592 KB Output is correct
40 Correct 4 ms 21592 KB Output is correct
41 Correct 5 ms 21848 KB Output is correct
42 Correct 4 ms 21592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 409 ms 27520 KB Output is correct
2 Correct 592 ms 33388 KB Output is correct
3 Correct 616 ms 33384 KB Output is correct
4 Correct 573 ms 33380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 409 ms 27520 KB Output is correct
2 Correct 592 ms 33388 KB Output is correct
3 Correct 616 ms 33384 KB Output is correct
4 Correct 573 ms 33380 KB Output is correct
5 Correct 444 ms 27632 KB Output is correct
6 Correct 641 ms 33392 KB Output is correct
7 Correct 655 ms 33384 KB Output is correct
8 Correct 566 ms 33384 KB Output is correct
9 Correct 276 ms 21848 KB Output is correct
10 Correct 580 ms 22356 KB Output is correct
11 Correct 548 ms 22356 KB Output is correct
12 Correct 562 ms 22104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21592 KB Output is correct
2 Correct 4 ms 21592 KB Output is correct
3 Correct 4 ms 21592 KB Output is correct
4 Correct 5 ms 21592 KB Output is correct
5 Correct 4 ms 21592 KB Output is correct
6 Correct 5 ms 21592 KB Output is correct
7 Correct 5 ms 21588 KB Output is correct
8 Correct 4 ms 21592 KB Output is correct
9 Correct 5 ms 21592 KB Output is correct
10 Correct 5 ms 21592 KB Output is correct
11 Correct 5 ms 21592 KB Output is correct
12 Correct 5 ms 21592 KB Output is correct
13 Correct 409 ms 27520 KB Output is correct
14 Correct 592 ms 33388 KB Output is correct
15 Correct 616 ms 33384 KB Output is correct
16 Correct 573 ms 33380 KB Output is correct
17 Correct 444 ms 27632 KB Output is correct
18 Correct 641 ms 33392 KB Output is correct
19 Correct 655 ms 33384 KB Output is correct
20 Correct 566 ms 33384 KB Output is correct
21 Correct 276 ms 21848 KB Output is correct
22 Correct 580 ms 22356 KB Output is correct
23 Correct 548 ms 22356 KB Output is correct
24 Correct 562 ms 22104 KB Output is correct
25 Correct 681 ms 39336 KB Output is correct
26 Correct 669 ms 39440 KB Output is correct
27 Correct 714 ms 39664 KB Output is correct
28 Correct 541 ms 39664 KB Output is correct
29 Correct 652 ms 47484 KB Output is correct
30 Correct 618 ms 47348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21592 KB Output is correct
2 Correct 4 ms 23640 KB Output is correct
3 Correct 5 ms 21592 KB Output is correct
4 Correct 5 ms 21640 KB Output is correct
5 Correct 4 ms 21592 KB Output is correct
6 Correct 4 ms 21564 KB Output is correct
7 Correct 4 ms 21592 KB Output is correct
8 Correct 5 ms 21592 KB Output is correct
9 Correct 4 ms 21592 KB Output is correct
10 Correct 4 ms 21592 KB Output is correct
11 Correct 4 ms 21592 KB Output is correct
12 Correct 5 ms 21592 KB Output is correct
13 Correct 4 ms 21592 KB Output is correct
14 Correct 5 ms 21592 KB Output is correct
15 Correct 5 ms 21588 KB Output is correct
16 Correct 4 ms 21592 KB Output is correct
17 Correct 5 ms 21592 KB Output is correct
18 Correct 5 ms 21592 KB Output is correct
19 Correct 5 ms 21592 KB Output is correct
20 Correct 5 ms 21592 KB Output is correct
21 Correct 5 ms 21588 KB Output is correct
22 Correct 4 ms 21592 KB Output is correct
23 Correct 4 ms 21684 KB Output is correct
24 Correct 5 ms 21592 KB Output is correct
25 Correct 5 ms 21608 KB Output is correct
26 Correct 5 ms 21592 KB Output is correct
27 Correct 5 ms 21576 KB Output is correct
28 Correct 6 ms 21844 KB Output is correct
29 Correct 5 ms 21592 KB Output is correct
30 Correct 4 ms 21576 KB Output is correct
31 Correct 5 ms 23640 KB Output is correct
32 Correct 5 ms 21592 KB Output is correct
33 Correct 4 ms 21592 KB Output is correct
34 Correct 6 ms 21592 KB Output is correct
35 Correct 4 ms 21656 KB Output is correct
36 Correct 5 ms 21592 KB Output is correct
37 Correct 6 ms 21592 KB Output is correct
38 Correct 5 ms 21592 KB Output is correct
39 Correct 5 ms 21592 KB Output is correct
40 Correct 4 ms 21592 KB Output is correct
41 Correct 5 ms 21848 KB Output is correct
42 Correct 4 ms 21592 KB Output is correct
43 Correct 433 ms 21848 KB Output is correct
44 Correct 597 ms 22104 KB Output is correct
45 Correct 563 ms 21848 KB Output is correct
46 Correct 556 ms 22104 KB Output is correct
47 Correct 577 ms 22360 KB Output is correct
48 Correct 565 ms 22104 KB Output is correct
49 Correct 529 ms 22360 KB Output is correct
50 Correct 594 ms 22088 KB Output is correct
51 Correct 544 ms 21848 KB Output is correct
52 Correct 529 ms 22104 KB Output is correct
53 Correct 548 ms 24408 KB Output is correct
54 Correct 521 ms 22104 KB Output is correct
55 Correct 540 ms 21848 KB Output is correct
56 Correct 536 ms 21848 KB Output is correct
57 Correct 531 ms 21848 KB Output is correct
58 Correct 539 ms 22872 KB Output is correct
59 Correct 554 ms 22616 KB Output is correct
60 Correct 507 ms 22616 KB Output is correct
61 Correct 526 ms 22104 KB Output is correct
62 Correct 507 ms 21848 KB Output is correct
63 Correct 529 ms 21848 KB Output is correct
64 Correct 541 ms 22100 KB Output is correct
65 Correct 257 ms 21848 KB Output is correct
66 Correct 563 ms 22104 KB Output is correct
67 Correct 522 ms 22104 KB Output is correct
68 Correct 508 ms 22104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21592 KB Output is correct
2 Correct 4 ms 23640 KB Output is correct
3 Correct 5 ms 21592 KB Output is correct
4 Correct 5 ms 21640 KB Output is correct
5 Correct 4 ms 21592 KB Output is correct
6 Correct 4 ms 21564 KB Output is correct
7 Correct 4 ms 21592 KB Output is correct
8 Correct 5 ms 21592 KB Output is correct
9 Correct 4 ms 21592 KB Output is correct
10 Correct 4 ms 21592 KB Output is correct
11 Correct 4 ms 21592 KB Output is correct
12 Correct 5 ms 21592 KB Output is correct
13 Correct 4 ms 21592 KB Output is correct
14 Correct 5 ms 21592 KB Output is correct
15 Correct 5 ms 21588 KB Output is correct
16 Correct 4 ms 21592 KB Output is correct
17 Correct 5 ms 21592 KB Output is correct
18 Correct 5 ms 21592 KB Output is correct
19 Correct 5 ms 21592 KB Output is correct
20 Correct 5 ms 21592 KB Output is correct
21 Correct 5 ms 21588 KB Output is correct
22 Correct 4 ms 21592 KB Output is correct
23 Correct 4 ms 21684 KB Output is correct
24 Correct 5 ms 21592 KB Output is correct
25 Correct 5 ms 21608 KB Output is correct
26 Correct 5 ms 21592 KB Output is correct
27 Correct 5 ms 21576 KB Output is correct
28 Correct 6 ms 21844 KB Output is correct
29 Correct 5 ms 21592 KB Output is correct
30 Correct 4 ms 21576 KB Output is correct
31 Correct 5 ms 23640 KB Output is correct
32 Correct 5 ms 21592 KB Output is correct
33 Correct 4 ms 21592 KB Output is correct
34 Correct 6 ms 21592 KB Output is correct
35 Correct 4 ms 21656 KB Output is correct
36 Correct 5 ms 21592 KB Output is correct
37 Correct 6 ms 21592 KB Output is correct
38 Correct 5 ms 21592 KB Output is correct
39 Correct 5 ms 21592 KB Output is correct
40 Correct 4 ms 21592 KB Output is correct
41 Correct 5 ms 21848 KB Output is correct
42 Correct 4 ms 21592 KB Output is correct
43 Correct 409 ms 27520 KB Output is correct
44 Correct 592 ms 33388 KB Output is correct
45 Correct 616 ms 33384 KB Output is correct
46 Correct 573 ms 33380 KB Output is correct
47 Correct 444 ms 27632 KB Output is correct
48 Correct 641 ms 33392 KB Output is correct
49 Correct 655 ms 33384 KB Output is correct
50 Correct 566 ms 33384 KB Output is correct
51 Correct 276 ms 21848 KB Output is correct
52 Correct 580 ms 22356 KB Output is correct
53 Correct 548 ms 22356 KB Output is correct
54 Correct 562 ms 22104 KB Output is correct
55 Correct 681 ms 39336 KB Output is correct
56 Correct 669 ms 39440 KB Output is correct
57 Correct 714 ms 39664 KB Output is correct
58 Correct 541 ms 39664 KB Output is correct
59 Correct 652 ms 47484 KB Output is correct
60 Correct 618 ms 47348 KB Output is correct
61 Correct 433 ms 21848 KB Output is correct
62 Correct 597 ms 22104 KB Output is correct
63 Correct 563 ms 21848 KB Output is correct
64 Correct 556 ms 22104 KB Output is correct
65 Correct 577 ms 22360 KB Output is correct
66 Correct 565 ms 22104 KB Output is correct
67 Correct 529 ms 22360 KB Output is correct
68 Correct 594 ms 22088 KB Output is correct
69 Correct 544 ms 21848 KB Output is correct
70 Correct 529 ms 22104 KB Output is correct
71 Correct 548 ms 24408 KB Output is correct
72 Correct 521 ms 22104 KB Output is correct
73 Correct 540 ms 21848 KB Output is correct
74 Correct 536 ms 21848 KB Output is correct
75 Correct 531 ms 21848 KB Output is correct
76 Correct 539 ms 22872 KB Output is correct
77 Correct 554 ms 22616 KB Output is correct
78 Correct 507 ms 22616 KB Output is correct
79 Correct 526 ms 22104 KB Output is correct
80 Correct 507 ms 21848 KB Output is correct
81 Correct 529 ms 21848 KB Output is correct
82 Correct 541 ms 22100 KB Output is correct
83 Correct 257 ms 21848 KB Output is correct
84 Correct 563 ms 22104 KB Output is correct
85 Correct 522 ms 22104 KB Output is correct
86 Correct 508 ms 22104 KB Output is correct
87 Correct 4 ms 21592 KB Output is correct
88 Correct 398 ms 39000 KB Output is correct
89 Correct 651 ms 34532 KB Output is correct
90 Correct 594 ms 33616 KB Output is correct
91 Correct 584 ms 40188 KB Output is correct
92 Correct 661 ms 40180 KB Output is correct
93 Correct 636 ms 40172 KB Output is correct
94 Correct 712 ms 40180 KB Output is correct
95 Correct 662 ms 40316 KB Output is correct
96 Correct 580 ms 31452 KB Output is correct
97 Correct 707 ms 31464 KB Output is correct
98 Correct 565 ms 41140 KB Output is correct
99 Correct 635 ms 39640 KB Output is correct
100 Correct 698 ms 34768 KB Output is correct
101 Correct 591 ms 33100 KB Output is correct
102 Correct 611 ms 31576 KB Output is correct
103 Correct 619 ms 47360 KB Output is correct
104 Correct 712 ms 49260 KB Output is correct
105 Correct 605 ms 49264 KB Output is correct
106 Correct 643 ms 33992 KB Output is correct
107 Correct 661 ms 33272 KB Output is correct
108 Correct 671 ms 32580 KB Output is correct
109 Correct 674 ms 31612 KB Output is correct