Submission #296132

#TimeUsernameProblemLanguageResultExecution timeMemory
296132TangentWerewolf (IOI18_werewolf)C++17
49 / 100
511 ms37880 KiB
#include <bits/stdc++.h> #include "werewolf.h" using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order(), order_of_key() typedef long long ll; typedef long double dd; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<dd, dd> pdd; typedef vector<int> vii; typedef vector<ll> vll; typedef vector<dd> vdd; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<vii> vvii; typedef vector<vll> vvll; typedef vector<vdd> vvdd; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; typedef vector<vpdd> vvpdd; typedef vector<bool> vb; const int inf = 1 << 30; #define rep(i, n) for (ll i = 0; i < n; i++) #define ffor(i, a, b) for(ll i = a; i < b; i++) #define forin(x, a) for (auto &x: a) #define all(x) x.begin(), x.end() #ifdef TEST #define dbg(x) cout << #x << ": " << x << '\n'; #define dbgc(x) cout << #x << ":"; forin(a, x) { cout << " " << a; } cout << endl; #define tassert(x) assert(x); #else #define dbg(x) #define dbgc(x) #define tassert(x) #endif void buildmin(vii &t, int v, int tl, int tr, vii &chain) { if (tl == tr) { t[v] = chain[tl]; } else { int tm = (tl + tr) / 2; buildmin(t, v << 1, tl, tm, chain); buildmin(t, v << 1 | 1, tm + 1, tr, chain); t[v] = min(t[v << 1], t[v << 1 | 1]); } } void buildmax(vii &t, int v, int tl, int tr, vii &chain) { if (tl == tr) { t[v] = chain[tl]; } else { int tm = (tl + tr) / 2; buildmax(t, v << 1, tl, tm, chain); buildmax(t, v << 1 | 1, tm + 1, tr, chain); t[v] = max(t[v << 1], t[v << 1 | 1]); } } int queryminr(vii &t, int v, int tl, int tr, int start, int limit) { if (tl > tr) { return start; } if (t[v] >= limit) { return tr; } if (tl == tr) { return start; } int tm = (tl + tr) / 2; if (start > tm) { return queryminr(t, v << 1 | 1, tm + 1, tr, start, limit); } int res = queryminr(t, v << 1, tl, tm, start, limit); if (res == tm) { return queryminr(t, v << 1 | 1, tm + 1, tr, res, limit); } else { return res; } } int querymaxr(vii &t, int v, int tl, int tr, int start, int limit) { if (tl > tr) { return start; } if (t[v] <= limit) { return tr; } if (tl == tr) { return start; } int tm = (tl + tr) / 2; if (start > tm) { return querymaxr(t, v << 1 | 1, tm + 1, tr, start, limit); } int res = querymaxr(t, v << 1, tl, tm, start, limit); if (res == tm) { return querymaxr(t, v << 1 | 1, tm + 1, tr, res, limit); } else { return res; } } int queryminl(vii &t, int v, int tl, int tr, int start, int limit) { if (tl > tr) { return start; } if (t[v] >= limit) { return tl; } if (tl == tr) { return start; } int tm = (tl + tr) / 2; if (start <= tm) { return queryminl(t, v << 1, tl, tm, start, limit); } int res = queryminl(t, v << 1 | 1, tm + 1, tr, start, limit); if (res == tm + 1) { return queryminl(t, v << 1, tl, tm, res, limit); } else { return res; } } int querymaxl(vii &t, int v, int tl, int tr, int start, int limit) { if (tl > tr) { return start; } if (t[v] <= limit) { return tl; } if (tl == tr) { return start; } int tm = (tl + tr) / 2; if (start <= tm) { return querymaxl(t, v << 1, tl, tm, start, limit); } int res = querymaxl(t, v << 1 | 1, tm + 1, tr, start, limit); if (res == tm + 1) { return querymaxl(t, v << 1, tl, tm, res, limit); } else { return res; } } 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 Q = S.size(); int M = X.size(); if (N <= 3000) { vvii adj(N); rep(i, M) { adj[X[i]].emplace_back(Y[i]); adj[Y[i]].emplace_back(X[i]); } vii res(Q); rep(i, Q) { vb vis(N); deque<int> q1, q2; q1.emplace_back(S[i]); while (!q1.empty()) { int u = q1.front(); q1.pop_front(); if (vis[u]) { continue; } vis[u] = true; if (u <= R[i]) { q2.emplace_back(u); } forin(v, adj[u]) { if (!vis[v] && v >= L[i]) { q1.emplace_back(v); } } } vis.assign(N, false); while (!q2.empty() && !vis[E[i]]) { int u = q2.front(); q2.pop_front(); if (vis[u]) { continue; } vis[u] = true; forin(v, adj[u]) { if (!vis[v] && v <= R[i]) { q2.emplace_back(v); } } } res[i] = vis[E[i]]; } return res; } vii tmax(4 * N), tmin(4 * N); vii chain(N), lookup(N); vvii adj(N); rep(i, M) { adj[X[i]].emplace_back(Y[i]); adj[Y[i]].emplace_back(X[i]); } int start = -1; rep(i, N) { if (adj[i].size() == 1) { start = i; break; } } chain[0] = start; lookup[start] = 0; rep(i, N - 1) { if (i == 0 || adj[chain[i]][0] != chain[i - 1]) { chain[i + 1] = adj[chain[i]][0]; lookup[adj[chain[i]][0]] = i + 1; } else { chain[i + 1] = adj[chain[i]][1]; lookup[adj[chain[i]][1]] = i + 1; } } tassert(adj[chain.back()].size() == 1); buildmin(tmin, 1, 0, N - 1, chain); buildmax(tmax, 1, 0, N - 1, chain); vii res(Q); rep(i, Q) { int ss = lookup[S[i]], ee = lookup[E[i]]; if (ss < ee) { res[i] = queryminr(tmin, 1, 0, N - 1, ss, L[i]) >= querymaxl(tmax, 1,0, N - 1, ee, R[i]); } else { res[i] = querymaxr(tmax, 1, 0, N - 1, ee, R[i]) >= queryminl(tmin, 1,0, N - 1, ss, L[i]); } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...