답안 #1058827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058827 2024-08-14T14:12:42 Z mychecksedad 디지털 회로 (IOI22_circuit) C++17
100 / 100
680 ms 72912 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define en cout << '\n'
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vi vector<int>
#define ll long long int
#define ff first
#define ss second
const int N = 500000+10;
const ll MOD = 1000002022;

int n, m;
vector<int> g[N];
ll sum[N];
array<ll, 2> T[N];
ll X[N];
vi val;
int lazy[N];
int F;
array<ll, 2> comb(array<ll, 2> x, array<ll, 2> y){
  array<ll, 2> z;
  z[0] = (x[0]+y[0])%MOD;
  z[1] = (x[1]+y[1])%MOD;
  return z;
}
void build(int l, int r, int k){
  lazy[k] = 0;
  if(l == r){
    T[k][0] = sum[l + n] * (1 - val[l]);
    T[k][1] = sum[l + n] * val[l];
    // cout << T[k][1] << ' ' << l << '\n';
    return;
  }
  int m = l+r>>1;
  build(l, m, k<<1);
  build(m+1, r, k<<1|1);
  T[k] = comb(T[k<<1], T[k<<1|1]);
}
int get(){
  return T[1][1];
}
void push(int k){
  if(lazy[k]){
    lazy[k<<1] ^= lazy[k];
    lazy[k<<1|1] ^= lazy[k];
    swap(T[k<<1][0], T[k<<1][1]);
    swap(T[k<<1|1][0], T[k<<1|1][1]);
    lazy[k] = 0;
  }
}
void upd(int l, int r, int ql, int qr, int k){
  if(ql > r || l > qr) return;
  if(ql <= l && r <= qr){
    swap(T[k][0], T[k][1]);
    lazy[k] ^= 1;
    // cout << l << ' ' << r << ' ' << T[k][0] << ' ' << T[k][1] << '\n';
    return;
  }
  push(k);
  int m = l+r>>1;
  upd(l, m, ql, qr, k<<1);
  upd(m+1, r, ql, qr, k<<1|1);
  T[k] = comb(T[k<<1], T[k<<1|1]);
  // cout << l << ' ' << r << ' ' << T[k][0] << ' ' << T[k][1] << '\n';
}
vector<ll> pref[N];
vector<ll> suf[N];
void dfs(int v){
  X[v] = 1;
  if(g[v].size() == 0) return;
  pref[v].resize(g[v].size());
  suf[v].resize(g[v].size());
  for(int u: g[v]){
    dfs(u);
    X[v] *= X[u];
    X[v] %= MOD;
  }
  X[v] *= g[v].size();
  X[v] %= MOD;
  pref[v][0] = X[g[v][0]];
  suf[v].back() = X[g[v].back()];
  for(int i = 1; i < pref[v].size(); ++i) pref[v][i] = (pref[v][i - 1] * X[g[v][i]]) % MOD;
  for(int i = int(suf[v].size()) - 2; i >= 0; --i) suf[v][i] = (suf[v][i + 1] * X[g[v][i]]) % MOD;
}
void dfs2(int v, ll num){
  if(g[v].size() == 0){
    sum[v] = num;
    return;
  }
  for(int i = 0; i < g[v].size(); ++i){
    ll x = 1;
    if(i > 0) x = pref[v][i - 1];
    ll y = 1;
    if(i + 1 < g[v].size()) y = suf[v][i + 1];
    x = x * y % MOD;
    dfs2(g[v][i], num * x % MOD);
  }
}
void init(int nn, int mm, std::vector<int> P, std::vector<int> A) { n=nn, m=mm;
  for(int i = 1; i < n + m; ++i) g[P[i]].pb(i);
  dfs(0);
  dfs2(0, 1);
  val = A;
  build(0, m - 1, 1);
  // for(int i = 0; i < n + m; ++i) cout << X[i] << ' ';en;
  // for(int i = 0; i < n + m; ++i) cout << sum[i] << ' ';en;
}

int count_ways(int L, int R) {
  L -= n, R -= n;
  upd(0, m - 1, L, R, 1);
  ll num = get();
  return num;
}

Compilation message

circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:37:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   int m = l+r>>1;
      |           ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:63:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |   int m = l+r>>1;
      |           ~^~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for(int i = 1; i < pref[v].size(); ++i) pref[v][i] = (pref[v][i - 1] * X[g[v][i]]) % MOD;
      |                  ~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, long long int)':
circuit.cpp:93:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for(int i = 0; i < g[v].size(); ++i){
      |                  ~~^~~~~~~~~~~~~
circuit.cpp:97:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     if(i + 1 < g[v].size()) y = suf[v][i + 1];
      |        ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 6 ms 44888 KB Output is correct
3 Correct 5 ms 44852 KB Output is correct
4 Correct 6 ms 45096 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 6 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 6 ms 44888 KB Output is correct
3 Correct 6 ms 44888 KB Output is correct
4 Correct 6 ms 44888 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 6 ms 45032 KB Output is correct
7 Correct 6 ms 45144 KB Output is correct
8 Correct 6 ms 45144 KB Output is correct
9 Correct 6 ms 45144 KB Output is correct
10 Correct 6 ms 45144 KB Output is correct
11 Correct 6 ms 45144 KB Output is correct
12 Correct 6 ms 45164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 6 ms 44888 KB Output is correct
3 Correct 5 ms 44852 KB Output is correct
4 Correct 6 ms 45096 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 6 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
9 Correct 6 ms 44888 KB Output is correct
10 Correct 6 ms 44888 KB Output is correct
11 Correct 6 ms 44888 KB Output is correct
12 Correct 6 ms 44888 KB Output is correct
13 Correct 6 ms 44888 KB Output is correct
14 Correct 6 ms 45032 KB Output is correct
15 Correct 6 ms 45144 KB Output is correct
16 Correct 6 ms 45144 KB Output is correct
17 Correct 6 ms 45144 KB Output is correct
18 Correct 6 ms 45144 KB Output is correct
19 Correct 6 ms 45144 KB Output is correct
20 Correct 6 ms 45164 KB Output is correct
21 Correct 7 ms 45144 KB Output is correct
22 Correct 6 ms 45092 KB Output is correct
23 Correct 6 ms 45096 KB Output is correct
24 Correct 6 ms 45144 KB Output is correct
25 Correct 6 ms 44984 KB Output is correct
26 Correct 6 ms 45144 KB Output is correct
27 Correct 6 ms 45144 KB Output is correct
28 Correct 6 ms 45144 KB Output is correct
29 Correct 5 ms 44888 KB Output is correct
30 Correct 7 ms 45140 KB Output is correct
31 Correct 6 ms 45144 KB Output is correct
32 Correct 6 ms 45144 KB Output is correct
33 Correct 6 ms 45036 KB Output is correct
34 Correct 6 ms 44888 KB Output is correct
35 Correct 6 ms 44888 KB Output is correct
36 Correct 7 ms 45144 KB Output is correct
37 Correct 6 ms 45144 KB Output is correct
38 Correct 6 ms 45144 KB Output is correct
39 Correct 6 ms 45144 KB Output is correct
40 Correct 6 ms 44888 KB Output is correct
41 Correct 6 ms 45044 KB Output is correct
42 Correct 6 ms 44888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 48984 KB Output is correct
2 Correct 541 ms 54872 KB Output is correct
3 Correct 528 ms 54864 KB Output is correct
4 Correct 511 ms 54864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 48984 KB Output is correct
2 Correct 541 ms 54872 KB Output is correct
3 Correct 528 ms 54864 KB Output is correct
4 Correct 511 ms 54864 KB Output is correct
5 Correct 452 ms 48984 KB Output is correct
6 Correct 560 ms 54940 KB Output is correct
7 Correct 614 ms 54864 KB Output is correct
8 Correct 573 ms 54872 KB Output is correct
9 Correct 263 ms 45144 KB Output is correct
10 Correct 570 ms 45400 KB Output is correct
11 Correct 553 ms 45400 KB Output is correct
12 Correct 575 ms 45400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 6 ms 44888 KB Output is correct
3 Correct 6 ms 44888 KB Output is correct
4 Correct 6 ms 44888 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 6 ms 45032 KB Output is correct
7 Correct 6 ms 45144 KB Output is correct
8 Correct 6 ms 45144 KB Output is correct
9 Correct 6 ms 45144 KB Output is correct
10 Correct 6 ms 45144 KB Output is correct
11 Correct 6 ms 45144 KB Output is correct
12 Correct 6 ms 45164 KB Output is correct
13 Correct 378 ms 48984 KB Output is correct
14 Correct 541 ms 54872 KB Output is correct
15 Correct 528 ms 54864 KB Output is correct
16 Correct 511 ms 54864 KB Output is correct
17 Correct 452 ms 48984 KB Output is correct
18 Correct 560 ms 54940 KB Output is correct
19 Correct 614 ms 54864 KB Output is correct
20 Correct 573 ms 54872 KB Output is correct
21 Correct 263 ms 45144 KB Output is correct
22 Correct 570 ms 45400 KB Output is correct
23 Correct 553 ms 45400 KB Output is correct
24 Correct 575 ms 45400 KB Output is correct
25 Correct 585 ms 63104 KB Output is correct
26 Correct 660 ms 63316 KB Output is correct
27 Correct 625 ms 63312 KB Output is correct
28 Correct 489 ms 63104 KB Output is correct
29 Correct 627 ms 70992 KB Output is correct
30 Correct 562 ms 70992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 6 ms 44888 KB Output is correct
3 Correct 5 ms 44852 KB Output is correct
4 Correct 6 ms 45096 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 6 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
9 Correct 6 ms 44888 KB Output is correct
10 Correct 6 ms 44888 KB Output is correct
11 Correct 6 ms 44888 KB Output is correct
12 Correct 6 ms 44888 KB Output is correct
13 Correct 6 ms 44888 KB Output is correct
14 Correct 6 ms 45032 KB Output is correct
15 Correct 6 ms 45144 KB Output is correct
16 Correct 6 ms 45144 KB Output is correct
17 Correct 6 ms 45144 KB Output is correct
18 Correct 6 ms 45144 KB Output is correct
19 Correct 6 ms 45144 KB Output is correct
20 Correct 6 ms 45164 KB Output is correct
21 Correct 7 ms 45144 KB Output is correct
22 Correct 6 ms 45092 KB Output is correct
23 Correct 6 ms 45096 KB Output is correct
24 Correct 6 ms 45144 KB Output is correct
25 Correct 6 ms 44984 KB Output is correct
26 Correct 6 ms 45144 KB Output is correct
27 Correct 6 ms 45144 KB Output is correct
28 Correct 6 ms 45144 KB Output is correct
29 Correct 5 ms 44888 KB Output is correct
30 Correct 7 ms 45140 KB Output is correct
31 Correct 6 ms 45144 KB Output is correct
32 Correct 6 ms 45144 KB Output is correct
33 Correct 6 ms 45036 KB Output is correct
34 Correct 6 ms 44888 KB Output is correct
35 Correct 6 ms 44888 KB Output is correct
36 Correct 7 ms 45144 KB Output is correct
37 Correct 6 ms 45144 KB Output is correct
38 Correct 6 ms 45144 KB Output is correct
39 Correct 6 ms 45144 KB Output is correct
40 Correct 6 ms 44888 KB Output is correct
41 Correct 6 ms 45044 KB Output is correct
42 Correct 6 ms 44888 KB Output is correct
43 Correct 416 ms 45400 KB Output is correct
44 Correct 585 ms 45400 KB Output is correct
45 Correct 552 ms 45448 KB Output is correct
46 Correct 555 ms 45656 KB Output is correct
47 Correct 540 ms 45656 KB Output is correct
48 Correct 525 ms 45680 KB Output is correct
49 Correct 596 ms 45656 KB Output is correct
50 Correct 521 ms 45656 KB Output is correct
51 Correct 523 ms 45392 KB Output is correct
52 Correct 530 ms 45248 KB Output is correct
53 Correct 499 ms 45912 KB Output is correct
54 Correct 589 ms 45656 KB Output is correct
55 Correct 523 ms 45400 KB Output is correct
56 Correct 575 ms 45144 KB Output is correct
57 Correct 551 ms 45144 KB Output is correct
58 Correct 531 ms 46028 KB Output is correct
59 Correct 494 ms 45912 KB Output is correct
60 Correct 532 ms 45912 KB Output is correct
61 Correct 517 ms 45596 KB Output is correct
62 Correct 553 ms 45144 KB Output is correct
63 Correct 519 ms 45144 KB Output is correct
64 Correct 559 ms 45144 KB Output is correct
65 Correct 290 ms 45144 KB Output is correct
66 Correct 514 ms 45400 KB Output is correct
67 Correct 513 ms 45400 KB Output is correct
68 Correct 548 ms 45400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 6 ms 44888 KB Output is correct
3 Correct 5 ms 44852 KB Output is correct
4 Correct 6 ms 45096 KB Output is correct
5 Correct 6 ms 44888 KB Output is correct
6 Correct 6 ms 44888 KB Output is correct
7 Correct 6 ms 44888 KB Output is correct
8 Correct 6 ms 44888 KB Output is correct
9 Correct 6 ms 44888 KB Output is correct
10 Correct 6 ms 44888 KB Output is correct
11 Correct 6 ms 44888 KB Output is correct
12 Correct 6 ms 44888 KB Output is correct
13 Correct 6 ms 44888 KB Output is correct
14 Correct 6 ms 45032 KB Output is correct
15 Correct 6 ms 45144 KB Output is correct
16 Correct 6 ms 45144 KB Output is correct
17 Correct 6 ms 45144 KB Output is correct
18 Correct 6 ms 45144 KB Output is correct
19 Correct 6 ms 45144 KB Output is correct
20 Correct 6 ms 45164 KB Output is correct
21 Correct 7 ms 45144 KB Output is correct
22 Correct 6 ms 45092 KB Output is correct
23 Correct 6 ms 45096 KB Output is correct
24 Correct 6 ms 45144 KB Output is correct
25 Correct 6 ms 44984 KB Output is correct
26 Correct 6 ms 45144 KB Output is correct
27 Correct 6 ms 45144 KB Output is correct
28 Correct 6 ms 45144 KB Output is correct
29 Correct 5 ms 44888 KB Output is correct
30 Correct 7 ms 45140 KB Output is correct
31 Correct 6 ms 45144 KB Output is correct
32 Correct 6 ms 45144 KB Output is correct
33 Correct 6 ms 45036 KB Output is correct
34 Correct 6 ms 44888 KB Output is correct
35 Correct 6 ms 44888 KB Output is correct
36 Correct 7 ms 45144 KB Output is correct
37 Correct 6 ms 45144 KB Output is correct
38 Correct 6 ms 45144 KB Output is correct
39 Correct 6 ms 45144 KB Output is correct
40 Correct 6 ms 44888 KB Output is correct
41 Correct 6 ms 45044 KB Output is correct
42 Correct 6 ms 44888 KB Output is correct
43 Correct 378 ms 48984 KB Output is correct
44 Correct 541 ms 54872 KB Output is correct
45 Correct 528 ms 54864 KB Output is correct
46 Correct 511 ms 54864 KB Output is correct
47 Correct 452 ms 48984 KB Output is correct
48 Correct 560 ms 54940 KB Output is correct
49 Correct 614 ms 54864 KB Output is correct
50 Correct 573 ms 54872 KB Output is correct
51 Correct 263 ms 45144 KB Output is correct
52 Correct 570 ms 45400 KB Output is correct
53 Correct 553 ms 45400 KB Output is correct
54 Correct 575 ms 45400 KB Output is correct
55 Correct 585 ms 63104 KB Output is correct
56 Correct 660 ms 63316 KB Output is correct
57 Correct 625 ms 63312 KB Output is correct
58 Correct 489 ms 63104 KB Output is correct
59 Correct 627 ms 70992 KB Output is correct
60 Correct 562 ms 70992 KB Output is correct
61 Correct 416 ms 45400 KB Output is correct
62 Correct 585 ms 45400 KB Output is correct
63 Correct 552 ms 45448 KB Output is correct
64 Correct 555 ms 45656 KB Output is correct
65 Correct 540 ms 45656 KB Output is correct
66 Correct 525 ms 45680 KB Output is correct
67 Correct 596 ms 45656 KB Output is correct
68 Correct 521 ms 45656 KB Output is correct
69 Correct 523 ms 45392 KB Output is correct
70 Correct 530 ms 45248 KB Output is correct
71 Correct 499 ms 45912 KB Output is correct
72 Correct 589 ms 45656 KB Output is correct
73 Correct 523 ms 45400 KB Output is correct
74 Correct 575 ms 45144 KB Output is correct
75 Correct 551 ms 45144 KB Output is correct
76 Correct 531 ms 46028 KB Output is correct
77 Correct 494 ms 45912 KB Output is correct
78 Correct 532 ms 45912 KB Output is correct
79 Correct 517 ms 45596 KB Output is correct
80 Correct 553 ms 45144 KB Output is correct
81 Correct 519 ms 45144 KB Output is correct
82 Correct 559 ms 45144 KB Output is correct
83 Correct 290 ms 45144 KB Output is correct
84 Correct 514 ms 45400 KB Output is correct
85 Correct 513 ms 45400 KB Output is correct
86 Correct 548 ms 45400 KB Output is correct
87 Correct 6 ms 44888 KB Output is correct
88 Correct 373 ms 60660 KB Output is correct
89 Correct 632 ms 55888 KB Output is correct
90 Correct 586 ms 55120 KB Output is correct
91 Correct 584 ms 63824 KB Output is correct
92 Correct 652 ms 63824 KB Output is correct
93 Correct 670 ms 63824 KB Output is correct
94 Correct 617 ms 63824 KB Output is correct
95 Correct 632 ms 63824 KB Output is correct
96 Correct 562 ms 53148 KB Output is correct
97 Correct 602 ms 53200 KB Output is correct
98 Correct 515 ms 63064 KB Output is correct
99 Correct 680 ms 63312 KB Output is correct
100 Correct 583 ms 56144 KB Output is correct
101 Correct 608 ms 54864 KB Output is correct
102 Correct 599 ms 53020 KB Output is correct
103 Correct 585 ms 70992 KB Output is correct
104 Correct 664 ms 72912 KB Output is correct
105 Correct 565 ms 72912 KB Output is correct
106 Correct 643 ms 57432 KB Output is correct
107 Correct 591 ms 54864 KB Output is correct
108 Correct 576 ms 54352 KB Output is correct
109 Correct 574 ms 53072 KB Output is correct