답안 #945044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945044 2024-03-13T10:29:47 Z abczz 디지털 회로 (IOI22_circuit) C++17
100 / 100
709 ms 40000 KB
#include "circuit.h"
#include <iostream>
#include <vector>
#include <array>
#define ll long long

using namespace std;

vector <ll> adj[200000];
bool B[200000];
array<ll, 2> st[400000];
bool lazy[400000];
ll n, m, sz[200000], X[200000], M = 1e9 + 2022;
void dfs(ll u) {
  sz[u] = adj[u].size();
  for (auto v : adj[u]) {
    dfs(v);
    sz[u] *= sz[v];
    sz[u] %= M;
  }
  if (!sz[u]) sz[u] = 1;
}
void solve(ll u, ll w) {
  X[u] = w;
  vector <ll> pref, suf;
  pref.resize(adj[u].size());
  suf.resize(adj[u].size());
  for (int i=0; i<adj[u].size(); ++i) {
    pref[i] = sz[adj[u][i]];
    if (i) {
      pref[i] *= pref[i-1];
      pref[i] %= M;
    }
  }
  for (int i=adj[u].size()-1; i>=0; --i) {
    suf[i] = sz[adj[u][i]];
    if (i != adj[u].size()-1) {
      suf[i] *= suf[i+1];
      suf[i] %= M;
    }
  }
  for (int i=0; i<adj[u].size(); ++i) {
    solve(adj[u][i], (w * (((i ? pref[i-1] : 1) * (i != adj[u].size()-1 ? suf[i+1] : 1)) % M))%M);
  }
}

void build(ll id, ll l, ll r) {
  if (l == r) {
    st[id] = {X[l], 0};
    if (B[l]) swap(st[id][0], st[id][1]);
    return;
  }
  ll mid = (l+r)/2;
  build(id*2, l, mid);
  build(id*2+1, mid+1, r);
  st[id][0] = st[id*2][0] + st[id*2+1][0];
  st[id][1] = st[id*2][1] + st[id*2+1][1];
  st[id][0] %= M;
  st[id][1] %= M;
}

void push(ll id) {
  if (lazy[id]) {
    lazy[id*2] ^= 1;
    lazy[id*2+1] ^= 1;
    swap(st[id*2][0], st[id*2][1]);
    swap(st[id*2+1][0], st[id*2+1][1]);
    lazy[id] = 0;
  }
}

void update(ll id, ll l, ll r, ll ql, ll qr) {
  if (qr < l || r < ql) return;
  else if (ql <= l && r <= qr) {
    lazy[id] ^= 1;
    swap(st[id][0], st[id][1]);
    return;
  }
  ll mid = (l+r)/2;
  push(id);
  update(id*2, l, mid, ql, qr);
  update(id*2+1, mid+1, r, ql, qr);
  st[id][0] = st[id*2][0] + st[id*2+1][0];
  st[id][1] = st[id*2][1] + st[id*2+1][1];
  st[id][0] %= M;
  st[id][1] %= M;
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n = N, m = M;
  for (int i=N; i<N+M; ++i) {
    B[i] = A[i-N];
  }
  for (int i=1; i<P.size(); ++i) {
    adj[P[i]].push_back(i);
  }
  dfs(0);
  solve(0, 1);
  build(1, n, n+m-1);
}

int count_ways(int L, int R) {
  update(1, n, n+m-1, L, R);
  return st[1][1];
}

Compilation message

circuit.cpp: In function 'void solve(long long int, long long int)':
circuit.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for (int i=0; i<adj[u].size(); ++i) {
      |                 ~^~~~~~~~~~~~~~
circuit.cpp:37:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     if (i != adj[u].size()-1) {
      |         ~~^~~~~~~~~~~~~~~~~~
circuit.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int i=0; i<adj[u].size(); ++i) {
      |                 ~^~~~~~~~~~~~~~
circuit.cpp:43:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     solve(adj[u][i], (w * (((i ? pref[i-1] : 1) * (i != adj[u].size()-1 ? suf[i+1] : 1)) % M))%M);
      |                                                    ~~^~~~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:94:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for (int i=1; i<P.size(); ++i) {
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10840 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10840 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 2 ms 10840 KB Output is correct
14 Correct 3 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
25 Correct 2 ms 10840 KB Output is correct
26 Correct 2 ms 11092 KB Output is correct
27 Correct 2 ms 10840 KB Output is correct
28 Correct 2 ms 10836 KB Output is correct
29 Correct 2 ms 10840 KB Output is correct
30 Correct 2 ms 10840 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 3 ms 10840 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 3 ms 10840 KB Output is correct
36 Correct 2 ms 11096 KB Output is correct
37 Correct 2 ms 11096 KB Output is correct
38 Correct 2 ms 10924 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 14816 KB Output is correct
2 Correct 599 ms 16516 KB Output is correct
3 Correct 576 ms 16476 KB Output is correct
4 Correct 613 ms 16668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 14816 KB Output is correct
2 Correct 599 ms 16516 KB Output is correct
3 Correct 576 ms 16476 KB Output is correct
4 Correct 613 ms 16668 KB Output is correct
5 Correct 501 ms 14680 KB Output is correct
6 Correct 681 ms 16480 KB Output is correct
7 Correct 677 ms 16464 KB Output is correct
8 Correct 580 ms 16616 KB Output is correct
9 Correct 289 ms 10840 KB Output is correct
10 Correct 534 ms 11096 KB Output is correct
11 Correct 548 ms 11096 KB Output is correct
12 Correct 552 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 417 ms 14816 KB Output is correct
14 Correct 599 ms 16516 KB Output is correct
15 Correct 576 ms 16476 KB Output is correct
16 Correct 613 ms 16668 KB Output is correct
17 Correct 501 ms 14680 KB Output is correct
18 Correct 681 ms 16480 KB Output is correct
19 Correct 677 ms 16464 KB Output is correct
20 Correct 580 ms 16616 KB Output is correct
21 Correct 289 ms 10840 KB Output is correct
22 Correct 534 ms 11096 KB Output is correct
23 Correct 548 ms 11096 KB Output is correct
24 Correct 552 ms 11096 KB Output is correct
25 Correct 709 ms 20416 KB Output is correct
26 Correct 682 ms 20592 KB Output is correct
27 Correct 708 ms 20440 KB Output is correct
28 Correct 554 ms 20968 KB Output is correct
29 Correct 658 ms 39248 KB Output is correct
30 Correct 675 ms 39648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10840 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 2 ms 10840 KB Output is correct
14 Correct 3 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
25 Correct 2 ms 10840 KB Output is correct
26 Correct 2 ms 11092 KB Output is correct
27 Correct 2 ms 10840 KB Output is correct
28 Correct 2 ms 10836 KB Output is correct
29 Correct 2 ms 10840 KB Output is correct
30 Correct 2 ms 10840 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 3 ms 10840 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 3 ms 10840 KB Output is correct
36 Correct 2 ms 11096 KB Output is correct
37 Correct 2 ms 11096 KB Output is correct
38 Correct 2 ms 10924 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 424 ms 10840 KB Output is correct
44 Correct 573 ms 10840 KB Output is correct
45 Correct 549 ms 10840 KB Output is correct
46 Correct 534 ms 11096 KB Output is correct
47 Correct 559 ms 11096 KB Output is correct
48 Correct 604 ms 11096 KB Output is correct
49 Correct 593 ms 11096 KB Output is correct
50 Correct 559 ms 11096 KB Output is correct
51 Correct 563 ms 11068 KB Output is correct
52 Correct 576 ms 11096 KB Output is correct
53 Correct 566 ms 11864 KB Output is correct
54 Correct 558 ms 11096 KB Output is correct
55 Correct 582 ms 11124 KB Output is correct
56 Correct 599 ms 10840 KB Output is correct
57 Correct 595 ms 10840 KB Output is correct
58 Correct 588 ms 11864 KB Output is correct
59 Correct 537 ms 12120 KB Output is correct
60 Correct 603 ms 12120 KB Output is correct
61 Correct 602 ms 11096 KB Output is correct
62 Correct 576 ms 10840 KB Output is correct
63 Correct 538 ms 10840 KB Output is correct
64 Correct 580 ms 10840 KB Output is correct
65 Correct 274 ms 10840 KB Output is correct
66 Correct 585 ms 11096 KB Output is correct
67 Correct 554 ms 11096 KB Output is correct
68 Correct 546 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10840 KB Output is correct
2 Correct 3 ms 10584 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10584 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 2 ms 10840 KB Output is correct
14 Correct 3 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
25 Correct 2 ms 10840 KB Output is correct
26 Correct 2 ms 11092 KB Output is correct
27 Correct 2 ms 10840 KB Output is correct
28 Correct 2 ms 10836 KB Output is correct
29 Correct 2 ms 10840 KB Output is correct
30 Correct 2 ms 10840 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 3 ms 10840 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 3 ms 10840 KB Output is correct
36 Correct 2 ms 11096 KB Output is correct
37 Correct 2 ms 11096 KB Output is correct
38 Correct 2 ms 10924 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 417 ms 14816 KB Output is correct
44 Correct 599 ms 16516 KB Output is correct
45 Correct 576 ms 16476 KB Output is correct
46 Correct 613 ms 16668 KB Output is correct
47 Correct 501 ms 14680 KB Output is correct
48 Correct 681 ms 16480 KB Output is correct
49 Correct 677 ms 16464 KB Output is correct
50 Correct 580 ms 16616 KB Output is correct
51 Correct 289 ms 10840 KB Output is correct
52 Correct 534 ms 11096 KB Output is correct
53 Correct 548 ms 11096 KB Output is correct
54 Correct 552 ms 11096 KB Output is correct
55 Correct 709 ms 20416 KB Output is correct
56 Correct 682 ms 20592 KB Output is correct
57 Correct 708 ms 20440 KB Output is correct
58 Correct 554 ms 20968 KB Output is correct
59 Correct 658 ms 39248 KB Output is correct
60 Correct 675 ms 39648 KB Output is correct
61 Correct 424 ms 10840 KB Output is correct
62 Correct 573 ms 10840 KB Output is correct
63 Correct 549 ms 10840 KB Output is correct
64 Correct 534 ms 11096 KB Output is correct
65 Correct 559 ms 11096 KB Output is correct
66 Correct 604 ms 11096 KB Output is correct
67 Correct 593 ms 11096 KB Output is correct
68 Correct 559 ms 11096 KB Output is correct
69 Correct 563 ms 11068 KB Output is correct
70 Correct 576 ms 11096 KB Output is correct
71 Correct 566 ms 11864 KB Output is correct
72 Correct 558 ms 11096 KB Output is correct
73 Correct 582 ms 11124 KB Output is correct
74 Correct 599 ms 10840 KB Output is correct
75 Correct 595 ms 10840 KB Output is correct
76 Correct 588 ms 11864 KB Output is correct
77 Correct 537 ms 12120 KB Output is correct
78 Correct 603 ms 12120 KB Output is correct
79 Correct 602 ms 11096 KB Output is correct
80 Correct 576 ms 10840 KB Output is correct
81 Correct 538 ms 10840 KB Output is correct
82 Correct 580 ms 10840 KB Output is correct
83 Correct 274 ms 10840 KB Output is correct
84 Correct 585 ms 11096 KB Output is correct
85 Correct 554 ms 11096 KB Output is correct
86 Correct 546 ms 11096 KB Output is correct
87 Correct 2 ms 10584 KB Output is correct
88 Correct 447 ms 20528 KB Output is correct
89 Correct 664 ms 16720 KB Output is correct
90 Correct 664 ms 16928 KB Output is correct
91 Correct 597 ms 21084 KB Output is correct
92 Correct 704 ms 20952 KB Output is correct
93 Correct 671 ms 21072 KB Output is correct
94 Correct 687 ms 21072 KB Output is correct
95 Correct 612 ms 21200 KB Output is correct
96 Correct 571 ms 17340 KB Output is correct
97 Correct 589 ms 17568 KB Output is correct
98 Correct 555 ms 33492 KB Output is correct
99 Correct 646 ms 20456 KB Output is correct
100 Correct 644 ms 19488 KB Output is correct
101 Correct 639 ms 18768 KB Output is correct
102 Correct 650 ms 17496 KB Output is correct
103 Correct 638 ms 39380 KB Output is correct
104 Correct 683 ms 40000 KB Output is correct
105 Correct 648 ms 39988 KB Output is correct
106 Correct 590 ms 20824 KB Output is correct
107 Correct 630 ms 17912 KB Output is correct
108 Correct 641 ms 18220 KB Output is correct
109 Correct 648 ms 17932 KB Output is correct