답안 #1078301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078301 2024-08-27T15:03:36 Z pcc 디지털 회로 (IOI22_circuit) C++17
100 / 100
833 ms 34968 KB
#include "circuit.h"

#include <vector>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second

const int mxn = 2e5+10;

const ll mod = 1000002022;

vector<int> tree[mxn];
int par[mxn];
int N,M;
ll dp[mxn];
ll sz[mxn];
ll arr[mxn];

ll mad(ll a,ll b){
	a += b;
	return a>=mod?a-mod:a;
}
ll mub(ll a,ll b){
	return mad(a,mod-b);
}


struct SEG{
#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
	ll seg[mxn*4][2];
	int tag[mxn*4];
	void push(int now,int l,int r){
		if(!tag[now])return;
		tag[ls] ^= 1;
		tag[rs] ^= 1;
		tag[now] = 0;
		swap(seg[ls][0],seg[ls][1]);
		swap(seg[rs][0],seg[rs][1]);
		return;
	}
	void build(int now,int l,int r){
		if(l == r){
			seg[now][arr[l]] = dp[l];
			return;
		}
		build(ls,l,mid);
		build(rs,mid+1,r);
		seg[now][0] = mad(seg[ls][0],seg[rs][0]);
		seg[now][1] = mad(seg[ls][1],seg[rs][1]);
	}
	void modify(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r){
			swap(seg[now][0],seg[now][1]);
			tag[now] ^= 1;
			return;
		}
		push(now,l,r);
		if(mid>=s)modify(ls,l,mid,s,e);
		if(mid<e)modify(rs,mid+1,r,s,e);
		seg[now][0] = mad(seg[ls][0],seg[rs][0]);
		seg[now][1] = mad(seg[ls][1],seg[rs][1]);
	}
	ll getval(){
		return seg[0][1];
	}
};

SEG seg;

void dfs(int now){
	dp[now] = sz[now] = 1;
	for(auto nxt:tree[now]){
		dfs(nxt);
		sz[now] = sz[nxt]*sz[now]%mod;
	}
	if(tree[now].size())sz[now] = sz[now]*tree[now].size()%mod;
	return;
}

void dfs1(int now){
	vector<ll> suf;
	for(auto nxt:tree[now]){
		suf.push_back(sz[nxt]);
	}
	suf.push_back(1);
	for(int i = (int)suf.size()-2;i>=0;i--)suf[i] = suf[i+1]*suf[i]%mod;
	ll pref = 1;
	for(int i = 0;i<tree[now].size();i++){
		int nxt = tree[now][i];
		ll ts = pref*suf[i+1]%mod;
		dp[nxt] = dp[now]*ts%mod;
		dfs1(nxt);
		pref = pref*sz[nxt]%mod;
	}
	return;
}

void init(int N1, int M1, std::vector<int> P, std::vector<int> A) {
	N = N1,M = M1;
	for(int i = 1;i<N+M;i++){
		par[i] = P[i];
		tree[par[i]].push_back(i);
	}
	for(int i = 0;i<M;i++){
		arr[i+N] = A[i];
	}
	dfs(0);
	dfs1(0);
	seg.build(0,N,N+M-1);
	/*
	cerr<<"SZ: ";
	for(int i = 0;i<N+M;i++)cerr<<sz[i]<<' ';cerr<<endl;
	cerr<<"DP: ";
	for(int i = 0;i<N+M;i++)cerr<<dp[i]<<' ';cerr<<endl;
	*/
	//for(int i = 0;i<N+M;i++)cerr<<dp[i][0]<<','<<dp[i][1]<<' ';cerr<<endl;
}

int count_ways(int L, int R) {
	seg.modify(0,N,N+M-1,L,R);
	//cerr<<"NOW: ";for(int i = N;i<N+M;i++)cerr<<arr[i]<<' ';cerr<<endl;
	return seg.getval();
	//dfs(0);
	//cerr<<"NOW: ";
	//for(int i = N;i<N+M;i++)cerr<<(dp[i][0]?0:1);cerr<<endl;
}

Compilation message

circuit.cpp: In function 'void dfs1(int)':
circuit.cpp:95:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for(int i = 0;i<tree[now].size();i++){
      |                ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 4 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 4 ms 5208 KB Output is correct
9 Correct 4 ms 5208 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 3 ms 5464 KB Output is correct
12 Correct 3 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 4 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 4 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 3 ms 5464 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 4 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 3 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 5216 KB Output is correct
29 Correct 3 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 3 ms 5084 KB Output is correct
34 Correct 3 ms 5460 KB Output is correct
35 Correct 3 ms 5264 KB Output is correct
36 Correct 3 ms 5452 KB Output is correct
37 Correct 3 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 3 ms 5276 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 479 ms 9304 KB Output is correct
2 Correct 643 ms 13656 KB Output is correct
3 Correct 703 ms 13648 KB Output is correct
4 Correct 731 ms 13768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 479 ms 9304 KB Output is correct
2 Correct 643 ms 13656 KB Output is correct
3 Correct 703 ms 13648 KB Output is correct
4 Correct 731 ms 13768 KB Output is correct
5 Correct 534 ms 9424 KB Output is correct
6 Correct 728 ms 13856 KB Output is correct
7 Correct 833 ms 13832 KB Output is correct
8 Correct 672 ms 13848 KB Output is correct
9 Correct 319 ms 5208 KB Output is correct
10 Correct 696 ms 5720 KB Output is correct
11 Correct 622 ms 5720 KB Output is correct
12 Correct 677 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 4 ms 5208 KB Output is correct
9 Correct 4 ms 5208 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 3 ms 5464 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 479 ms 9304 KB Output is correct
14 Correct 643 ms 13656 KB Output is correct
15 Correct 703 ms 13648 KB Output is correct
16 Correct 731 ms 13768 KB Output is correct
17 Correct 534 ms 9424 KB Output is correct
18 Correct 728 ms 13856 KB Output is correct
19 Correct 833 ms 13832 KB Output is correct
20 Correct 672 ms 13848 KB Output is correct
21 Correct 319 ms 5208 KB Output is correct
22 Correct 696 ms 5720 KB Output is correct
23 Correct 622 ms 5720 KB Output is correct
24 Correct 677 ms 5720 KB Output is correct
25 Correct 763 ms 19128 KB Output is correct
26 Correct 758 ms 19380 KB Output is correct
27 Correct 782 ms 19272 KB Output is correct
28 Correct 594 ms 19416 KB Output is correct
29 Correct 775 ms 34916 KB Output is correct
30 Correct 694 ms 34896 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 4 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 4 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 3 ms 5464 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 4 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 3 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 5216 KB Output is correct
29 Correct 3 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 3 ms 5084 KB Output is correct
34 Correct 3 ms 5460 KB Output is correct
35 Correct 3 ms 5264 KB Output is correct
36 Correct 3 ms 5452 KB Output is correct
37 Correct 3 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 3 ms 5276 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 2 ms 5208 KB Output is correct
43 Correct 478 ms 5464 KB Output is correct
44 Correct 684 ms 5464 KB Output is correct
45 Correct 673 ms 5464 KB Output is correct
46 Correct 660 ms 5976 KB Output is correct
47 Correct 664 ms 5976 KB Output is correct
48 Correct 653 ms 5976 KB Output is correct
49 Correct 681 ms 5976 KB Output is correct
50 Correct 629 ms 5720 KB Output is correct
51 Correct 604 ms 5768 KB Output is correct
52 Correct 616 ms 5812 KB Output is correct
53 Correct 615 ms 5976 KB Output is correct
54 Correct 673 ms 5976 KB Output is correct
55 Correct 641 ms 5716 KB Output is correct
56 Correct 717 ms 5720 KB Output is correct
57 Correct 655 ms 5720 KB Output is correct
58 Correct 715 ms 6744 KB Output is correct
59 Correct 635 ms 6744 KB Output is correct
60 Correct 647 ms 6744 KB Output is correct
61 Correct 640 ms 5720 KB Output is correct
62 Correct 654 ms 5748 KB Output is correct
63 Correct 610 ms 5712 KB Output is correct
64 Correct 700 ms 5720 KB Output is correct
65 Correct 290 ms 5208 KB Output is correct
66 Correct 616 ms 5720 KB Output is correct
67 Correct 697 ms 5720 KB Output is correct
68 Correct 651 ms 5720 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 4 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 4 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 3 ms 5464 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 4 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 3 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 5216 KB Output is correct
29 Correct 3 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 3 ms 5084 KB Output is correct
34 Correct 3 ms 5460 KB Output is correct
35 Correct 3 ms 5264 KB Output is correct
36 Correct 3 ms 5452 KB Output is correct
37 Correct 3 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 3 ms 5276 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 2 ms 5208 KB Output is correct
43 Correct 479 ms 9304 KB Output is correct
44 Correct 643 ms 13656 KB Output is correct
45 Correct 703 ms 13648 KB Output is correct
46 Correct 731 ms 13768 KB Output is correct
47 Correct 534 ms 9424 KB Output is correct
48 Correct 728 ms 13856 KB Output is correct
49 Correct 833 ms 13832 KB Output is correct
50 Correct 672 ms 13848 KB Output is correct
51 Correct 319 ms 5208 KB Output is correct
52 Correct 696 ms 5720 KB Output is correct
53 Correct 622 ms 5720 KB Output is correct
54 Correct 677 ms 5720 KB Output is correct
55 Correct 763 ms 19128 KB Output is correct
56 Correct 758 ms 19380 KB Output is correct
57 Correct 782 ms 19272 KB Output is correct
58 Correct 594 ms 19416 KB Output is correct
59 Correct 775 ms 34916 KB Output is correct
60 Correct 694 ms 34896 KB Output is correct
61 Correct 478 ms 5464 KB Output is correct
62 Correct 684 ms 5464 KB Output is correct
63 Correct 673 ms 5464 KB Output is correct
64 Correct 660 ms 5976 KB Output is correct
65 Correct 664 ms 5976 KB Output is correct
66 Correct 653 ms 5976 KB Output is correct
67 Correct 681 ms 5976 KB Output is correct
68 Correct 629 ms 5720 KB Output is correct
69 Correct 604 ms 5768 KB Output is correct
70 Correct 616 ms 5812 KB Output is correct
71 Correct 615 ms 5976 KB Output is correct
72 Correct 673 ms 5976 KB Output is correct
73 Correct 641 ms 5716 KB Output is correct
74 Correct 717 ms 5720 KB Output is correct
75 Correct 655 ms 5720 KB Output is correct
76 Correct 715 ms 6744 KB Output is correct
77 Correct 635 ms 6744 KB Output is correct
78 Correct 647 ms 6744 KB Output is correct
79 Correct 640 ms 5720 KB Output is correct
80 Correct 654 ms 5748 KB Output is correct
81 Correct 610 ms 5712 KB Output is correct
82 Correct 700 ms 5720 KB Output is correct
83 Correct 290 ms 5208 KB Output is correct
84 Correct 616 ms 5720 KB Output is correct
85 Correct 697 ms 5720 KB Output is correct
86 Correct 651 ms 5720 KB Output is correct
87 Correct 3 ms 4952 KB Output is correct
88 Correct 438 ms 18608 KB Output is correct
89 Correct 705 ms 13908 KB Output is correct
90 Correct 735 ms 13448 KB Output is correct
91 Correct 729 ms 19340 KB Output is correct
92 Correct 807 ms 19388 KB Output is correct
93 Correct 777 ms 19388 KB Output is correct
94 Correct 747 ms 19388 KB Output is correct
95 Correct 731 ms 19280 KB Output is correct
96 Correct 703 ms 13888 KB Output is correct
97 Correct 720 ms 14336 KB Output is correct
98 Correct 580 ms 24912 KB Output is correct
99 Correct 748 ms 19280 KB Output is correct
100 Correct 748 ms 16560 KB Output is correct
101 Correct 740 ms 15680 KB Output is correct
102 Correct 706 ms 14324 KB Output is correct
103 Correct 738 ms 34968 KB Output is correct
104 Correct 738 ms 33888 KB Output is correct
105 Correct 701 ms 33940 KB Output is correct
106 Correct 725 ms 16720 KB Output is correct
107 Correct 704 ms 15140 KB Output is correct
108 Correct 653 ms 14796 KB Output is correct
109 Correct 719 ms 14432 KB Output is correct