Submission #832121

# Submission time Handle Problem Language Result Execution time Memory
832121 2023-08-21T01:46:55 Z Username4132 Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 7496 KB
#include "circuit.h"
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back

const int MAXN = 100010;
int n, m, arr[MAXN];
int cal[MAXN][3];
int coef[MAXN];
vector<int> g[MAXN];

int crt(int x, int y, int z){
    return (500001011LL*x + 143498048LL*y + 356502964LL*z)%1000002022;
}

ll ex(ll b, int e, int mod){
  ll ret=1;
  while(e>0){
    if(e&1) ret=(ret*b)%mod;
    b=(b*b)%mod;
    e>>=1;
  }
  return ret;
}

void dfs(int v, int mod, int prod, int cnt, int ind){
  if(v>=n){
    cal[v-n][ind]=cnt>0? 0 : prod;
    return;
  }
  int x = (int)g[v].size();
  while(!(x%mod)) x/=mod, --cnt;
  prod = (prod*ex(x, mod-2, mod))%mod;
  for(int to:g[v]) dfs(to, mod, prod, cnt, ind);
}

void init(int N, int M, vector<int> P, vector<int> A) {
  n=N, m=M;
  forn(i, n+m) g[P[i]].PB(i);
  vector<int> fact = {2, 223, 2242157};
  forn(ind, 3){
    int pr = fact[ind];
    int cnt=0;
    ll prod=1;
    forn(i, n){
      int x = (int)g[i].size();
      while(!(x%pr)) x/=pr, cnt++;
      prod=(prod*x)%pr;
    }
    dfs(0, pr, prod, cnt, ind);
  }
  forn(i, m) coef[i] = crt(cal[i][0], cal[i][1], cal[i][2]);
  forn(i, m) arr[i]=A[i];
}

int count_ways(int L, int R) {
  forsn(i, L-n, R+1-n) arr[i]^=1;
  ll sum=0;
  forn(i, m) sum+=arr[i]*coef[i];
  return sum%1000002022;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 1 ms 2640 KB Output is correct
7 Correct 1 ms 2640 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2768 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 1 ms 2640 KB Output is correct
7 Correct 1 ms 2640 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 1 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2768 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 1 ms 2640 KB Output is correct
30 Correct 1 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2804 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 1 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1937 ms 5064 KB Output is correct
2 Execution timed out 3030 ms 7496 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1937 ms 5064 KB Output is correct
2 Execution timed out 3030 ms 7496 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2768 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 1937 ms 5064 KB Output is correct
14 Execution timed out 3030 ms 7496 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 1 ms 2640 KB Output is correct
7 Correct 1 ms 2640 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 1 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2768 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 1 ms 2640 KB Output is correct
30 Correct 1 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2804 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 1 ms 2640 KB Output is correct
43 Correct 603 ms 2764 KB Output is correct
44 Correct 950 ms 2780 KB Output is correct
45 Correct 907 ms 2788 KB Output is correct
46 Correct 1061 ms 3024 KB Output is correct
47 Correct 1024 ms 3024 KB Output is correct
48 Correct 1067 ms 3024 KB Output is correct
49 Correct 1116 ms 3024 KB Output is correct
50 Correct 1229 ms 3024 KB Output is correct
51 Correct 1224 ms 2768 KB Output is correct
52 Correct 875 ms 2784 KB Output is correct
53 Correct 789 ms 3152 KB Output is correct
54 Correct 1118 ms 3024 KB Output is correct
55 Correct 1067 ms 2896 KB Output is correct
56 Correct 1112 ms 2896 KB Output is correct
57 Correct 1040 ms 2768 KB Output is correct
58 Correct 1046 ms 3280 KB Output is correct
59 Correct 1097 ms 3380 KB Output is correct
60 Correct 1250 ms 3376 KB Output is correct
61 Correct 782 ms 2896 KB Output is correct
62 Correct 879 ms 2784 KB Output is correct
63 Correct 908 ms 2768 KB Output is correct
64 Correct 1077 ms 2768 KB Output is correct
65 Correct 458 ms 2784 KB Output is correct
66 Correct 1044 ms 2896 KB Output is correct
67 Correct 1030 ms 2896 KB Output is correct
68 Correct 1215 ms 2956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 1 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 1 ms 2640 KB Output is correct
6 Correct 1 ms 2640 KB Output is correct
7 Correct 1 ms 2640 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 1 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2768 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 1 ms 2640 KB Output is correct
30 Correct 1 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 1 ms 2640 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2804 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 1 ms 2640 KB Output is correct
43 Correct 1937 ms 5064 KB Output is correct
44 Execution timed out 3030 ms 7496 KB Time limit exceeded
45 Halted 0 ms 0 KB -