Submission #787965

# Submission time Handle Problem Language Result Execution time Memory
787965 2023-07-19T15:32:48 Z khshg Digital Circuit (IOI22_circuit) C++17
Compilation error
0 ms 0 KB
#include"circuit.h"
#include<bits/stdc++.h>

const long long MOD =  1000002022;

long long MUL(long long A, long long B) {
	return A * B % MOD;
}

long long ADD(long long A, long long B) {
	A += B;
	if(A >= MOD) A -= MOD;
	return A;
}

long long SUB(long long A, long long B) {
	return ADD(A, MOD - B);
}

int N, M;
vector<vector<int>> ch;
vector<int> par, stat;
vector<long long> sz, val;
long long ans;

void dfs(int s) {
	if(ch[s].empty()) {
		sz[s] = 1LL;
		return;
	}
	sz[s] = 2LL;
	for(auto& u : ch) {
		dfs(u);
		sz[s] = MUL(sz[s], sz[u]);
	}
}

void ass_val(int s, long long v) {
	if(ch[s].empty()) { val[s - N] = v; return; }
	ass_val(ch[s][0], MUL(v, sz[ch[s][1]]));
	ass_val(ch[s][1], MUL(v, sz[ch[s][0]]));
}

void init(int _N, int _M, vector<int> P, vector<int> A) {
	N = _N; M = _M;
	swap(P, par);
	swap(A, stat);
	val.resize(M);
	ch.resize(N + M);
	sz.resize(N + M);
	for(int i = 1; i < N + M; ++i) {
		ch[par[i]].push_back(i);
	}
	dfs(0);
	ass_val(0, 1LL);
	for(int i = 0; i < M; ++i) {
		if(stat[i]) ans = ADD(ans, val[i]);
	}
}

int count_ways(int L, int R) {
	if(stat[L]) ans = SUB(ans, val[L]);
	stat[L] = stat[L] ^ true;
	return ans;
}

Compilation message

circuit.cpp:21:1: error: 'vector' does not name a type
   21 | vector<vector<int>> ch;
      | ^~~~~~
circuit.cpp:22:1: error: 'vector' does not name a type
   22 | vector<int> par, stat;
      | ^~~~~~
circuit.cpp:23:1: error: 'vector' does not name a type
   23 | vector<long long> sz, val;
      | ^~~~~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:27:5: error: 'ch' was not declared in this scope
   27 |  if(ch[s].empty()) {
      |     ^~
circuit.cpp:28:3: error: 'sz' was not declared in this scope; did you mean 's'?
   28 |   sz[s] = 1LL;
      |   ^~
      |   s
circuit.cpp:31:2: error: 'sz' was not declared in this scope; did you mean 's'?
   31 |  sz[s] = 2LL;
      |  ^~
      |  s
circuit.cpp:32:16: error: 'ch' was not declared in this scope
   32 |  for(auto& u : ch) {
      |                ^~
circuit.cpp: In function 'void ass_val(int, long long int)':
circuit.cpp:39:5: error: 'ch' was not declared in this scope
   39 |  if(ch[s].empty()) { val[s - N] = v; return; }
      |     ^~
circuit.cpp:39:22: error: 'val' was not declared in this scope
   39 |  if(ch[s].empty()) { val[s - N] = v; return; }
      |                      ^~~
circuit.cpp:40:10: error: 'ch' was not declared in this scope
   40 |  ass_val(ch[s][0], MUL(v, sz[ch[s][1]]));
      |          ^~
circuit.cpp:40:27: error: 'sz' was not declared in this scope; did you mean 's'?
   40 |  ass_val(ch[s][0], MUL(v, sz[ch[s][1]]));
      |                           ^~
      |                           s
circuit.cpp: At global scope:
circuit.cpp:44:27: error: 'vector' has not been declared
   44 | void init(int _N, int _M, vector<int> P, vector<int> A) {
      |                           ^~~~~~
circuit.cpp:44:33: error: expected ',' or '...' before '<' token
   44 | void init(int _N, int _M, vector<int> P, vector<int> A) {
      |                                 ^
circuit.cpp: In function 'void init(int, int, int)':
circuit.cpp:46:7: error: 'P' was not declared in this scope
   46 |  swap(P, par);
      |       ^
circuit.cpp:46:10: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   46 |  swap(P, par);
      |          ^~~
      |          __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from circuit.cpp:2:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
circuit.cpp:46:2: error: 'swap' was not declared in this scope
   46 |  swap(P, par);
      |  ^~~~
circuit.cpp:46:2: note: suggested alternatives:
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from circuit.cpp:2:
/usr/include/c++/10/bits/regex.h:2141:5: note:   'std::__cxx11::swap'
 2141 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from circuit.h:1,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/move.h:189:5: note:   'std::swap'
  189 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/10/bits/move.h:189:5: note:   'std::swap'
In file included from /usr/include/c++/10/exception:147,
                 from /usr/include/c++/10/new:41,
                 from /usr/include/c++/10/ext/new_allocator.h:33,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
                 from /usr/include/c++/10/bits/allocator.h:46,
                 from /usr/include/c++/10/vector:64,
                 from circuit.h:1,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/exception_ptr.h:169:5: note:   'std::__exception_ptr::swap'
  169 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/10/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from circuit.cpp:2:
/usr/include/c++/10/bits/fs_path.h:658:15: note:   'std::filesystem::__cxx11::swap'
  658 |   inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
      |               ^~~~
circuit.cpp:47:7: error: 'A' was not declared in this scope
   47 |  swap(A, stat);
      |       ^
circuit.cpp:47:10: error: 'stat' was not declared in this scope; did you mean 'strcat'?
   47 |  swap(A, stat);
      |          ^~~~
      |          strcat
circuit.cpp:48:2: error: 'val' was not declared in this scope
   48 |  val.resize(M);
      |  ^~~
circuit.cpp:49:2: error: 'ch' was not declared in this scope
   49 |  ch.resize(N + M);
      |  ^~
circuit.cpp:50:2: error: 'sz' was not declared in this scope
   50 |  sz.resize(N + M);
      |  ^~
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:62:5: error: 'stat' was not declared in this scope; did you mean 'strcat'?
   62 |  if(stat[L]) ans = SUB(ans, val[L]);
      |     ^~~~
      |     strcat
circuit.cpp:62:29: error: 'val' was not declared in this scope
   62 |  if(stat[L]) ans = SUB(ans, val[L]);
      |                             ^~~
circuit.cpp:63:2: error: 'stat' was not declared in this scope; did you mean 'strcat'?
   63 |  stat[L] = stat[L] ^ true;
      |  ^~~~
      |  strcat