Submission #1066191

#TimeUsernameProblemLanguageResultExecution timeMemory
1066191blackslexWerewolf (IOI18_werewolf)C++17
34 / 100
274 ms68496 KiB
#include "werewolf.h" #include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y, std::vector<int> S, std::vector<int> E, std::vector<int> L, std::vector<int> R) { int n = N, m = X.size(), q = S.size(); vector<vector<int>> v(n, vector<int>()); vector<int> a(n), par(n), mx(n), mn(n); iota(par.begin(), par.end(), 0); for (int i = 0; i < m; i++) v[X[i]].emplace_back(Y[i]), v[Y[i]].emplace_back(X[i]); int st = -1, curidx = -1; for (int i = 0; i < n; i++) if (v[i].size() == 1) st = i; function<void(int, int)> dfs = [&] (int cur, int par) { a[++curidx] = cur; for (auto &e: v[cur]) { if (par == e) continue; dfs(e, cur); } }; dfs(st, -1); for (int i = 0; i < n; i++) mx[a[i]] = mn[a[i]] = i; function<int(int)> fset = [&] (int x) {return (par[x] == x ? x : par[x] = fset(par[x]));}; auto mg = [&] (int x, int y) { if ((x = fset(x)) == (y = fset(y))) return; mx[x] = max(mx[x], mx[y]); mn[x] = min(mn[x], mn[y]); par[y] = x; }; vector<vector<pii>> ev(n), ev2(n); vector<pii> ival(q), ival2(q); for (int i = 0; i < q; i++) { int cs = S[i], ce = E[i], cl = L[i], cr = R[i]; ev[L[i]].emplace_back(cs, i); ev2[R[i]].emplace_back(ce, i); } vector<int> ans(q); for (int i = n - 1; i >= 0; i--) { for (auto &e: v[i]) if (e >= i) mg(i, e); for (auto &[x, y]: ev[i]) ival[y] = pii(mn[fset(x)], mx[fset(x)]); } iota(par.begin(), par.end(), 0); for (int i = 0; i < n; i++) mx[a[i]] = mn[a[i]] = i; for (int i = 0; i < n; i++) { for (auto &e: v[i]) if (e <= i) mg(i, e); for (auto &[x, y]: ev2[i]) ival2[y] = pii(mn[fset(x)], mx[fset(x)]); } for (int i = 0; i < q; i++) { auto ck = [&] (int x, int y, int z) { return z >= x && z <= y; }; if (ck(ival[i].first, ival[i].second, ival2[i].first)) ans[i] = 1; if (ck(ival[i].first, ival[i].second, ival2[i].second)) ans[i] = 1; if (ck(ival2[i].first, ival2[i].second, ival[i].first)) ans[i] = 1; if (ck(ival2[i].first, ival2[i].second, ival[i].second)) ans[i] = 1; } return ans; }

Compilation message (stderr)

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:36:31: warning: unused variable 'cl' [-Wunused-variable]
   36 |     int cs = S[i], ce = E[i], cl = L[i], cr = R[i];
      |                               ^~
werewolf.cpp:36:42: warning: unused variable 'cr' [-Wunused-variable]
   36 |     int cs = S[i], ce = E[i], cl = L[i], cr = R[i];
      |                                          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...