Submission #1070574

#TimeUsernameProblemLanguageResultExecution timeMemory
1070574panDigital Circuit (IOI22_circuit)C++17
100 / 100
877 ms35912 KiB
#include <bits/stdc++.h> //#include "bits_stdc++.h" //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%lld", &x); #define input2(x, y) scanf("%lld%lld", &x, &y); #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a); #define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define all(x) x.begin(), x.end() #define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define FOR(i, x, n) for (ll i =x; i<=n; ++i) #define RFOR(i, x, n) for (ll i =x; i>=n; --i) using namespace std; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> //#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<pi, pi> piii; ll const mod = 1000002022; ll n, m; ll a[200005], child[200005], path[200005], sum[200005]; vector<ll> adj[200005]; // RURQ Segment Tree struct node{ int s, e, m; ll val, tot; ll lazy; node *l, *r; node (int S, int E) { s = S, e = E, m = (s+e)/2; lazy = 0; if(s != e) { l = new node(s, m); r = new node(m+1, e); val = (l->val + r->val)%mod; tot = (l->tot + r->tot)%mod; } else { val = ((a[s])?path[n+s]%mod:0); tot = path[n+s]%mod; } } void propogate() { if (lazy==0) return; val = (tot - val + mod)%mod; if (s != e){ l->lazy^=lazy; r->lazy^=lazy; } lazy=0; } void update(int S, int E) { propogate(); if(s==S && e==E){ lazy^=1;} else{ if(E <= m) l->update(S, E); else if (m < S) r->update(S, E); else l->update(S, m),r->update(m+1, E); l->propogate(),r->propogate(); val = (l->val + r->val)%mod; tot = (l->tot + r->tot)%mod; } } ll query() { propogate(); return val; } } *root; void dfs(ll x) { if (x >= n){ sum[x] = 1; return;} sum[x] = child[x]; for (ll u: adj[x]) { dfs(u); sum[x] = (sum[u] * sum[x])%mod; } } void dfs2(ll x) { //show(x); if (x >= n) return; vector<ll> dp(child[x], path[x]); ll ps = 1; for (ll i=0; i<child[x]; ++i) { dp[i] = (dp[i] * ps)%mod; ps = (ps * sum[adj[x][i]])%mod; } ll ss = 1; for (ll i=child[x]-1; i>=0; --i) { dp[i] = (dp[i] * ss)%mod; ss = (ss * sum[adj[x][i]])%mod; } for (ll i=0; i<child[x]; ++i) { path[adj[x][i]] = dp[i]; dfs2(adj[x][i]); } } void init(int N, int M, std::vector<int> P, std::vector<int> A) { n = N, m = M; for (ll i=0; i<m; ++i) a[i] = A[i]; for (ll i=0; i<n+m; ++i) child[i] =0; for (ll i=1; i<n+m; ++i) {adj[P[i]].pb(i); child[P[i]]++;} dfs(0); path[0] = 1; dfs2(0); //for (ll i=0; i<=n+m-1; ++i) show(path[i]); root = new node(0, m-1); } int count_ways(int L, int R) { root->update(L-n, R-n); return root->query()%mod; }
#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...