답안 #1068704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068704 2024-08-21T11:25:32 Z beaconmc 디지털 회로 (IOI22_circuit) C++17
89 / 100
3000 ms 35944 KB
    #include <bits/stdc++.h>
     
    typedef long long ll;
    using namespace std;
     
     
    #define FOR(i, x, y) for(ll i=x; i<y; i++)
    #define FORNEG(i, x, y) for(ll i=x; i>y; i--)
    #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
     
     
    basic_string<ll> edges[200001];
    ll possible[200001];
    ll contrib[200001];
    ll dps[200001];
    vector<int> p;
     
     
     
     
    int initdfs(ll a){
      if (edges[a].size() == 0) return possible[a] = 1;
     
      ll temp = 1;
      for (auto&i : edges[a]){
        temp *= initdfs(i);
        temp %= 1000002022;
      }
      temp *= edges[a].size();
      temp %= 1000002022;
     
     
      return possible[a] = temp;
    }
     
    int dp(ll a){
      if (a==0) return 1;
      if (dps[a] != -1) return dps[a];
     
      ll temp = 1;
     
      for (auto&i : edges[p[a]]){
        if (i != a) temp *= possible[i];
        temp %= 1000002022;
      }
      dps[a] = temp * dp(p[a]) % 1000002022;
      return dps[a];
    }
     
    ll n,m;
     
     
     
    const ll NN = (1<<18);
    ll tree[NN*2];
    ll actual[NN*2];
    ll lazy[NN*2];
     
    int actupd(ll a, ll b, ll val, ll k=1, ll x = 0, ll y = NN-1){
     
      if (b<x || a>y) return actual[k];
      if (a<=x && y<=b){
     
        actual[k] += val;
        actual[k] %= 1000002022;
        return actual[k];
      }
      ll mid = (x+y)/2;
     
     
      actual[k] =  actupd(a,b,val,k*2, x, mid) + actupd(a,b,val,k*2+1, mid+1, y);
      actual[k] %= 1000002022;
     
      return actual[k];
    }
     
     
    void prop(ll k){
      lazy[k*2] += lazy[k];
      lazy[k*2+1] += lazy[k];
      if (lazy[k] %2==1){
        tree[k] = (actual[k] - tree[k]+1000002022)%1000002022;
      }
      lazy[k] = 0;
    }
     
     
    int upd(ll a, ll b, ll k=1, ll x = 0, ll y = NN-1){
      if (b<x || a>y) return lazy[k]%2==0 ? tree[k] : ((actual[k] - tree[k]+1000002022)%1000002022);
      if (a<=x && y<=b){
        lazy[k] += 1;
        return lazy[k]%2==0 ? tree[k] : ((actual[k] - tree[k]+1000002022)%1000002022);
      }
      ll mid = (x+y)/2;
      prop(k);
     
      tree[k] = upd(a,b,k*2, x, mid) + upd(a,b,k*2+1, mid+1, y);
      tree[k] %= 1000002022;
      return lazy[k]%2==0 ? tree[k] : ((actual[k] - tree[k]+1000002022)%1000002022);
    }
     
    void init(int N, int M, std::vector<int> P, std::vector<int> A) {
      FOR(i,0,200001) dps[i] = -1;
      FOR(i,0,NN*2) tree[i] = 0, actual[i] = 0, lazy[i] = 0;
      p = P;
      n = N;
      m = M;
      FOR(i,1,N+M){
        edges[P[i]].push_back(i);
      }
      initdfs(0);
     
     
      FOR(i,N,N+M){
        ll temp = possible[i];
        temp *= dp(i);
        contrib[i] = temp%1000002022;
      }
      FOR(i,n,n+m){
        actupd(i-n+1, i-n+1, contrib[i]);
      }
      FOR(i,0,NN*2) tree[i] = actual[i];
      FOR(i,n,n+m){
        if (A[i-n] == 0){
          upd(i-n+1, i-n+1);
        }
      }
     
     
    }
     
     
     
     
     
    int count_ways(int L, int R) {
      upd(L-n+1, R-n+1);
     
     
      return lazy[1]%2==0 ? tree[1] : ((actual[1] - tree[1]+1000002022)%1000002022);
     
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23640 KB Output is correct
2 Correct 3 ms 23640 KB Output is correct
3 Correct 8 ms 23736 KB Output is correct
4 Correct 8 ms 23640 KB Output is correct
5 Correct 8 ms 23736 KB Output is correct
6 Correct 8 ms 23736 KB Output is correct
7 Correct 8 ms 23640 KB Output is correct
8 Correct 8 ms 23640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23640 KB Output is correct
2 Correct 4 ms 23640 KB Output is correct
3 Correct 4 ms 23640 KB Output is correct
4 Correct 4 ms 23640 KB Output is correct
5 Correct 4 ms 23640 KB Output is correct
6 Correct 4 ms 23732 KB Output is correct
7 Correct 4 ms 23640 KB Output is correct
8 Correct 4 ms 23640 KB Output is correct
9 Correct 5 ms 23640 KB Output is correct
10 Correct 4 ms 23640 KB Output is correct
11 Correct 4 ms 23640 KB Output is correct
12 Correct 3 ms 23640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23640 KB Output is correct
2 Correct 3 ms 23640 KB Output is correct
3 Correct 8 ms 23736 KB Output is correct
4 Correct 8 ms 23640 KB Output is correct
5 Correct 8 ms 23736 KB Output is correct
6 Correct 8 ms 23736 KB Output is correct
7 Correct 8 ms 23640 KB Output is correct
8 Correct 8 ms 23640 KB Output is correct
9 Correct 3 ms 23640 KB Output is correct
10 Correct 4 ms 23640 KB Output is correct
11 Correct 4 ms 23640 KB Output is correct
12 Correct 4 ms 23640 KB Output is correct
13 Correct 4 ms 23640 KB Output is correct
14 Correct 4 ms 23732 KB Output is correct
15 Correct 4 ms 23640 KB Output is correct
16 Correct 4 ms 23640 KB Output is correct
17 Correct 5 ms 23640 KB Output is correct
18 Correct 4 ms 23640 KB Output is correct
19 Correct 4 ms 23640 KB Output is correct
20 Correct 3 ms 23640 KB Output is correct
21 Correct 4 ms 23640 KB Output is correct
22 Correct 3 ms 23640 KB Output is correct
23 Correct 4 ms 23640 KB Output is correct
24 Correct 4 ms 23640 KB Output is correct
25 Correct 3 ms 23640 KB Output is correct
26 Correct 4 ms 23640 KB Output is correct
27 Correct 4 ms 23720 KB Output is correct
28 Correct 3 ms 23640 KB Output is correct
29 Correct 9 ms 23712 KB Output is correct
30 Correct 8 ms 23640 KB Output is correct
31 Correct 3 ms 23688 KB Output is correct
32 Correct 4 ms 23640 KB Output is correct
33 Correct 3 ms 23640 KB Output is correct
34 Correct 4 ms 23640 KB Output is correct
35 Correct 5 ms 23640 KB Output is correct
36 Correct 4 ms 23640 KB Output is correct
37 Correct 8 ms 23640 KB Output is correct
38 Correct 8 ms 23640 KB Output is correct
39 Correct 4 ms 23640 KB Output is correct
40 Correct 4 ms 23640 KB Output is correct
41 Correct 4 ms 23640 KB Output is correct
42 Correct 4 ms 23640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 470 ms 25688 KB Output is correct
2 Correct 747 ms 27988 KB Output is correct
3 Correct 696 ms 27736 KB Output is correct
4 Correct 683 ms 27736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 470 ms 25688 KB Output is correct
2 Correct 747 ms 27988 KB Output is correct
3 Correct 696 ms 27736 KB Output is correct
4 Correct 683 ms 27736 KB Output is correct
5 Correct 569 ms 25688 KB Output is correct
6 Correct 754 ms 27736 KB Output is correct
7 Correct 714 ms 27736 KB Output is correct
8 Correct 692 ms 27736 KB Output is correct
9 Correct 351 ms 21592 KB Output is correct
10 Correct 658 ms 21828 KB Output is correct
11 Correct 674 ms 21848 KB Output is correct
12 Correct 660 ms 21848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23640 KB Output is correct
2 Correct 4 ms 23640 KB Output is correct
3 Correct 4 ms 23640 KB Output is correct
4 Correct 4 ms 23640 KB Output is correct
5 Correct 4 ms 23640 KB Output is correct
6 Correct 4 ms 23732 KB Output is correct
7 Correct 4 ms 23640 KB Output is correct
8 Correct 4 ms 23640 KB Output is correct
9 Correct 5 ms 23640 KB Output is correct
10 Correct 4 ms 23640 KB Output is correct
11 Correct 4 ms 23640 KB Output is correct
12 Correct 3 ms 23640 KB Output is correct
13 Correct 470 ms 25688 KB Output is correct
14 Correct 747 ms 27988 KB Output is correct
15 Correct 696 ms 27736 KB Output is correct
16 Correct 683 ms 27736 KB Output is correct
17 Correct 569 ms 25688 KB Output is correct
18 Correct 754 ms 27736 KB Output is correct
19 Correct 714 ms 27736 KB Output is correct
20 Correct 692 ms 27736 KB Output is correct
21 Correct 351 ms 21592 KB Output is correct
22 Correct 658 ms 21828 KB Output is correct
23 Correct 674 ms 21848 KB Output is correct
24 Correct 660 ms 21848 KB Output is correct
25 Correct 777 ms 29668 KB Output is correct
26 Correct 840 ms 29776 KB Output is correct
27 Correct 812 ms 29628 KB Output is correct
28 Correct 610 ms 29776 KB Output is correct
29 Correct 787 ms 35944 KB Output is correct
30 Correct 732 ms 35920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23640 KB Output is correct
2 Correct 3 ms 23640 KB Output is correct
3 Correct 8 ms 23736 KB Output is correct
4 Correct 8 ms 23640 KB Output is correct
5 Correct 8 ms 23736 KB Output is correct
6 Correct 8 ms 23736 KB Output is correct
7 Correct 8 ms 23640 KB Output is correct
8 Correct 8 ms 23640 KB Output is correct
9 Correct 3 ms 23640 KB Output is correct
10 Correct 4 ms 23640 KB Output is correct
11 Correct 4 ms 23640 KB Output is correct
12 Correct 4 ms 23640 KB Output is correct
13 Correct 4 ms 23640 KB Output is correct
14 Correct 4 ms 23732 KB Output is correct
15 Correct 4 ms 23640 KB Output is correct
16 Correct 4 ms 23640 KB Output is correct
17 Correct 5 ms 23640 KB Output is correct
18 Correct 4 ms 23640 KB Output is correct
19 Correct 4 ms 23640 KB Output is correct
20 Correct 3 ms 23640 KB Output is correct
21 Correct 4 ms 23640 KB Output is correct
22 Correct 3 ms 23640 KB Output is correct
23 Correct 4 ms 23640 KB Output is correct
24 Correct 4 ms 23640 KB Output is correct
25 Correct 3 ms 23640 KB Output is correct
26 Correct 4 ms 23640 KB Output is correct
27 Correct 4 ms 23720 KB Output is correct
28 Correct 3 ms 23640 KB Output is correct
29 Correct 9 ms 23712 KB Output is correct
30 Correct 8 ms 23640 KB Output is correct
31 Correct 3 ms 23688 KB Output is correct
32 Correct 4 ms 23640 KB Output is correct
33 Correct 3 ms 23640 KB Output is correct
34 Correct 4 ms 23640 KB Output is correct
35 Correct 5 ms 23640 KB Output is correct
36 Correct 4 ms 23640 KB Output is correct
37 Correct 8 ms 23640 KB Output is correct
38 Correct 8 ms 23640 KB Output is correct
39 Correct 4 ms 23640 KB Output is correct
40 Correct 4 ms 23640 KB Output is correct
41 Correct 4 ms 23640 KB Output is correct
42 Correct 4 ms 23640 KB Output is correct
43 Correct 444 ms 21848 KB Output is correct
44 Correct 625 ms 21848 KB Output is correct
45 Correct 647 ms 21848 KB Output is correct
46 Correct 666 ms 21848 KB Output is correct
47 Correct 691 ms 21848 KB Output is correct
48 Correct 714 ms 21848 KB Output is correct
49 Correct 577 ms 21848 KB Output is correct
50 Correct 738 ms 23896 KB Output is correct
51 Correct 813 ms 23896 KB Output is correct
52 Correct 790 ms 21888 KB Output is correct
53 Correct 634 ms 22044 KB Output is correct
54 Correct 688 ms 23896 KB Output is correct
55 Correct 610 ms 21848 KB Output is correct
56 Correct 688 ms 21848 KB Output is correct
57 Correct 716 ms 23640 KB Output is correct
58 Correct 705 ms 22360 KB Output is correct
59 Correct 801 ms 24264 KB Output is correct
60 Correct 740 ms 24316 KB Output is correct
61 Correct 695 ms 23896 KB Output is correct
62 Correct 724 ms 21848 KB Output is correct
63 Correct 766 ms 23844 KB Output is correct
64 Correct 731 ms 21848 KB Output is correct
65 Correct 376 ms 23640 KB Output is correct
66 Correct 790 ms 24152 KB Output is correct
67 Correct 778 ms 21848 KB Output is correct
68 Correct 717 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 23640 KB Output is correct
2 Correct 3 ms 23640 KB Output is correct
3 Correct 8 ms 23736 KB Output is correct
4 Correct 8 ms 23640 KB Output is correct
5 Correct 8 ms 23736 KB Output is correct
6 Correct 8 ms 23736 KB Output is correct
7 Correct 8 ms 23640 KB Output is correct
8 Correct 8 ms 23640 KB Output is correct
9 Correct 3 ms 23640 KB Output is correct
10 Correct 4 ms 23640 KB Output is correct
11 Correct 4 ms 23640 KB Output is correct
12 Correct 4 ms 23640 KB Output is correct
13 Correct 4 ms 23640 KB Output is correct
14 Correct 4 ms 23732 KB Output is correct
15 Correct 4 ms 23640 KB Output is correct
16 Correct 4 ms 23640 KB Output is correct
17 Correct 5 ms 23640 KB Output is correct
18 Correct 4 ms 23640 KB Output is correct
19 Correct 4 ms 23640 KB Output is correct
20 Correct 3 ms 23640 KB Output is correct
21 Correct 4 ms 23640 KB Output is correct
22 Correct 3 ms 23640 KB Output is correct
23 Correct 4 ms 23640 KB Output is correct
24 Correct 4 ms 23640 KB Output is correct
25 Correct 3 ms 23640 KB Output is correct
26 Correct 4 ms 23640 KB Output is correct
27 Correct 4 ms 23720 KB Output is correct
28 Correct 3 ms 23640 KB Output is correct
29 Correct 9 ms 23712 KB Output is correct
30 Correct 8 ms 23640 KB Output is correct
31 Correct 3 ms 23688 KB Output is correct
32 Correct 4 ms 23640 KB Output is correct
33 Correct 3 ms 23640 KB Output is correct
34 Correct 4 ms 23640 KB Output is correct
35 Correct 5 ms 23640 KB Output is correct
36 Correct 4 ms 23640 KB Output is correct
37 Correct 8 ms 23640 KB Output is correct
38 Correct 8 ms 23640 KB Output is correct
39 Correct 4 ms 23640 KB Output is correct
40 Correct 4 ms 23640 KB Output is correct
41 Correct 4 ms 23640 KB Output is correct
42 Correct 4 ms 23640 KB Output is correct
43 Correct 470 ms 25688 KB Output is correct
44 Correct 747 ms 27988 KB Output is correct
45 Correct 696 ms 27736 KB Output is correct
46 Correct 683 ms 27736 KB Output is correct
47 Correct 569 ms 25688 KB Output is correct
48 Correct 754 ms 27736 KB Output is correct
49 Correct 714 ms 27736 KB Output is correct
50 Correct 692 ms 27736 KB Output is correct
51 Correct 351 ms 21592 KB Output is correct
52 Correct 658 ms 21828 KB Output is correct
53 Correct 674 ms 21848 KB Output is correct
54 Correct 660 ms 21848 KB Output is correct
55 Correct 777 ms 29668 KB Output is correct
56 Correct 840 ms 29776 KB Output is correct
57 Correct 812 ms 29628 KB Output is correct
58 Correct 610 ms 29776 KB Output is correct
59 Correct 787 ms 35944 KB Output is correct
60 Correct 732 ms 35920 KB Output is correct
61 Correct 444 ms 21848 KB Output is correct
62 Correct 625 ms 21848 KB Output is correct
63 Correct 647 ms 21848 KB Output is correct
64 Correct 666 ms 21848 KB Output is correct
65 Correct 691 ms 21848 KB Output is correct
66 Correct 714 ms 21848 KB Output is correct
67 Correct 577 ms 21848 KB Output is correct
68 Correct 738 ms 23896 KB Output is correct
69 Correct 813 ms 23896 KB Output is correct
70 Correct 790 ms 21888 KB Output is correct
71 Correct 634 ms 22044 KB Output is correct
72 Correct 688 ms 23896 KB Output is correct
73 Correct 610 ms 21848 KB Output is correct
74 Correct 688 ms 21848 KB Output is correct
75 Correct 716 ms 23640 KB Output is correct
76 Correct 705 ms 22360 KB Output is correct
77 Correct 801 ms 24264 KB Output is correct
78 Correct 740 ms 24316 KB Output is correct
79 Correct 695 ms 23896 KB Output is correct
80 Correct 724 ms 21848 KB Output is correct
81 Correct 766 ms 23844 KB Output is correct
82 Correct 731 ms 21848 KB Output is correct
83 Correct 376 ms 23640 KB Output is correct
84 Correct 790 ms 24152 KB Output is correct
85 Correct 778 ms 21848 KB Output is correct
86 Correct 717 ms 23896 KB Output is correct
87 Correct 3 ms 21592 KB Output is correct
88 Correct 554 ms 27948 KB Output is correct
89 Correct 817 ms 26252 KB Output is correct
90 Correct 723 ms 26324 KB Output is correct
91 Correct 795 ms 28752 KB Output is correct
92 Correct 797 ms 28680 KB Output is correct
93 Correct 820 ms 28768 KB Output is correct
94 Correct 773 ms 28764 KB Output is correct
95 Correct 787 ms 28668 KB Output is correct
96 Execution timed out 3037 ms 25292 KB Time limit exceeded
97 Halted 0 ms 0 KB -