Submission #791658

#TimeUsernameProblemLanguageResultExecution timeMemory
791658firewaterDigital Circuit (IOI22_circuit)C++17
2 / 100
501 ms20420 KiB
#include "circuit.h" #include<cstdio> #include<vector> #include<cstring> //#include<cassert> #include<iostream> #include<algorithm> #define ll long long #define MX 202300 #define mod 1000002022 using namespace std; ll n,m,a[MX],b[MX],sz[MX]; vector<ll>to[MX],pre[MX],suf[MX]; struct Tree { #define ls x*2 #define rs x*2+1 ll c[MX<<2],s[MX<<2],lazy[MX<<2]; void push_up(int x) { c[x]=c[ls]+c[rs]; s[x]=s[ls]+s[rs]; return; } void get(int x) { s[x]=(c[x]-s[x]+mod)%mod; lazy[x]^=1; return; } void push_down(int x) { if(lazy[x]){ get(ls); get(rs); lazy[x]=0; } return; } void build(int x,int l,int r) { if(l==r){ c[x]=a[l]; s[x]=a[l]*b[l]; return; } int mid=l+r>>1; build(ls,l,mid); build(rs,mid+1,r); push_up(x); return; } void change(int x,int L,int R,int l,int r) { if(L==l&&R==r){ get(x); return; } push_down(x); int mid=L+R>>1; if(r<=mid)change(ls,L,mid,l,r); else if(l>mid)change(rs,mid+1,R,l,r); else change(ls,L,mid,l,mid),change(rs,mid+1,R,mid+1,r); push_up(x); return; } }T; void dfs(int x) { sz[x]=to[x].size(); if(!sz[x])sz[x]=1; int sav=to[x].size(); for(int i=0;i<sav;++i){ dfs(to[x][i]); sz[x]=sz[x]*sz[to[x][i]]%mod; } return; } void dfs1(int x,int num) { if(x>=n)a[x-n+1]=num; int sav=to[x].size(); for(int i=0;i<sav;++i){ pre[x].push_back(sz[to[x][i]]); suf[x].push_back(sz[to[x][i]]); } for(int i=1;i<sav;++i) pre[x][i]=pre[x][i]*pre[x][i-1]%mod; for(int i=sav-2;i>=0;--i) suf[x][i]=suf[x][i]*suf[x][i+1]%mod; for(int i=0;i<sav;++i) dfs1(to[x][i],(i>0?pre[x][i-1]:1)*(i<sav-1?suf[x][i+1]:1)%mod*num%mod); return; } 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) to[P[i]].push_back(i); for(int i=1;i<=m;++i) b[i]=A[i-1]; dfs(0); dfs1(0,1); T.build(1,1,m); return; } int count_ways(int L, int R) { L=L-n+1; R=R-n+1; T.change(1,1,m,L,R); return T.s[1]; } //int main() { // int N, M, Q; // assert(3 == scanf("%d %d %d", &N, &M, &Q)); // std::vector<int> P(N + M), A(M); // for (int i = 0; i < N + M; ++i) { // assert(1 == scanf("%d", &P[i])); // } // for (int j = 0; j < M; ++j) { // assert(1 == scanf("%d", &A[j])); // } // init(N, M, P, A); // // for (int i = 0; i < Q; ++i) { // int L, R; // assert(2 == scanf("%d %d", &L, &R)); // printf("%d\n", count_ways(L, R)); // } // return 0; //}

Compilation message (stderr)

circuit.cpp: In member function 'void Tree::build(int, int, int)':
circuit.cpp:48:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |   int mid=l+r>>1;
      |           ~^~
circuit.cpp: In member function 'void Tree::change(int, int, int, int, int)':
circuit.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |   int mid=L+R>>1;
      |           ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...