답안 #1010679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010679 2024-06-29T09:30:52 Z Cookie 디지털 회로 (IOI22_circuit) C++17
100 / 100
769 ms 38576 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
const int cox[4] = {1, 0, -1, 0};
const int coy[4] = {0, -1, 0, 1};
const ll mod =  1000002022, pr = 31;
const int mxn = 2e5 + 5, mxd = 250 * 250, sq = 500, mxv = 2e6 + 1;
const int max_iter = 8e4, global_iter = 15e5 + 5;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
//#include "circuit.h"

#include <vector>
int n, m;
vt<int>adj[mxn + 1];
ll sub[mxn + 1], val[mxn + 1], pref[mxn + 1], suf[mxn + 1], a[mxn + 1];
ll st[4 * mxn + 1], sm[4 * mxn + 1];
bool lz[4 * mxn + 1];
void dfs(int s){
    sub[s] = 1;
    for(auto i: adj[s]){
        dfs(i); sub[s] = (sub[s] * sub[i]) % mod;
    }
    if(sz(adj[s])){
        sub[s] = (sub[s] * sz(adj[s])) % mod;
    }
}
void dfs2(int s, ll mul){
    if(s >= n)val[s - n] = mul;
	vt<ll>pref(sz(adj[s]) + 1), suf(sz(adj[s]) + 1);
    pref[0] = 1;
    for(int i = 0; i < sz(adj[s]); i++){
        pref[i + 1] = (pref[i] * sub[adj[s][i]]) % mod;
    }
    suf[sz(adj[s])] = 1;
    for(int i = sz(adj[s]) - 1; i >= 0; i--){
        suf[i] = (suf[i + 1] * sub[adj[s][i]]) % mod;
    }
    for(int i = 0; i < sz(adj[s]); i++){
        ll cool = (pref[i] * suf[i + 1]) % mod;
        dfs2(adj[s][i], (mul * cool) % mod);
    }
}
void pull(int nd){
    st[nd] = (st[nd << 1] + st[nd << 1 | 1]) % mod;
    sm[nd] = (sm[nd << 1] + sm[nd << 1 | 1]) % mod;
}
void build(int nd, int l, int r){
    if(l == r){
        st[nd] = a[l] * val[l]; sm[nd] = val[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(nd << 1, l, mid); build(nd << 1 | 1, mid + 1, r);
    pull(nd);
}
void go(int nd){
    st[nd] = (sm[nd] - st[nd] + mod) % mod; lz[nd] ^= 1;
}
void push(int nd){
    if(!lz[nd])return;
    go(nd << 1); go(nd << 1 | 1);
	lz[nd] = 0;
}
void upd(int nd, int l, int r, int ql, int qr){
    if(ql > r || qr < l)return;
    if(ql <= l && qr >= r){
        go(nd); 
        return;
    }
    push(nd);
    int mid = (l + r) >> 1;
    upd(nd << 1, l, mid, ql, qr); upd(nd << 1 | 1, mid + 1, r, ql, qr);
    pull(nd);
    
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N; m = M;
    for(int i = 1; i < n + m; i++){
        adj[P[i]].pb(i);
    }
    for(int i = 0; i < m; i++){
        a[i] = A[i];
    }
    dfs(0); dfs2(0, 1);
    build(1, 0, m - 1);
}

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

 
 /*
//#include "circuit.h"

#include <cassert>
#include <cstdio>

#include <vector>

int main() {
  int N, M, Q;
  assert(3 == scanf("%d %d %d", &N, &M, &Q));
  std::vector<int> P(N + M), A(M);
  for (int i = 0; i < N + M; ++i) {
    assert(1 == scanf("%d", &P[i]));
  }
  for (int j = 0; j < M; ++j) {
    assert(1 == scanf("%d", &A[j]));
  }
  init(N, M, P, A);

  for (int i = 0; i < Q; ++i) {
    int L, R;
    assert(2 == scanf("%d %d", &L, &R));
    printf("%d\n", count_ways(L, R));
  }
  return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5204 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 3 ms 5108 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5224 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 5208 KB Output is correct
10 Correct 3 ms 5464 KB Output is correct
11 Correct 3 ms 5440 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5204 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 3 ms 5108 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 5224 KB Output is correct
15 Correct 2 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 2 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 3 ms 5440 KB Output is correct
20 Correct 2 ms 5208 KB Output is correct
21 Correct 2 ms 5208 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 2 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5208 KB Output is correct
35 Correct 2 ms 5208 KB Output is correct
36 Correct 2 ms 5440 KB Output is correct
37 Correct 2 ms 5464 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 2 ms 5208 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 8792 KB Output is correct
2 Correct 607 ms 12828 KB Output is correct
3 Correct 643 ms 12632 KB Output is correct
4 Correct 661 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 8792 KB Output is correct
2 Correct 607 ms 12828 KB Output is correct
3 Correct 643 ms 12632 KB Output is correct
4 Correct 661 ms 12624 KB Output is correct
5 Correct 504 ms 8792 KB Output is correct
6 Correct 636 ms 12828 KB Output is correct
7 Correct 584 ms 12780 KB Output is correct
8 Correct 681 ms 12736 KB Output is correct
9 Correct 270 ms 5204 KB Output is correct
10 Correct 497 ms 5464 KB Output is correct
11 Correct 598 ms 5464 KB Output is correct
12 Correct 514 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 3 ms 5108 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5224 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 5208 KB Output is correct
10 Correct 3 ms 5464 KB Output is correct
11 Correct 3 ms 5440 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 431 ms 8792 KB Output is correct
14 Correct 607 ms 12828 KB Output is correct
15 Correct 643 ms 12632 KB Output is correct
16 Correct 661 ms 12624 KB Output is correct
17 Correct 504 ms 8792 KB Output is correct
18 Correct 636 ms 12828 KB Output is correct
19 Correct 584 ms 12780 KB Output is correct
20 Correct 681 ms 12736 KB Output is correct
21 Correct 270 ms 5204 KB Output is correct
22 Correct 497 ms 5464 KB Output is correct
23 Correct 598 ms 5464 KB Output is correct
24 Correct 514 ms 5464 KB Output is correct
25 Correct 625 ms 17488 KB Output is correct
26 Correct 680 ms 17840 KB Output is correct
27 Correct 695 ms 17824 KB Output is correct
28 Correct 511 ms 17840 KB Output is correct
29 Correct 737 ms 38060 KB Output is correct
30 Correct 619 ms 38220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5204 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 3 ms 5108 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 5224 KB Output is correct
15 Correct 2 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 2 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 3 ms 5440 KB Output is correct
20 Correct 2 ms 5208 KB Output is correct
21 Correct 2 ms 5208 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 2 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5208 KB Output is correct
35 Correct 2 ms 5208 KB Output is correct
36 Correct 2 ms 5440 KB Output is correct
37 Correct 2 ms 5464 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 2 ms 5208 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 414 ms 5464 KB Output is correct
44 Correct 569 ms 5424 KB Output is correct
45 Correct 583 ms 5464 KB Output is correct
46 Correct 521 ms 5720 KB Output is correct
47 Correct 568 ms 5720 KB Output is correct
48 Correct 627 ms 5720 KB Output is correct
49 Correct 567 ms 5720 KB Output is correct
50 Correct 535 ms 5720 KB Output is correct
51 Correct 540 ms 5752 KB Output is correct
52 Correct 562 ms 5760 KB Output is correct
53 Correct 518 ms 6232 KB Output is correct
54 Correct 590 ms 5648 KB Output is correct
55 Correct 561 ms 5720 KB Output is correct
56 Correct 541 ms 5720 KB Output is correct
57 Correct 585 ms 5464 KB Output is correct
58 Correct 578 ms 6744 KB Output is correct
59 Correct 514 ms 6756 KB Output is correct
60 Correct 579 ms 6744 KB Output is correct
61 Correct 597 ms 5720 KB Output is correct
62 Correct 629 ms 5464 KB Output is correct
63 Correct 617 ms 5464 KB Output is correct
64 Correct 628 ms 5720 KB Output is correct
65 Correct 331 ms 5208 KB Output is correct
66 Correct 596 ms 5464 KB Output is correct
67 Correct 626 ms 5464 KB Output is correct
68 Correct 562 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5204 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 3 ms 5108 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 5224 KB Output is correct
15 Correct 2 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 2 ms 5208 KB Output is correct
18 Correct 3 ms 5464 KB Output is correct
19 Correct 3 ms 5440 KB Output is correct
20 Correct 2 ms 5208 KB Output is correct
21 Correct 2 ms 5208 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 2 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5208 KB Output is correct
35 Correct 2 ms 5208 KB Output is correct
36 Correct 2 ms 5440 KB Output is correct
37 Correct 2 ms 5464 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 2 ms 5208 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 431 ms 8792 KB Output is correct
44 Correct 607 ms 12828 KB Output is correct
45 Correct 643 ms 12632 KB Output is correct
46 Correct 661 ms 12624 KB Output is correct
47 Correct 504 ms 8792 KB Output is correct
48 Correct 636 ms 12828 KB Output is correct
49 Correct 584 ms 12780 KB Output is correct
50 Correct 681 ms 12736 KB Output is correct
51 Correct 270 ms 5204 KB Output is correct
52 Correct 497 ms 5464 KB Output is correct
53 Correct 598 ms 5464 KB Output is correct
54 Correct 514 ms 5464 KB Output is correct
55 Correct 625 ms 17488 KB Output is correct
56 Correct 680 ms 17840 KB Output is correct
57 Correct 695 ms 17824 KB Output is correct
58 Correct 511 ms 17840 KB Output is correct
59 Correct 737 ms 38060 KB Output is correct
60 Correct 619 ms 38220 KB Output is correct
61 Correct 414 ms 5464 KB Output is correct
62 Correct 569 ms 5424 KB Output is correct
63 Correct 583 ms 5464 KB Output is correct
64 Correct 521 ms 5720 KB Output is correct
65 Correct 568 ms 5720 KB Output is correct
66 Correct 627 ms 5720 KB Output is correct
67 Correct 567 ms 5720 KB Output is correct
68 Correct 535 ms 5720 KB Output is correct
69 Correct 540 ms 5752 KB Output is correct
70 Correct 562 ms 5760 KB Output is correct
71 Correct 518 ms 6232 KB Output is correct
72 Correct 590 ms 5648 KB Output is correct
73 Correct 561 ms 5720 KB Output is correct
74 Correct 541 ms 5720 KB Output is correct
75 Correct 585 ms 5464 KB Output is correct
76 Correct 578 ms 6744 KB Output is correct
77 Correct 514 ms 6756 KB Output is correct
78 Correct 579 ms 6744 KB Output is correct
79 Correct 597 ms 5720 KB Output is correct
80 Correct 629 ms 5464 KB Output is correct
81 Correct 617 ms 5464 KB Output is correct
82 Correct 628 ms 5720 KB Output is correct
83 Correct 331 ms 5208 KB Output is correct
84 Correct 596 ms 5464 KB Output is correct
85 Correct 626 ms 5464 KB Output is correct
86 Correct 562 ms 5464 KB Output is correct
87 Correct 2 ms 4952 KB Output is correct
88 Correct 431 ms 16948 KB Output is correct
89 Correct 713 ms 12628 KB Output is correct
90 Correct 769 ms 12616 KB Output is correct
91 Correct 627 ms 17972 KB Output is correct
92 Correct 661 ms 17928 KB Output is correct
93 Correct 635 ms 17828 KB Output is correct
94 Correct 662 ms 17992 KB Output is correct
95 Correct 606 ms 17964 KB Output is correct
96 Correct 546 ms 13488 KB Output is correct
97 Correct 613 ms 13676 KB Output is correct
98 Correct 493 ms 30376 KB Output is correct
99 Correct 623 ms 17780 KB Output is correct
100 Correct 634 ms 15516 KB Output is correct
101 Correct 650 ms 14672 KB Output is correct
102 Correct 680 ms 13708 KB Output is correct
103 Correct 697 ms 38224 KB Output is correct
104 Correct 606 ms 38576 KB Output is correct
105 Correct 602 ms 38576 KB Output is correct
106 Correct 622 ms 16776 KB Output is correct
107 Correct 565 ms 13656 KB Output is correct
108 Correct 596 ms 13648 KB Output is correct
109 Correct 638 ms 13868 KB Output is correct