# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078473 | 2024-08-27T17:57:27 Z | allin27x | Digital Circuit (IOI22_circuit) | C++17 | 3000 ms | 14424 KB |
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1000002022; const int MAXN = 100007; int ar[MAXN]; int n,m; vector<int> ch[2*MAXN]; int mlt[2*MAXN]; int sgt[4*MAXN]; int rel[MAXN]; int res = 0; void update(int i, int v) { for (sgt[i+=2*MAXN]=v; i>1; i>>=1) sgt[i>>1] = (sgt[i] * sgt[i^1]) % mod; } int query(int l, int r) { int res = 1; for (l+=2*MAXN, r+=2*MAXN+1; l<r; l>>=1, r>>=1) { if (l&1) res *= sgt[l++], res %= mod; if (r&1) res *= sgt[--r], res %= mod; } return res; } int dfs0(int i) { vector<int> vl; for (int c: ch[i]) vl.push_back(dfs0(c)); if (vl.size() <= 1) return 1; int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod; for (int i=0; i<vl.size(); i++) update(i, vl[i]); for (int j=0; j<vl.size(); j++) { mlt[ch[i][j]] = (query(0, j-1)) * query(j+1, vl.size()-1) % mod; } return ans; } void dfs1(int i, int p) { if (ch[i].size() == 0) { rel[i-n] = (p*mlt[i]) % mod; } else { for (int c: ch[i]) { dfs1(c, (p*mlt[i]) % mod); } } } void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) { for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M; for (int i=1; i<M+N; i++) ch[P[i]].push_back(i); for (int i=0; i<4*MAXN; i++) sgt[i] = 1; for (int i=0; i<2*MAXN; i++) mlt[i] = 1; dfs0(0); dfs1(0,1); for (int i=0; i<M; i++) if (A[i]) res += rel[i]; } signed count_ways(signed L, signed R) { L-=n; R-=n; for (int i=L; i<=R; i++) { if (ar[i]) { res -= rel[i]; res %= mod; res += mod; res %= mod; ar[i] = 0; } else { res += rel[i]; res %= mod; ar[i] = 1; } } return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9816 KB | Output is correct |
2 | Correct | 4 ms | 9816 KB | Output is correct |
3 | Correct | 4 ms | 9816 KB | Output is correct |
4 | Correct | 4 ms | 9740 KB | Output is correct |
5 | Correct | 5 ms | 9816 KB | Output is correct |
6 | Correct | 4 ms | 9816 KB | Output is correct |
7 | Correct | 4 ms | 9816 KB | Output is correct |
8 | Correct | 4 ms | 9816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9816 KB | Output is correct |
2 | Correct | 4 ms | 9816 KB | Output is correct |
3 | Correct | 4 ms | 9676 KB | Output is correct |
4 | Correct | 5 ms | 9816 KB | Output is correct |
5 | Correct | 4 ms | 9816 KB | Output is correct |
6 | Correct | 4 ms | 9776 KB | Output is correct |
7 | Correct | 4 ms | 9816 KB | Output is correct |
8 | Correct | 4 ms | 9816 KB | Output is correct |
9 | Correct | 5 ms | 9816 KB | Output is correct |
10 | Correct | 5 ms | 9816 KB | Output is correct |
11 | Correct | 5 ms | 9816 KB | Output is correct |
12 | Correct | 5 ms | 9680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9816 KB | Output is correct |
2 | Correct | 4 ms | 9816 KB | Output is correct |
3 | Correct | 4 ms | 9816 KB | Output is correct |
4 | Correct | 4 ms | 9740 KB | Output is correct |
5 | Correct | 5 ms | 9816 KB | Output is correct |
6 | Correct | 4 ms | 9816 KB | Output is correct |
7 | Correct | 4 ms | 9816 KB | Output is correct |
8 | Correct | 4 ms | 9816 KB | Output is correct |
9 | Correct | 4 ms | 9816 KB | Output is correct |
10 | Correct | 4 ms | 9816 KB | Output is correct |
11 | Correct | 4 ms | 9676 KB | Output is correct |
12 | Correct | 5 ms | 9816 KB | Output is correct |
13 | Correct | 4 ms | 9816 KB | Output is correct |
14 | Correct | 4 ms | 9776 KB | Output is correct |
15 | Correct | 4 ms | 9816 KB | Output is correct |
16 | Correct | 4 ms | 9816 KB | Output is correct |
17 | Correct | 5 ms | 9816 KB | Output is correct |
18 | Correct | 5 ms | 9816 KB | Output is correct |
19 | Correct | 5 ms | 9816 KB | Output is correct |
20 | Correct | 5 ms | 9680 KB | Output is correct |
21 | Incorrect | 5 ms | 9816 KB | 1st lines differ - on the 1st token, expected: '759476520', found: '209535362' |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 460 ms | 12120 KB | Output is correct |
2 | Correct | 672 ms | 14424 KB | Output is correct |
3 | Correct | 630 ms | 14416 KB | Output is correct |
4 | Correct | 680 ms | 14380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 460 ms | 12120 KB | Output is correct |
2 | Correct | 672 ms | 14424 KB | Output is correct |
3 | Correct | 630 ms | 14416 KB | Output is correct |
4 | Correct | 680 ms | 14380 KB | Output is correct |
5 | Execution timed out | 3036 ms | 12120 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9816 KB | Output is correct |
2 | Correct | 4 ms | 9816 KB | Output is correct |
3 | Correct | 4 ms | 9676 KB | Output is correct |
4 | Correct | 5 ms | 9816 KB | Output is correct |
5 | Correct | 4 ms | 9816 KB | Output is correct |
6 | Correct | 4 ms | 9776 KB | Output is correct |
7 | Correct | 4 ms | 9816 KB | Output is correct |
8 | Correct | 4 ms | 9816 KB | Output is correct |
9 | Correct | 5 ms | 9816 KB | Output is correct |
10 | Correct | 5 ms | 9816 KB | Output is correct |
11 | Correct | 5 ms | 9816 KB | Output is correct |
12 | Correct | 5 ms | 9680 KB | Output is correct |
13 | Correct | 460 ms | 12120 KB | Output is correct |
14 | Correct | 672 ms | 14424 KB | Output is correct |
15 | Correct | 630 ms | 14416 KB | Output is correct |
16 | Correct | 680 ms | 14380 KB | Output is correct |
17 | Execution timed out | 3036 ms | 12120 KB | Time limit exceeded |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9816 KB | Output is correct |
2 | Correct | 4 ms | 9816 KB | Output is correct |
3 | Correct | 4 ms | 9816 KB | Output is correct |
4 | Correct | 4 ms | 9740 KB | Output is correct |
5 | Correct | 5 ms | 9816 KB | Output is correct |
6 | Correct | 4 ms | 9816 KB | Output is correct |
7 | Correct | 4 ms | 9816 KB | Output is correct |
8 | Correct | 4 ms | 9816 KB | Output is correct |
9 | Correct | 4 ms | 9816 KB | Output is correct |
10 | Correct | 4 ms | 9816 KB | Output is correct |
11 | Correct | 4 ms | 9676 KB | Output is correct |
12 | Correct | 5 ms | 9816 KB | Output is correct |
13 | Correct | 4 ms | 9816 KB | Output is correct |
14 | Correct | 4 ms | 9776 KB | Output is correct |
15 | Correct | 4 ms | 9816 KB | Output is correct |
16 | Correct | 4 ms | 9816 KB | Output is correct |
17 | Correct | 5 ms | 9816 KB | Output is correct |
18 | Correct | 5 ms | 9816 KB | Output is correct |
19 | Correct | 5 ms | 9816 KB | Output is correct |
20 | Correct | 5 ms | 9680 KB | Output is correct |
21 | Incorrect | 5 ms | 9816 KB | 1st lines differ - on the 1st token, expected: '759476520', found: '209535362' |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9816 KB | Output is correct |
2 | Correct | 4 ms | 9816 KB | Output is correct |
3 | Correct | 4 ms | 9816 KB | Output is correct |
4 | Correct | 4 ms | 9740 KB | Output is correct |
5 | Correct | 5 ms | 9816 KB | Output is correct |
6 | Correct | 4 ms | 9816 KB | Output is correct |
7 | Correct | 4 ms | 9816 KB | Output is correct |
8 | Correct | 4 ms | 9816 KB | Output is correct |
9 | Correct | 4 ms | 9816 KB | Output is correct |
10 | Correct | 4 ms | 9816 KB | Output is correct |
11 | Correct | 4 ms | 9676 KB | Output is correct |
12 | Correct | 5 ms | 9816 KB | Output is correct |
13 | Correct | 4 ms | 9816 KB | Output is correct |
14 | Correct | 4 ms | 9776 KB | Output is correct |
15 | Correct | 4 ms | 9816 KB | Output is correct |
16 | Correct | 4 ms | 9816 KB | Output is correct |
17 | Correct | 5 ms | 9816 KB | Output is correct |
18 | Correct | 5 ms | 9816 KB | Output is correct |
19 | Correct | 5 ms | 9816 KB | Output is correct |
20 | Correct | 5 ms | 9680 KB | Output is correct |
21 | Incorrect | 5 ms | 9816 KB | 1st lines differ - on the 1st token, expected: '759476520', found: '209535362' |
22 | Halted | 0 ms | 0 KB | - |