Submission #719058

#TimeUsernameProblemLanguageResultExecution timeMemory
719058baojiaopisuDigital Circuit (IOI22_circuit)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; #define fi first #define se second #define left BAO #define right ANH #define pb push_back #define pf push_front #define mp make_pair #define ins insert #define btpc __builtin_popcount #define btclz __builtin_clz #define sz(x) (int)(x.size()); #define all(x) x.begin(), x.end() #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1}; int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1}; template<class X, class Y> bool minimize(X &x, const Y &y) { if (x > y) { x = y; return true; } return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { if (x < y) { x = y; return true; } return false; } const int MOD = 1000002022; //998244353 template<class X, class Y> void add(X &x, const Y &y) { x = (x + y); if(x >= MOD) x -= MOD; } template<class X, class Y> void sub(X &x, const Y &y) { x = (x - y); if(x < 0) x += MOD; } /* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/ const ll INF = 1e9; const int N = 1000 + 10; vector<int> g[N]; ll dp[N][2], f[N][N]; struct SegTree { int n; struct Node { int one, zero; int lazy; Node(int _one = 0, int _zero = 0, int _lazy = 0) { one = _one; zero = _zero; lazy = _lazy; } }; vector<Node> node; SegTree(int _n = 0) { n = _n; node.resize(4 * n + 7); build(0, n - 1, 1); } private: void build(int l, int r, int id) { node[id].zero = r - l + 1; if(l == r) return; int mid = (l + r) >> 1; build(l, mid, id << 1); build(mid + 1, r, id << 1 | 1); } void Down(int id) { if(!node[id].lazy) return; node[id].lazy = 0; for(int i = (id << 1); i <= (id << 1 | 1); i++) { swap(node[i].one, node[i].zero); node[i].lazy ^= 1; } } Node merge(const Node &a, const Node &b) { Node ans = Node(); ans.one = a.one + b.one; ans.zero = a.zero + b.zero; return ans; } void Update(int l, int r, int lo, int hi, int id) { if(l > hi || r < lo) return; if(lo <= l && r <= hi) { swap(node[id].one, node[id].zero); node[id].lazy ^= 1; return; } int mid = (l + r) >> 1; Down(id); Update(l, mid, lo, hi, id << 1); Update(mid + 1, r, lo, hi, id << 1 | 1); node[id] = merge(node[id << 1], node[id << 1 | 1]); } public: void update(int l, int r) { Update(0, n - 1, l, r, 1); } }; SegTree IT = SegTree(1); int n, m; ll coef = 0; vector<int> state; void init(int N, int M, vector<int> p, vector<int> A) { for(int i = 1; i < N + M; i++) { g[p[i]].pb(i); } n = N; m = M; state = A; coef = 1; IT = SegTree(m); for(int i = 0; i < m; i++) { if(state[i]) IT.update(i, i); } int d = m, f = 0; while(d > 1) { d /= 2; f++; } for(int i = 0; i < n - f; i++) { coef = (coef * 2) % MOD; } } void dfs(int u) { if(u >= n) return; for(int i = 0; i <= g[u].size(); i++) f[u][i] = 0; f[u][0] = 1; for(auto v : g[u]) { dfs(v); for(int i = g[u].size(); i >= 0; i--) { f[u][i] = f[u][i] * dp[v][0] % MOD; if(i > 0) f[u][i] += f[u][i - 1] * dp[v][1] % MOD; f[u][i] %= MOD; } } dp[u][0] = dp[u][1] = 0; for(int i = 0; i <= g[u].size(); i++) { dp[u][1] += f[u][i] * i % MOD; dp[u][0] += f[u][i] * (g[u].size() - i) % MOD; dp[u][0] %= MOD; dp[u][1] %= MOD; } // IT = SegTree(m); } ll count_ways(int l, int r) { l -= n; r -= n; if(n <= 1000 && m <= 1000) { for(int i = l; i <= r; i++) state[i] ^= 1; for(int i = n; i < n + m; i++) { dp[i][1] = state[i - n]; dp[i][0] = state[i - n] ^ 1; } dfs(0); return dp[0][1]; } IT.update(l, r); return (coef * IT.node[1].one) % MOD; } void BaoJiaoPisu() { int n, m, q; cin >> n >> m >> q; vector<int> p(n + m); vector<int> a(m); for(int i = 0; i < n + m; i++) { cin >> p[i]; } for(int i = 0; i < m; i++) { cin >> a[i]; } init(n, m, p, a); while(q--) { int l, r; cin >> l >> r; cout << count_ways(l, r) << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else //online #endif int tc = 1, ddd = 0; // cin >> tc; while(tc--) { //ddd++; //cout << "Case #" << ddd << ": "; BaoJiaoPisu(); } }

Compilation message (stderr)

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:167:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |  for(int i = 0; i <= g[u].size(); i++) f[u][i] = 0;
      |                 ~~^~~~~~~~~~~~~~
circuit.cpp:179:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  179 |  for(int i = 0; i <= g[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~
circuit.cpp: In function 'int main()':
circuit.cpp:237:17: warning: unused variable 'ddd' [-Wunused-variable]
  237 |     int tc = 1, ddd = 0;
      |                 ^~~
circuit.cpp:231:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  231 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
circuit.cpp:232:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  232 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc50LQ0B.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cctF2aDy.o:circuit.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status