답안 #1070574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070574 2024-08-22T15:33:01 Z pan 디지털 회로 (IOI22_circuit) C++17
100 / 100
877 ms 35912 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;

ll const mod = 1000002022;


ll n, m;
ll a[200005], child[200005], path[200005], sum[200005];
vector<ll> adj[200005];

// RURQ Segment Tree

struct node{

    int s, e, m; 
    ll val, tot;
    ll lazy; 
    node *l, *r; 
	node (int S, int E)
	{ 
       s = S, e = E, m = (s+e)/2;
       lazy = 0; 
       if(s != e)
       { 
           l = new node(s, m); 
           r = new node(m+1, e);
           val = (l->val + r->val)%mod;
           tot = (l->tot + r->tot)%mod;
       }
       else
       {
		   val = ((a[s])?path[n+s]%mod:0);
		   tot = path[n+s]%mod;
	   }
 
    }
 
	void propogate()
	{
       if (lazy==0) return; 
       val = (tot - val + mod)%mod;
       if (s != e){ 
           l->lazy^=lazy;
           r->lazy^=lazy;
       }
       lazy=0; 
    }
	void update(int S, int E)
	{ 
	   propogate();
       if(s==S && e==E){ lazy^=1;}
       else{ 
           if(E <= m) l->update(S, E); 
           else if (m < S) r->update(S, E); 
           else l->update(S, m),r->update(m+1, E);
           l->propogate(),r->propogate();
           val = (l->val + r->val)%mod;
           tot = (l->tot + r->tot)%mod;
       }
    }
    ll query()
    {
		propogate();
		return val;
	}

} *root;

void dfs(ll x)
{
	if (x >= n){ sum[x] = 1; return;}
	sum[x] = child[x];
	for (ll u: adj[x])
	{
		dfs(u);
		sum[x] = (sum[u] * sum[x])%mod;
	}
}

void dfs2(ll x)
{
	//show(x);
	if (x >= n) return;
	vector<ll> dp(child[x], path[x]);
	ll ps = 1;
	for (ll i=0; i<child[x]; ++i)
	{
		dp[i] = (dp[i] * ps)%mod;
		ps = (ps * sum[adj[x][i]])%mod;
	}
	ll ss = 1;
	for (ll i=child[x]-1; i>=0; --i)
	{
		dp[i] = (dp[i] * ss)%mod;
		ss = (ss * sum[adj[x][i]])%mod;
	}
	for (ll i=0; i<child[x]; ++i)
	{
		path[adj[x][i]] = dp[i];
		dfs2(adj[x][i]);
	}
	
}
 

void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
	n = N, m = M;
	for (ll i=0; i<m; ++i) a[i] = A[i];
	for (ll i=0; i<n+m; ++i) child[i] =0;
	for (ll i=1; i<n+m; ++i) {adj[P[i]].pb(i); child[P[i]]++;}
	dfs(0);
	path[0] = 1;
	dfs2(0);
	//for (ll i=0; i<=n+m-1; ++i) show(path[i]);
	root = new node(0, m-1);
	

}
int count_ways(int L, int R)
{
	root->update(L-n, R-n);
	return root->query()%mod;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 11092 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 1 ms 10840 KB Output is correct
6 Correct 1 ms 10840 KB Output is correct
7 Correct 1 ms 10840 KB Output is correct
8 Correct 1 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10840 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 10856 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10848 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 2 ms 11096 KB Output is correct
12 Correct 2 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 11092 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 1 ms 10840 KB Output is correct
6 Correct 1 ms 10840 KB Output is correct
7 Correct 1 ms 10840 KB Output is correct
8 Correct 1 ms 10840 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 1 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 2 ms 10840 KB Output is correct
14 Correct 2 ms 10856 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10848 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 11096 KB Output is correct
20 Correct 2 ms 10836 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 3 ms 10840 KB Output is correct
25 Correct 2 ms 10856 KB Output is correct
26 Correct 2 ms 10840 KB Output is correct
27 Correct 2 ms 10880 KB Output is correct
28 Correct 2 ms 10840 KB Output is correct
29 Correct 1 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 2 ms 10840 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 2 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 11096 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 469 ms 16724 KB Output is correct
2 Correct 680 ms 22608 KB Output is correct
3 Correct 679 ms 22616 KB Output is correct
4 Correct 696 ms 22608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 469 ms 16724 KB Output is correct
2 Correct 680 ms 22608 KB Output is correct
3 Correct 679 ms 22616 KB Output is correct
4 Correct 696 ms 22608 KB Output is correct
5 Correct 553 ms 16728 KB Output is correct
6 Correct 731 ms 22616 KB Output is correct
7 Correct 728 ms 22608 KB Output is correct
8 Correct 669 ms 22608 KB Output is correct
9 Correct 338 ms 11096 KB Output is correct
10 Correct 630 ms 11608 KB Output is correct
11 Correct 678 ms 11608 KB Output is correct
12 Correct 610 ms 11608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10840 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 10856 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10848 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 11096 KB Output is correct
11 Correct 2 ms 11096 KB Output is correct
12 Correct 2 ms 10836 KB Output is correct
13 Correct 469 ms 16724 KB Output is correct
14 Correct 680 ms 22608 KB Output is correct
15 Correct 679 ms 22616 KB Output is correct
16 Correct 696 ms 22608 KB Output is correct
17 Correct 553 ms 16728 KB Output is correct
18 Correct 731 ms 22616 KB Output is correct
19 Correct 728 ms 22608 KB Output is correct
20 Correct 669 ms 22608 KB Output is correct
21 Correct 338 ms 11096 KB Output is correct
22 Correct 630 ms 11608 KB Output is correct
23 Correct 678 ms 11608 KB Output is correct
24 Correct 610 ms 11608 KB Output is correct
25 Correct 749 ms 28524 KB Output is correct
26 Correct 803 ms 28752 KB Output is correct
27 Correct 860 ms 28644 KB Output is correct
28 Correct 614 ms 28752 KB Output is correct
29 Correct 778 ms 34896 KB Output is correct
30 Correct 692 ms 34896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 11092 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 1 ms 10840 KB Output is correct
6 Correct 1 ms 10840 KB Output is correct
7 Correct 1 ms 10840 KB Output is correct
8 Correct 1 ms 10840 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 1 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 2 ms 10840 KB Output is correct
14 Correct 2 ms 10856 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10848 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 11096 KB Output is correct
20 Correct 2 ms 10836 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 3 ms 10840 KB Output is correct
25 Correct 2 ms 10856 KB Output is correct
26 Correct 2 ms 10840 KB Output is correct
27 Correct 2 ms 10880 KB Output is correct
28 Correct 2 ms 10840 KB Output is correct
29 Correct 1 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 2 ms 10840 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 2 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 11096 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 499 ms 11352 KB Output is correct
44 Correct 698 ms 11352 KB Output is correct
45 Correct 579 ms 11352 KB Output is correct
46 Correct 502 ms 11608 KB Output is correct
47 Correct 607 ms 11608 KB Output is correct
48 Correct 606 ms 11608 KB Output is correct
49 Correct 645 ms 11608 KB Output is correct
50 Correct 600 ms 11608 KB Output is correct
51 Correct 588 ms 11608 KB Output is correct
52 Correct 719 ms 11608 KB Output is correct
53 Correct 582 ms 11352 KB Output is correct
54 Correct 686 ms 11608 KB Output is correct
55 Correct 657 ms 11608 KB Output is correct
56 Correct 729 ms 11608 KB Output is correct
57 Correct 684 ms 11608 KB Output is correct
58 Correct 713 ms 11864 KB Output is correct
59 Correct 695 ms 12120 KB Output is correct
60 Correct 654 ms 12120 KB Output is correct
61 Correct 738 ms 11352 KB Output is correct
62 Correct 686 ms 11352 KB Output is correct
63 Correct 643 ms 11352 KB Output is correct
64 Correct 681 ms 11608 KB Output is correct
65 Correct 329 ms 11096 KB Output is correct
66 Correct 701 ms 11608 KB Output is correct
67 Correct 694 ms 11608 KB Output is correct
68 Correct 672 ms 11608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 11092 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 1 ms 10840 KB Output is correct
6 Correct 1 ms 10840 KB Output is correct
7 Correct 1 ms 10840 KB Output is correct
8 Correct 1 ms 10840 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 1 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 2 ms 10840 KB Output is correct
14 Correct 2 ms 10856 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10848 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 11096 KB Output is correct
20 Correct 2 ms 10836 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 3 ms 10840 KB Output is correct
25 Correct 2 ms 10856 KB Output is correct
26 Correct 2 ms 10840 KB Output is correct
27 Correct 2 ms 10880 KB Output is correct
28 Correct 2 ms 10840 KB Output is correct
29 Correct 1 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 2 ms 10840 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 2 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 11096 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 469 ms 16724 KB Output is correct
44 Correct 680 ms 22608 KB Output is correct
45 Correct 679 ms 22616 KB Output is correct
46 Correct 696 ms 22608 KB Output is correct
47 Correct 553 ms 16728 KB Output is correct
48 Correct 731 ms 22616 KB Output is correct
49 Correct 728 ms 22608 KB Output is correct
50 Correct 669 ms 22608 KB Output is correct
51 Correct 338 ms 11096 KB Output is correct
52 Correct 630 ms 11608 KB Output is correct
53 Correct 678 ms 11608 KB Output is correct
54 Correct 610 ms 11608 KB Output is correct
55 Correct 749 ms 28524 KB Output is correct
56 Correct 803 ms 28752 KB Output is correct
57 Correct 860 ms 28644 KB Output is correct
58 Correct 614 ms 28752 KB Output is correct
59 Correct 778 ms 34896 KB Output is correct
60 Correct 692 ms 34896 KB Output is correct
61 Correct 499 ms 11352 KB Output is correct
62 Correct 698 ms 11352 KB Output is correct
63 Correct 579 ms 11352 KB Output is correct
64 Correct 502 ms 11608 KB Output is correct
65 Correct 607 ms 11608 KB Output is correct
66 Correct 606 ms 11608 KB Output is correct
67 Correct 645 ms 11608 KB Output is correct
68 Correct 600 ms 11608 KB Output is correct
69 Correct 588 ms 11608 KB Output is correct
70 Correct 719 ms 11608 KB Output is correct
71 Correct 582 ms 11352 KB Output is correct
72 Correct 686 ms 11608 KB Output is correct
73 Correct 657 ms 11608 KB Output is correct
74 Correct 729 ms 11608 KB Output is correct
75 Correct 684 ms 11608 KB Output is correct
76 Correct 713 ms 11864 KB Output is correct
77 Correct 695 ms 12120 KB Output is correct
78 Correct 654 ms 12120 KB Output is correct
79 Correct 738 ms 11352 KB Output is correct
80 Correct 686 ms 11352 KB Output is correct
81 Correct 643 ms 11352 KB Output is correct
82 Correct 681 ms 11608 KB Output is correct
83 Correct 329 ms 11096 KB Output is correct
84 Correct 701 ms 11608 KB Output is correct
85 Correct 694 ms 11608 KB Output is correct
86 Correct 672 ms 11608 KB Output is correct
87 Correct 1 ms 10840 KB Output is correct
88 Correct 521 ms 26560 KB Output is correct
89 Correct 767 ms 20816 KB Output is correct
90 Correct 759 ms 21840 KB Output is correct
91 Correct 796 ms 29416 KB Output is correct
92 Correct 877 ms 29248 KB Output is correct
93 Correct 801 ms 29264 KB Output is correct
94 Correct 846 ms 29448 KB Output is correct
95 Correct 707 ms 29256 KB Output is correct
96 Correct 577 ms 25524 KB Output is correct
97 Correct 739 ms 25788 KB Output is correct
98 Correct 523 ms 24064 KB Output is correct
99 Correct 714 ms 28752 KB Output is correct
100 Correct 684 ms 27852 KB Output is correct
101 Correct 732 ms 27100 KB Output is correct
102 Correct 700 ms 25688 KB Output is correct
103 Correct 730 ms 34896 KB Output is correct
104 Correct 705 ms 35888 KB Output is correct
105 Correct 571 ms 35912 KB Output is correct
106 Correct 624 ms 21072 KB Output is correct
107 Correct 638 ms 22096 KB Output is correct
108 Correct 658 ms 23636 KB Output is correct
109 Correct 718 ms 25980 KB Output is correct