Submission #1057592

# Submission time Handle Problem Language Result Execution time Memory
1057592 2024-08-13T22:47:45 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
100 / 100
664 ms 65620 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 3 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 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 3 ms 31688 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 4 ms 31832 KB Output is correct
4 Correct 4 ms 31692 KB Output is correct
5 Correct 4 ms 31832 KB Output is correct
6 Correct 5 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 5 ms 31832 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 32188 KB Output is correct
11 Correct 5 ms 32088 KB Output is correct
12 Correct 5 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 3 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 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 3 ms 31688 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 31832 KB Output is correct
11 Correct 4 ms 31832 KB Output is correct
12 Correct 4 ms 31692 KB Output is correct
13 Correct 4 ms 31832 KB Output is correct
14 Correct 5 ms 31832 KB Output is correct
15 Correct 4 ms 31832 KB Output is correct
16 Correct 5 ms 31832 KB Output is correct
17 Correct 4 ms 31832 KB Output is correct
18 Correct 4 ms 32188 KB Output is correct
19 Correct 5 ms 32088 KB Output is correct
20 Correct 5 ms 31832 KB Output is correct
21 Correct 4 ms 31832 KB Output is correct
22 Correct 4 ms 31832 KB Output is correct
23 Correct 3 ms 31832 KB Output is correct
24 Correct 4 ms 31700 KB Output is correct
25 Correct 4 ms 31832 KB Output is correct
26 Correct 4 ms 31940 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 4 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 4 ms 31856 KB Output is correct
35 Correct 3 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 4 ms 31832 KB Output is correct
40 Correct 3 ms 31916 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 391 ms 33880 KB Output is correct
2 Correct 585 ms 35920 KB Output is correct
3 Correct 582 ms 35928 KB Output is correct
4 Correct 584 ms 36180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 33880 KB Output is correct
2 Correct 585 ms 35920 KB Output is correct
3 Correct 582 ms 35928 KB Output is correct
4 Correct 584 ms 36180 KB Output is correct
5 Correct 433 ms 33880 KB Output is correct
6 Correct 614 ms 35928 KB Output is correct
7 Correct 628 ms 35920 KB Output is correct
8 Correct 585 ms 35920 KB Output is correct
9 Correct 270 ms 31832 KB Output is correct
10 Correct 551 ms 32088 KB Output is correct
11 Correct 538 ms 32088 KB Output is correct
12 Correct 508 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 4 ms 31832 KB Output is correct
4 Correct 4 ms 31692 KB Output is correct
5 Correct 4 ms 31832 KB Output is correct
6 Correct 5 ms 31832 KB Output is correct
7 Correct 4 ms 31832 KB Output is correct
8 Correct 5 ms 31832 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 32188 KB Output is correct
11 Correct 5 ms 32088 KB Output is correct
12 Correct 5 ms 31832 KB Output is correct
13 Correct 391 ms 33880 KB Output is correct
14 Correct 585 ms 35920 KB Output is correct
15 Correct 582 ms 35928 KB Output is correct
16 Correct 584 ms 36180 KB Output is correct
17 Correct 433 ms 33880 KB Output is correct
18 Correct 614 ms 35928 KB Output is correct
19 Correct 628 ms 35920 KB Output is correct
20 Correct 585 ms 35920 KB Output is correct
21 Correct 270 ms 31832 KB Output is correct
22 Correct 551 ms 32088 KB Output is correct
23 Correct 538 ms 32088 KB Output is correct
24 Correct 508 ms 32088 KB Output is correct
25 Correct 641 ms 37488 KB Output is correct
26 Correct 654 ms 37456 KB Output is correct
27 Correct 664 ms 37456 KB Output is correct
28 Correct 507 ms 37344 KB Output is correct
29 Correct 644 ms 65616 KB Output is correct
30 Correct 659 ms 65620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 3 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 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 3 ms 31688 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 31832 KB Output is correct
11 Correct 4 ms 31832 KB Output is correct
12 Correct 4 ms 31692 KB Output is correct
13 Correct 4 ms 31832 KB Output is correct
14 Correct 5 ms 31832 KB Output is correct
15 Correct 4 ms 31832 KB Output is correct
16 Correct 5 ms 31832 KB Output is correct
17 Correct 4 ms 31832 KB Output is correct
18 Correct 4 ms 32188 KB Output is correct
19 Correct 5 ms 32088 KB Output is correct
20 Correct 5 ms 31832 KB Output is correct
21 Correct 4 ms 31832 KB Output is correct
22 Correct 4 ms 31832 KB Output is correct
23 Correct 3 ms 31832 KB Output is correct
24 Correct 4 ms 31700 KB Output is correct
25 Correct 4 ms 31832 KB Output is correct
26 Correct 4 ms 31940 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 4 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 4 ms 31856 KB Output is correct
35 Correct 3 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 4 ms 31832 KB Output is correct
40 Correct 3 ms 31916 KB Output is correct
41 Correct 3 ms 31832 KB Output is correct
42 Correct 3 ms 31832 KB Output is correct
43 Correct 382 ms 31832 KB Output is correct
44 Correct 559 ms 32088 KB Output is correct
45 Correct 578 ms 31832 KB Output is correct
46 Correct 534 ms 32088 KB Output is correct
47 Correct 572 ms 32088 KB Output is correct
48 Correct 556 ms 32088 KB Output is correct
49 Correct 499 ms 32088 KB Output is correct
50 Correct 524 ms 32088 KB Output is correct
51 Correct 524 ms 32132 KB Output is correct
52 Correct 535 ms 32132 KB Output is correct
53 Correct 486 ms 33112 KB Output is correct
54 Correct 592 ms 32088 KB Output is correct
55 Correct 557 ms 32088 KB Output is correct
56 Correct 518 ms 31832 KB Output is correct
57 Correct 537 ms 31828 KB Output is correct
58 Correct 523 ms 33368 KB Output is correct
59 Correct 546 ms 33624 KB Output is correct
60 Correct 567 ms 33580 KB Output is correct
61 Correct 565 ms 32344 KB Output is correct
62 Correct 518 ms 31832 KB Output is correct
63 Correct 525 ms 31832 KB Output is correct
64 Correct 577 ms 31832 KB Output is correct
65 Correct 283 ms 31832 KB Output is correct
66 Correct 518 ms 32088 KB Output is correct
67 Correct 528 ms 32088 KB Output is correct
68 Correct 491 ms 32088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 31832 KB Output is correct
2 Correct 3 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 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 3 ms 31688 KB Output is correct
9 Correct 4 ms 31832 KB Output is correct
10 Correct 4 ms 31832 KB Output is correct
11 Correct 4 ms 31832 KB Output is correct
12 Correct 4 ms 31692 KB Output is correct
13 Correct 4 ms 31832 KB Output is correct
14 Correct 5 ms 31832 KB Output is correct
15 Correct 4 ms 31832 KB Output is correct
16 Correct 5 ms 31832 KB Output is correct
17 Correct 4 ms 31832 KB Output is correct
18 Correct 4 ms 32188 KB Output is correct
19 Correct 5 ms 32088 KB Output is correct
20 Correct 5 ms 31832 KB Output is correct
21 Correct 4 ms 31832 KB Output is correct
22 Correct 4 ms 31832 KB Output is correct
23 Correct 3 ms 31832 KB Output is correct
24 Correct 4 ms 31700 KB Output is correct
25 Correct 4 ms 31832 KB Output is correct
26 Correct 4 ms 31940 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 4 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 4 ms 31856 KB Output is correct
35 Correct 3 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 4 ms 31832 KB Output is correct
40 Correct 3 ms 31916 KB Output is correct
41 Correct 3 ms 31832 KB Output is correct
42 Correct 3 ms 31832 KB Output is correct
43 Correct 391 ms 33880 KB Output is correct
44 Correct 585 ms 35920 KB Output is correct
45 Correct 582 ms 35928 KB Output is correct
46 Correct 584 ms 36180 KB Output is correct
47 Correct 433 ms 33880 KB Output is correct
48 Correct 614 ms 35928 KB Output is correct
49 Correct 628 ms 35920 KB Output is correct
50 Correct 585 ms 35920 KB Output is correct
51 Correct 270 ms 31832 KB Output is correct
52 Correct 551 ms 32088 KB Output is correct
53 Correct 538 ms 32088 KB Output is correct
54 Correct 508 ms 32088 KB Output is correct
55 Correct 641 ms 37488 KB Output is correct
56 Correct 654 ms 37456 KB Output is correct
57 Correct 664 ms 37456 KB Output is correct
58 Correct 507 ms 37344 KB Output is correct
59 Correct 644 ms 65616 KB Output is correct
60 Correct 659 ms 65620 KB Output is correct
61 Correct 382 ms 31832 KB Output is correct
62 Correct 559 ms 32088 KB Output is correct
63 Correct 578 ms 31832 KB Output is correct
64 Correct 534 ms 32088 KB Output is correct
65 Correct 572 ms 32088 KB Output is correct
66 Correct 556 ms 32088 KB Output is correct
67 Correct 499 ms 32088 KB Output is correct
68 Correct 524 ms 32088 KB Output is correct
69 Correct 524 ms 32132 KB Output is correct
70 Correct 535 ms 32132 KB Output is correct
71 Correct 486 ms 33112 KB Output is correct
72 Correct 592 ms 32088 KB Output is correct
73 Correct 557 ms 32088 KB Output is correct
74 Correct 518 ms 31832 KB Output is correct
75 Correct 537 ms 31828 KB Output is correct
76 Correct 523 ms 33368 KB Output is correct
77 Correct 546 ms 33624 KB Output is correct
78 Correct 567 ms 33580 KB Output is correct
79 Correct 565 ms 32344 KB Output is correct
80 Correct 518 ms 31832 KB Output is correct
81 Correct 525 ms 31832 KB Output is correct
82 Correct 577 ms 31832 KB Output is correct
83 Correct 283 ms 31832 KB Output is correct
84 Correct 518 ms 32088 KB Output is correct
85 Correct 528 ms 32088 KB Output is correct
86 Correct 491 ms 32088 KB Output is correct
87 Correct 4 ms 31832 KB Output is correct
88 Correct 393 ms 36964 KB Output is correct
89 Correct 596 ms 35984 KB Output is correct
90 Correct 593 ms 35672 KB Output is correct
91 Correct 593 ms 37464 KB Output is correct
92 Correct 660 ms 37460 KB Output is correct
93 Correct 643 ms 37456 KB Output is correct
94 Correct 638 ms 37656 KB Output is correct
95 Correct 630 ms 37688 KB Output is correct
96 Correct 501 ms 36812 KB Output is correct
97 Correct 590 ms 36812 KB Output is correct
98 Correct 547 ms 60752 KB Output is correct
99 Correct 629 ms 37572 KB Output is correct
100 Correct 595 ms 35928 KB Output is correct
101 Correct 621 ms 35672 KB Output is correct
102 Correct 639 ms 34648 KB Output is correct
103 Correct 634 ms 65568 KB Output is correct
104 Correct 618 ms 65228 KB Output is correct
105 Correct 590 ms 65232 KB Output is correct
106 Correct 614 ms 41560 KB Output is correct
107 Correct 622 ms 34920 KB Output is correct
108 Correct 602 ms 34904 KB Output is correct
109 Correct 635 ms 34648 KB Output is correct