답안 #1078122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078122 2024-08-27T13:01:31 Z pcc 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 12880 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);
}

ll pw(ll a,ll b){
	ll re = 1;
	while(b){
		if(b&1)re = re*a%mod;
		b>>=1;
		a = a*a%mod;
	}
	return re;
}

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){
	ll sum = 0;
	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);
	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) {
	for(int i = L;i<=R;i++){
		arr[i] ^= 1;
	}
	//cerr<<"NOW: ";for(int i = N;i<N+M;i++)cerr<<arr[i]<<' ';cerr<<endl;
	ll ans = 0;
	for(int i = N;i<N+M;i++)ans = mad(ans,dp[i]*arr[i]%mod);
	return ans;
	//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:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 0;i<tree[now].size();i++){
      |                ~^~~~~~~~~~~~~~~~~
circuit.cpp:53:5: warning: unused variable 'sum' [-Wunused-variable]
   53 |  ll sum = 0;
      |     ^~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:83:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   83 |  for(int i = 0;i<N+M;i++)cerr<<sz[i]<<' ';cerr<<endl;
      |  ^~~
circuit.cpp:83:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   83 |  for(int i = 0;i<N+M;i++)cerr<<sz[i]<<' ';cerr<<endl;
      |                                           ^~~~
circuit.cpp:85:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   85 |  for(int i = 0;i<N+M;i++)cerr<<dp[i]<<' ';cerr<<endl;
      |  ^~~
circuit.cpp:85:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |  for(int i = 0;i<N+M;i++)cerr<<dp[i]<<' ';cerr<<endl;
      |                                           ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 2 ms 8280 KB Output is correct
3 Correct 6 ms 8280 KB Output is correct
4 Correct 6 ms 10328 KB Output is correct
5 Correct 6 ms 8280 KB Output is correct
6 Correct 5 ms 10328 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 6 ms 8240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 4 ms 10328 KB Output is correct
3 Correct 7 ms 8280 KB Output is correct
4 Correct 6 ms 10328 KB Output is correct
5 Correct 6 ms 10328 KB Output is correct
6 Correct 8 ms 8280 KB Output is correct
7 Correct 11 ms 10516 KB Output is correct
8 Correct 10 ms 8504 KB Output is correct
9 Correct 10 ms 8280 KB Output is correct
10 Correct 10 ms 8644 KB Output is correct
11 Correct 16 ms 8536 KB Output is correct
12 Correct 8 ms 10328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 2 ms 8280 KB Output is correct
3 Correct 6 ms 8280 KB Output is correct
4 Correct 6 ms 10328 KB Output is correct
5 Correct 6 ms 8280 KB Output is correct
6 Correct 5 ms 10328 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 6 ms 8240 KB Output is correct
9 Correct 2 ms 10328 KB Output is correct
10 Correct 4 ms 10328 KB Output is correct
11 Correct 7 ms 8280 KB Output is correct
12 Correct 6 ms 10328 KB Output is correct
13 Correct 6 ms 10328 KB Output is correct
14 Correct 8 ms 8280 KB Output is correct
15 Correct 11 ms 10516 KB Output is correct
16 Correct 10 ms 8504 KB Output is correct
17 Correct 10 ms 8280 KB Output is correct
18 Correct 10 ms 8644 KB Output is correct
19 Correct 16 ms 8536 KB Output is correct
20 Correct 8 ms 10328 KB Output is correct
21 Correct 9 ms 8280 KB Output is correct
22 Correct 7 ms 8280 KB Output is correct
23 Correct 7 ms 10484 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 10 ms 10328 KB Output is correct
26 Correct 10 ms 10512 KB Output is correct
27 Correct 10 ms 10328 KB Output is correct
28 Correct 10 ms 10328 KB Output is correct
29 Correct 6 ms 10328 KB Output is correct
30 Correct 6 ms 10328 KB Output is correct
31 Correct 6 ms 10584 KB Output is correct
32 Correct 10 ms 10328 KB Output is correct
33 Correct 8 ms 10328 KB Output is correct
34 Correct 7 ms 10480 KB Output is correct
35 Correct 5 ms 10328 KB Output is correct
36 Correct 10 ms 10672 KB Output is correct
37 Correct 11 ms 10416 KB Output is correct
38 Correct 10 ms 8536 KB Output is correct
39 Correct 7 ms 8280 KB Output is correct
40 Correct 8 ms 8460 KB Output is correct
41 Correct 7 ms 8280 KB Output is correct
42 Correct 6 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3034 ms 12880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3034 ms 12880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 4 ms 10328 KB Output is correct
3 Correct 7 ms 8280 KB Output is correct
4 Correct 6 ms 10328 KB Output is correct
5 Correct 6 ms 10328 KB Output is correct
6 Correct 8 ms 8280 KB Output is correct
7 Correct 11 ms 10516 KB Output is correct
8 Correct 10 ms 8504 KB Output is correct
9 Correct 10 ms 8280 KB Output is correct
10 Correct 10 ms 8644 KB Output is correct
11 Correct 16 ms 8536 KB Output is correct
12 Correct 8 ms 10328 KB Output is correct
13 Execution timed out 3034 ms 12880 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 2 ms 8280 KB Output is correct
3 Correct 6 ms 8280 KB Output is correct
4 Correct 6 ms 10328 KB Output is correct
5 Correct 6 ms 8280 KB Output is correct
6 Correct 5 ms 10328 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 6 ms 8240 KB Output is correct
9 Correct 2 ms 10328 KB Output is correct
10 Correct 4 ms 10328 KB Output is correct
11 Correct 7 ms 8280 KB Output is correct
12 Correct 6 ms 10328 KB Output is correct
13 Correct 6 ms 10328 KB Output is correct
14 Correct 8 ms 8280 KB Output is correct
15 Correct 11 ms 10516 KB Output is correct
16 Correct 10 ms 8504 KB Output is correct
17 Correct 10 ms 8280 KB Output is correct
18 Correct 10 ms 8644 KB Output is correct
19 Correct 16 ms 8536 KB Output is correct
20 Correct 8 ms 10328 KB Output is correct
21 Correct 9 ms 8280 KB Output is correct
22 Correct 7 ms 8280 KB Output is correct
23 Correct 7 ms 10484 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 10 ms 10328 KB Output is correct
26 Correct 10 ms 10512 KB Output is correct
27 Correct 10 ms 10328 KB Output is correct
28 Correct 10 ms 10328 KB Output is correct
29 Correct 6 ms 10328 KB Output is correct
30 Correct 6 ms 10328 KB Output is correct
31 Correct 6 ms 10584 KB Output is correct
32 Correct 10 ms 10328 KB Output is correct
33 Correct 8 ms 10328 KB Output is correct
34 Correct 7 ms 10480 KB Output is correct
35 Correct 5 ms 10328 KB Output is correct
36 Correct 10 ms 10672 KB Output is correct
37 Correct 11 ms 10416 KB Output is correct
38 Correct 10 ms 8536 KB Output is correct
39 Correct 7 ms 8280 KB Output is correct
40 Correct 8 ms 8460 KB Output is correct
41 Correct 7 ms 8280 KB Output is correct
42 Correct 6 ms 8280 KB Output is correct
43 Correct 866 ms 8536 KB Output is correct
44 Correct 1142 ms 8536 KB Output is correct
45 Correct 1250 ms 8532 KB Output is correct
46 Correct 1612 ms 10824 KB Output is correct
47 Correct 1596 ms 10808 KB Output is correct
48 Correct 1620 ms 8792 KB Output is correct
49 Correct 1594 ms 10776 KB Output is correct
50 Correct 1647 ms 10832 KB Output is correct
51 Correct 1649 ms 10680 KB Output is correct
52 Correct 1555 ms 8680 KB Output is correct
53 Correct 606 ms 9304 KB Output is correct
54 Correct 1620 ms 10840 KB Output is correct
55 Correct 1597 ms 8672 KB Output is correct
56 Correct 1574 ms 8536 KB Output is correct
57 Correct 1593 ms 10584 KB Output is correct
58 Correct 1637 ms 9560 KB Output is correct
59 Correct 1623 ms 9560 KB Output is correct
60 Correct 1764 ms 11604 KB Output is correct
61 Correct 1072 ms 6744 KB Output is correct
62 Correct 1321 ms 6652 KB Output is correct
63 Correct 1359 ms 6488 KB Output is correct
64 Correct 1595 ms 6488 KB Output is correct
65 Correct 537 ms 6568 KB Output is correct
66 Correct 1424 ms 8740 KB Output is correct
67 Correct 1500 ms 6744 KB Output is correct
68 Correct 1564 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10328 KB Output is correct
2 Correct 2 ms 8280 KB Output is correct
3 Correct 6 ms 8280 KB Output is correct
4 Correct 6 ms 10328 KB Output is correct
5 Correct 6 ms 8280 KB Output is correct
6 Correct 5 ms 10328 KB Output is correct
7 Correct 6 ms 8280 KB Output is correct
8 Correct 6 ms 8240 KB Output is correct
9 Correct 2 ms 10328 KB Output is correct
10 Correct 4 ms 10328 KB Output is correct
11 Correct 7 ms 8280 KB Output is correct
12 Correct 6 ms 10328 KB Output is correct
13 Correct 6 ms 10328 KB Output is correct
14 Correct 8 ms 8280 KB Output is correct
15 Correct 11 ms 10516 KB Output is correct
16 Correct 10 ms 8504 KB Output is correct
17 Correct 10 ms 8280 KB Output is correct
18 Correct 10 ms 8644 KB Output is correct
19 Correct 16 ms 8536 KB Output is correct
20 Correct 8 ms 10328 KB Output is correct
21 Correct 9 ms 8280 KB Output is correct
22 Correct 7 ms 8280 KB Output is correct
23 Correct 7 ms 10484 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 10 ms 10328 KB Output is correct
26 Correct 10 ms 10512 KB Output is correct
27 Correct 10 ms 10328 KB Output is correct
28 Correct 10 ms 10328 KB Output is correct
29 Correct 6 ms 10328 KB Output is correct
30 Correct 6 ms 10328 KB Output is correct
31 Correct 6 ms 10584 KB Output is correct
32 Correct 10 ms 10328 KB Output is correct
33 Correct 8 ms 10328 KB Output is correct
34 Correct 7 ms 10480 KB Output is correct
35 Correct 5 ms 10328 KB Output is correct
36 Correct 10 ms 10672 KB Output is correct
37 Correct 11 ms 10416 KB Output is correct
38 Correct 10 ms 8536 KB Output is correct
39 Correct 7 ms 8280 KB Output is correct
40 Correct 8 ms 8460 KB Output is correct
41 Correct 7 ms 8280 KB Output is correct
42 Correct 6 ms 8280 KB Output is correct
43 Execution timed out 3034 ms 12880 KB Time limit exceeded
44 Halted 0 ms 0 KB -