Submission #1057594

# Submission time Handle Problem Language Result Execution time Memory
1057594 2024-08-13T22:53:58 Z boyliguanhan Digital Circuit (IOI22_circuit) C++17
100 / 100
684 ms 65692 KB
#include "circuit.h"
#include <vector>
typedef long long ll;
using namespace std;
const ll mod=1e9+2022;
struct segtree{
  struct DATA{
    ll totsum,actsum;
    int lz;
    DATA(){
      totsum=actsum=lz=0;
    }
    DATA(ll v){
      totsum=actsum=v;
      lz=0;
    }
    void apply(){
      lz^=1;
    }
    void flip(){
      lz^=1;
      actsum=(totsum+mod-actsum)%mod;
    }
    DATA(DATA a,DATA b){
      totsum=a.totsum+b.totsum;
      lz=0;actsum=a.actsum+b.actsum;
      totsum%=mod,actsum%=mod;
    }
  } T[1<<20];
  void pd(int i){
      if(T[i].lz)
        T[i].flip(),
        T[i*2].apply(),
        T[i*2+1].apply();
  }
  void init(int i,int l,int r,ll arr[]){
    if(l==r) return void(T[i]=DATA(arr[l]));
    init(i*2,l,l+r>>1,arr);
    init(i*2+1,l+r+2>>1,r,arr);
    T[i]=DATA(T[i*2],T[i*2+1]);
  }
  void tog(int i,int l,int r,int ll,int rr){
    pd(i); if(ll<=l&&r<=rr)
      return T[i].apply(),pd(i);
    if(ll>r||l>rr) return;
    tog(i*2,l,l+r>>1,ll,rr);
    tog(i*2+1,l+r+2>>1,r,ll,rr);
    T[i]=DATA(T[i*2],T[i*2+1]);
  }
} ST;
vector<int>adj[200100];
ll PRD[200100],FINALE[200100];
void dfs1(int n){
  if(adj[n].empty())
    return void(PRD[n]=1);
  PRD[n]=adj[n].size();
  for(auto x:adj[n])
    dfs1(x),PRD[n]=PRD[n]*PRD[x]%mod;
}
void dfs2(int n,ll K){
  if(adj[n].empty()){
    FINALE[n]=K;
  }
  vector<ll>v1,v2;
  v1.push_back(1);
  for(auto i:adj[n])
    v1.push_back(PRD[i]),
    v2.push_back(PRD[i]);
  v2.push_back(1);
  for(int i=1;i<v1.size();i++)
    v1[i]=v1[i-1]*v1[i]%mod;
  for(int i=v1.size();--i;)
    v2[i-1]=v2[i-1]*v2[i]%mod;
  int CC=0;
  for(auto i:adj[n]) CC++,
    dfs2(i,K*v1[CC-1]%mod*v2[CC]%mod);
}
int N,M;
void init(int N_, int M_, std::vector<int> P, std::vector<int> A) {
  N=N_,M=M_;
  for(int i=1;i<N+M;i++)
    adj[P[i]].push_back(i);
  dfs1(0);dfs2(0,1);
  ST.init(1,N,N+M-1,FINALE);
  for(int i=0;i<M;i++)
    if(!A[i])
      ST.tog(1,0,M-1,i,i);
}

int count_ways(int L, int R) {
  ST.tog(1,N,N+M-1,L,R);
  return ST.T[1].actsum;
}

Compilation message

circuit.cpp: In member function 'void segtree::init(int, int, int, ll*)':
circuit.cpp:38:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |     init(i*2,l,l+r>>1,arr);
      |                ~^~
circuit.cpp:39:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |     init(i*2+1,l+r+2>>1,r,arr);
      |                ~~~^~
circuit.cpp: In member function 'void segtree::tog(int, int, int, int, int)':
circuit.cpp:46:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     tog(i*2,l,l+r>>1,ll,rr);
      |               ~^~
circuit.cpp:47:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |     tog(i*2+1,l+r+2>>1,r,ll,rr);
      |               ~~~^~
circuit.cpp: In function 'void dfs2(int, ll)':
circuit.cpp:70:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(int i=1;i<v1.size();i++)
      |               ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 4 ms 31832 KB Output is correct
3 Correct 3 ms 31832 KB Output is correct
4 Correct 3 ms 31688 KB Output is correct
5 Correct 4 ms 31832 KB Output is correct
6 Correct 4 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 4 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 4 ms 31832 KB Output is correct
3 Correct 3 ms 31832 KB Output is correct
4 Correct 4 ms 31832 KB Output is correct
5 Correct 3 ms 31660 KB Output is correct
6 Correct 4 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 4 ms 31832 KB Output is correct
9 Correct 3 ms 31832 KB Output is correct
10 Correct 4 ms 32088 KB Output is correct
11 Correct 4 ms 32088 KB Output is correct
12 Correct 3 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 4 ms 31832 KB Output is correct
3 Correct 3 ms 31832 KB Output is correct
4 Correct 3 ms 31688 KB Output is correct
5 Correct 4 ms 31832 KB Output is correct
6 Correct 4 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 4 ms 31832 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 31832 KB Output is correct
11 Correct 3 ms 31832 KB Output is correct
12 Correct 4 ms 31832 KB Output is correct
13 Correct 3 ms 31660 KB Output is correct
14 Correct 4 ms 31832 KB Output is correct
15 Correct 4 ms 31832 KB Output is correct
16 Correct 4 ms 31832 KB Output is correct
17 Correct 3 ms 31832 KB Output is correct
18 Correct 4 ms 32088 KB Output is correct
19 Correct 4 ms 32088 KB Output is correct
20 Correct 3 ms 31832 KB Output is correct
21 Correct 4 ms 31828 KB Output is correct
22 Correct 3 ms 31832 KB Output is correct
23 Correct 4 ms 31832 KB Output is correct
24 Correct 4 ms 31832 KB Output is correct
25 Correct 4 ms 31948 KB Output is correct
26 Correct 4 ms 31832 KB Output is correct
27 Correct 3 ms 31832 KB Output is correct
28 Correct 4 ms 31832 KB Output is correct
29 Correct 4 ms 31832 KB Output is correct
30 Correct 3 ms 31832 KB Output is correct
31 Correct 4 ms 32088 KB Output is correct
32 Correct 4 ms 31832 KB Output is correct
33 Correct 4 ms 31832 KB Output is correct
34 Correct 3 ms 31832 KB Output is correct
35 Correct 4 ms 31832 KB Output is correct
36 Correct 4 ms 32088 KB Output is correct
37 Correct 4 ms 32088 KB Output is correct
38 Correct 4 ms 32088 KB Output is correct
39 Correct 3 ms 31944 KB Output is correct
40 Correct 3 ms 31832 KB Output is correct
41 Correct 3 ms 31832 KB Output is correct
42 Correct 3 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 349 ms 33808 KB Output is correct
2 Correct 575 ms 35928 KB Output is correct
3 Correct 581 ms 35928 KB Output is correct
4 Correct 581 ms 35920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 349 ms 33808 KB Output is correct
2 Correct 575 ms 35928 KB Output is correct
3 Correct 581 ms 35928 KB Output is correct
4 Correct 581 ms 35920 KB Output is correct
5 Correct 497 ms 33880 KB Output is correct
6 Correct 647 ms 35928 KB Output is correct
7 Correct 574 ms 35984 KB Output is correct
8 Correct 598 ms 35980 KB Output is correct
9 Correct 251 ms 31832 KB Output is correct
10 Correct 561 ms 32088 KB Output is correct
11 Correct 572 ms 32088 KB Output is correct
12 Correct 513 ms 32088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 4 ms 31832 KB Output is correct
3 Correct 3 ms 31832 KB Output is correct
4 Correct 4 ms 31832 KB Output is correct
5 Correct 3 ms 31660 KB Output is correct
6 Correct 4 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 4 ms 31832 KB Output is correct
9 Correct 3 ms 31832 KB Output is correct
10 Correct 4 ms 32088 KB Output is correct
11 Correct 4 ms 32088 KB Output is correct
12 Correct 3 ms 31832 KB Output is correct
13 Correct 349 ms 33808 KB Output is correct
14 Correct 575 ms 35928 KB Output is correct
15 Correct 581 ms 35928 KB Output is correct
16 Correct 581 ms 35920 KB Output is correct
17 Correct 497 ms 33880 KB Output is correct
18 Correct 647 ms 35928 KB Output is correct
19 Correct 574 ms 35984 KB Output is correct
20 Correct 598 ms 35980 KB Output is correct
21 Correct 251 ms 31832 KB Output is correct
22 Correct 561 ms 32088 KB Output is correct
23 Correct 572 ms 32088 KB Output is correct
24 Correct 513 ms 32088 KB Output is correct
25 Correct 618 ms 37464 KB Output is correct
26 Correct 619 ms 37456 KB Output is correct
27 Correct 631 ms 37360 KB Output is correct
28 Correct 491 ms 37456 KB Output is correct
29 Correct 618 ms 65560 KB Output is correct
30 Correct 663 ms 65616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 4 ms 31832 KB Output is correct
3 Correct 3 ms 31832 KB Output is correct
4 Correct 3 ms 31688 KB Output is correct
5 Correct 4 ms 31832 KB Output is correct
6 Correct 4 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 4 ms 31832 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 31832 KB Output is correct
11 Correct 3 ms 31832 KB Output is correct
12 Correct 4 ms 31832 KB Output is correct
13 Correct 3 ms 31660 KB Output is correct
14 Correct 4 ms 31832 KB Output is correct
15 Correct 4 ms 31832 KB Output is correct
16 Correct 4 ms 31832 KB Output is correct
17 Correct 3 ms 31832 KB Output is correct
18 Correct 4 ms 32088 KB Output is correct
19 Correct 4 ms 32088 KB Output is correct
20 Correct 3 ms 31832 KB Output is correct
21 Correct 4 ms 31828 KB Output is correct
22 Correct 3 ms 31832 KB Output is correct
23 Correct 4 ms 31832 KB Output is correct
24 Correct 4 ms 31832 KB Output is correct
25 Correct 4 ms 31948 KB Output is correct
26 Correct 4 ms 31832 KB Output is correct
27 Correct 3 ms 31832 KB Output is correct
28 Correct 4 ms 31832 KB Output is correct
29 Correct 4 ms 31832 KB Output is correct
30 Correct 3 ms 31832 KB Output is correct
31 Correct 4 ms 32088 KB Output is correct
32 Correct 4 ms 31832 KB Output is correct
33 Correct 4 ms 31832 KB Output is correct
34 Correct 3 ms 31832 KB Output is correct
35 Correct 4 ms 31832 KB Output is correct
36 Correct 4 ms 32088 KB Output is correct
37 Correct 4 ms 32088 KB Output is correct
38 Correct 4 ms 32088 KB Output is correct
39 Correct 3 ms 31944 KB Output is correct
40 Correct 3 ms 31832 KB Output is correct
41 Correct 3 ms 31832 KB Output is correct
42 Correct 3 ms 31832 KB Output is correct
43 Correct 372 ms 31832 KB Output is correct
44 Correct 563 ms 32088 KB Output is correct
45 Correct 576 ms 31832 KB Output is correct
46 Correct 542 ms 32088 KB Output is correct
47 Correct 528 ms 32088 KB Output is correct
48 Correct 553 ms 32088 KB Output is correct
49 Correct 607 ms 32088 KB Output is correct
50 Correct 551 ms 32088 KB Output is correct
51 Correct 543 ms 32140 KB Output is correct
52 Correct 589 ms 32140 KB Output is correct
53 Correct 486 ms 33112 KB Output is correct
54 Correct 534 ms 32088 KB Output is correct
55 Correct 559 ms 32088 KB Output is correct
56 Correct 548 ms 31832 KB Output is correct
57 Correct 490 ms 31832 KB Output is correct
58 Correct 557 ms 33368 KB Output is correct
59 Correct 557 ms 33624 KB Output is correct
60 Correct 520 ms 33580 KB Output is correct
61 Correct 531 ms 32344 KB Output is correct
62 Correct 563 ms 31832 KB Output is correct
63 Correct 550 ms 31832 KB Output is correct
64 Correct 583 ms 32084 KB Output is correct
65 Correct 271 ms 31832 KB Output is correct
66 Correct 581 ms 32088 KB Output is correct
67 Correct 573 ms 32088 KB Output is correct
68 Correct 540 ms 32088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 4 ms 31832 KB Output is correct
3 Correct 3 ms 31832 KB Output is correct
4 Correct 3 ms 31688 KB Output is correct
5 Correct 4 ms 31832 KB Output is correct
6 Correct 4 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 4 ms 31832 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 31832 KB Output is correct
11 Correct 3 ms 31832 KB Output is correct
12 Correct 4 ms 31832 KB Output is correct
13 Correct 3 ms 31660 KB Output is correct
14 Correct 4 ms 31832 KB Output is correct
15 Correct 4 ms 31832 KB Output is correct
16 Correct 4 ms 31832 KB Output is correct
17 Correct 3 ms 31832 KB Output is correct
18 Correct 4 ms 32088 KB Output is correct
19 Correct 4 ms 32088 KB Output is correct
20 Correct 3 ms 31832 KB Output is correct
21 Correct 4 ms 31828 KB Output is correct
22 Correct 3 ms 31832 KB Output is correct
23 Correct 4 ms 31832 KB Output is correct
24 Correct 4 ms 31832 KB Output is correct
25 Correct 4 ms 31948 KB Output is correct
26 Correct 4 ms 31832 KB Output is correct
27 Correct 3 ms 31832 KB Output is correct
28 Correct 4 ms 31832 KB Output is correct
29 Correct 4 ms 31832 KB Output is correct
30 Correct 3 ms 31832 KB Output is correct
31 Correct 4 ms 32088 KB Output is correct
32 Correct 4 ms 31832 KB Output is correct
33 Correct 4 ms 31832 KB Output is correct
34 Correct 3 ms 31832 KB Output is correct
35 Correct 4 ms 31832 KB Output is correct
36 Correct 4 ms 32088 KB Output is correct
37 Correct 4 ms 32088 KB Output is correct
38 Correct 4 ms 32088 KB Output is correct
39 Correct 3 ms 31944 KB Output is correct
40 Correct 3 ms 31832 KB Output is correct
41 Correct 3 ms 31832 KB Output is correct
42 Correct 3 ms 31832 KB Output is correct
43 Correct 349 ms 33808 KB Output is correct
44 Correct 575 ms 35928 KB Output is correct
45 Correct 581 ms 35928 KB Output is correct
46 Correct 581 ms 35920 KB Output is correct
47 Correct 497 ms 33880 KB Output is correct
48 Correct 647 ms 35928 KB Output is correct
49 Correct 574 ms 35984 KB Output is correct
50 Correct 598 ms 35980 KB Output is correct
51 Correct 251 ms 31832 KB Output is correct
52 Correct 561 ms 32088 KB Output is correct
53 Correct 572 ms 32088 KB Output is correct
54 Correct 513 ms 32088 KB Output is correct
55 Correct 618 ms 37464 KB Output is correct
56 Correct 619 ms 37456 KB Output is correct
57 Correct 631 ms 37360 KB Output is correct
58 Correct 491 ms 37456 KB Output is correct
59 Correct 618 ms 65560 KB Output is correct
60 Correct 663 ms 65616 KB Output is correct
61 Correct 372 ms 31832 KB Output is correct
62 Correct 563 ms 32088 KB Output is correct
63 Correct 576 ms 31832 KB Output is correct
64 Correct 542 ms 32088 KB Output is correct
65 Correct 528 ms 32088 KB Output is correct
66 Correct 553 ms 32088 KB Output is correct
67 Correct 607 ms 32088 KB Output is correct
68 Correct 551 ms 32088 KB Output is correct
69 Correct 543 ms 32140 KB Output is correct
70 Correct 589 ms 32140 KB Output is correct
71 Correct 486 ms 33112 KB Output is correct
72 Correct 534 ms 32088 KB Output is correct
73 Correct 559 ms 32088 KB Output is correct
74 Correct 548 ms 31832 KB Output is correct
75 Correct 490 ms 31832 KB Output is correct
76 Correct 557 ms 33368 KB Output is correct
77 Correct 557 ms 33624 KB Output is correct
78 Correct 520 ms 33580 KB Output is correct
79 Correct 531 ms 32344 KB Output is correct
80 Correct 563 ms 31832 KB Output is correct
81 Correct 550 ms 31832 KB Output is correct
82 Correct 583 ms 32084 KB Output is correct
83 Correct 271 ms 31832 KB Output is correct
84 Correct 581 ms 32088 KB Output is correct
85 Correct 573 ms 32088 KB Output is correct
86 Correct 540 ms 32088 KB Output is correct
87 Correct 3 ms 31832 KB Output is correct
88 Correct 361 ms 36972 KB Output is correct
89 Correct 578 ms 35928 KB Output is correct
90 Correct 631 ms 35672 KB Output is correct
91 Correct 561 ms 37464 KB Output is correct
92 Correct 635 ms 37456 KB Output is correct
93 Correct 670 ms 37452 KB Output is correct
94 Correct 673 ms 37464 KB Output is correct
95 Correct 570 ms 37688 KB Output is correct
96 Correct 560 ms 36836 KB Output is correct
97 Correct 608 ms 36812 KB Output is correct
98 Correct 534 ms 60752 KB Output is correct
99 Correct 670 ms 37460 KB Output is correct
100 Correct 594 ms 35928 KB Output is correct
101 Correct 618 ms 35672 KB Output is correct
102 Correct 588 ms 34648 KB Output is correct
103 Correct 628 ms 65692 KB Output is correct
104 Correct 684 ms 65228 KB Output is correct
105 Correct 638 ms 65224 KB Output is correct
106 Correct 637 ms 41556 KB Output is correct
107 Correct 614 ms 34904 KB Output is correct
108 Correct 624 ms 34896 KB Output is correct
109 Correct 633 ms 34896 KB Output is correct