Submission #274867

#TimeUsernameProblemLanguageResultExecution timeMemory
274867Haunted_CppWerewolf (IOI18_werewolf)C++17
0 / 100
4081 ms524292 KiB
#include "werewolf.h" #include <bits/stdc++.h> using namespace std; class SegmentTree { private: struct Node { int mn, mx; Node() { mn = 1e9; mx = -1e9; } void merge(Node l, Node r) { mn = min(l.mn, r.mn); mx = max(l.mx, r.mx); } }; const int LO, HI; vector<Node> seg; void build(int l, int r, int node, const vector<int> &arr) { if (l == r) { seg[node].mn = seg[node].mx = arr[l]; return; } const int mid = l + (r - l) / 2; build(l, mid, 2 * node + 1, arr); build(mid + 1, r, 2 * node + 2, arr); seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]); } Node query(int ql, int qr, int l, int r, int node) { if (l > qr || r < ql) return Node(); if (l >= ql && r <= qr) { return seg[node]; } const int mid = l + (r - l) / 2; Node esq = query(ql, qr, l, mid, 2 * node + 1); Node dir = query(ql, qr, mid + 1, r, 2 * node + 2); Node ans; ans.merge(esq, dir); return ans; } public: SegmentTree(const vector<int> &arr) : LO(0), HI((int)arr.size() - 1) { seg.clear(); seg.resize(4 * (int) arr.size()); build(LO, HI, 0, arr); } int get_max(int ql, int qr) { Node ans = query(ql, qr, LO, HI, 0); return ans.mx; } int get_min(int ql, int qr) { Node ans = query(ql, qr, LO, HI, 0); return ans.mn; } }; const int MAX_N = 2e5 + 5; vector<vector<int>> g(MAX_N); vector<int> in(MAX_N); vector<int> out(MAX_N); vector<int> euler = {0}; int Time = 0; void dfs(int node, int p) { in[node] = ++Time; euler.emplace_back(node); for (auto to : g[node]) { if (to != p) { dfs(to, node); } } out[node] = Time; } vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) { vector<int> deg(N); for (int i = 0; i < (int) X.size(); i++) { const int st = X[i]; const int et = Y[i]; ++deg[st]; ++deg[et]; g[st].emplace_back(et); g[et].emplace_back(st); } int root = -1; for (int i = 0; i < N; i++) { if (deg[i] == 1) { root = i; break; } } dfs(root, -1); SegmentTree seg(euler); int Q = S.size(); vector<int> A(Q, 0); for (int i = 0; i < Q; i++) { int cidade_inicial = S[i]; int cidade_final = E[i]; const int evitar_humano = L[i]; const int evitar_lobo = R[i]; // CIDADE INICIAL - HUMANO >= evitar_Humano int lo = in[cidade_inicial]; int hi = N; while(lo < hi) { const int mid = lo + (hi - lo) / 2 + 1; if (seg.get_min(in[cidade_inicial], mid) >= evitar_humano) lo = mid; else hi = mid - 1; } const int rightmost_inicial = lo; lo = 0; hi = in[cidade_inicial]; while(lo < hi) { const int mid = lo + (hi - lo) / 2; if (seg.get_min(mid, in[cidade_inicial]) >= evitar_humano) hi = mid; else lo = mid + 1; } const int leftmost_inicial = hi; // CIDADA_FINAL - LOBO <= Evitar_LOBO lo = in[cidade_final]; hi = N; while(lo < hi) { const int mid = lo + (hi - lo) / 2 + 1; if (seg.get_max(in[cidade_final], mid) <= evitar_lobo) lo = mid; else hi = mid - 1; } const int rightmost_final = lo; lo = 0; hi = in[cidade_final]; while(lo < hi) { const int mid = lo + (hi - lo) / 2; if (seg.get_max(mid, in[cidade_final]) <= evitar_lobo) hi = mid; else lo = mid + 1; } const int leftmost_final = hi; if (in[cidade_inicial] < in[cidade_final]) { A[i] = (leftmost_final <= rightmost_inicial); } else { A[i] = (rightmost_final >= leftmost_inicial); } } return A; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...