제출 #134348

#제출 시각아이디문제언어결과실행 시간메모리
134348MoNsTeR_CuBe늑대인간 (IOI18_werewolf)C++17
0 / 100
4073 ms524288 KiB
#include "werewolf.h" #include <bits/stdc++.h> using namespace std; int min(int &a, int &b){ if(a < b) return a; return b; } int max(int &a, int &b){ if(a < b) return b; return a; } vector< int > v; struct node{ node* l, *r; int mini, maxi; void update(){ mini = INT_MAX; maxi = INT_MIN; if(l){ mini = min(mini, l->mini); maxi = max(maxi, l->maxi); } if(r){ mini = min(mini, r->mini); maxi = max(maxi, r->maxi); } } }; void Build(node* root, int left, int right){ if(left == right){ root->mini = root->maxi = v[left]; return; } root->l = new node{NULL,NULL,0,0}; root->r = new node{NULL,NULL,0,0}; int mid = (left+right)/2; Build(root->l, left, mid); Build(root->r, mid+1, right); root->update(); } pair<int, int> query(node* root, int left, int right, int qL, int qR){ if(left > qR || right < qL) return {INT_MAX, INT_MIN}; if(left >= qL && right <= qR) return {root->mini, root->maxi}; int mid = (left+right)/2; pair<int, int> L = query(root->l, left, mid, qL, qR); pair<int, int> R = query(root->r, mid+1, right, qL, qR); return {min(L.first, R.first), max(L.second, R.second)}; } /////////////////////////////////////////////////////////////////////// void dfs(vector< vector< int > >& Graph, int last, int nodee){ v.push_back(nodee); for(int a : Graph[nodee]){ if(a == last) continue; dfs(Graph, nodee, a); } } vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) { int Q = S.size(); int M = X.size(); vector< vector< int > > Graph(N); for(int i = 0; i < M; i++){ Graph[X[i]].push_back(Y[i]); Graph[Y[i]].push_back(X[i]); } vector<int> A(Q); int beg = -1; for(int i = 0; i < N; i++){ if(Graph[i].size() == 1){ beg = i; break; } } v.resize(1); dfs(Graph, -1, beg); node* root = new node{NULL,NULL,0,0}; Build(root, 1, N); vector< int > pos(N); for(int i = 1; i <= N; i++){ pos[v[i]] = i; } /*for(int a : v) cout << a << ' '; cout << endl;*/ for(int i = 0; i < Q; i++){ if(S[i] < L[i] || E[i] > R[i]){ A[i] = 0; continue; } if(pos[S[i]] < pos[E[i]]){ //int indexL = human_right(root, 1, N, pos[S[i]], pos[E[i]], L[i]); int left = pos[S[i]]; int right = pos[E[i]]; while(left < right){ int mid = (left+right+1)/2; pair<int, int> Qe = query(root, 1,N, pos[S[i]], mid); if(Qe.first < L[i]){ right = mid-1; }else{ left = mid; } } int indexL = left; left = pos[S[i]]; right = pos[E[i]]; while(left < right){ int mid = (left+right+1)/2; pair<int, int> Qe = query(root, 1,N, mid, pos[E[i]]); if(Qe.second > R[i]){ right = mid+1; }else{ left = mid; } } int indexR = left; if(indexL >= indexR) A[i] = 1; else A[i] = 0; }else{ int left = pos[S[i]]; int right = pos[E[i]]; while(left < right){ int mid = (left+right+1)/2; pair<int, int> Qe = query(root, 1,N, pos[S[i]], mid); if(Qe.second > R[i]){ right = mid-1; }else{ left = mid; } } int indexL = left; left = pos[S[i]]; right = pos[E[i]]; while(left < right){ int mid = (left+right+1)/2; pair<int, int> Qe = query(root, 1,N, mid, pos[E[i]]); if(Qe.first < L[i]){ right = mid+1; }else{ left = mid; } } int indexR = left; if(indexL >= indexR) A[i] = 1; else A[i] = 0; } } 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...