제출 #139172

#제출 시각아이디문제언어결과실행 시간메모리
139172rajarshi_basu늑대인간 (IOI18_werewolf)C++14
0 / 100
640 ms367112 KiB
#include <bits/stdc++.h> #include "werewolf.h" #define FOR(i,n) for(int i=0;i<n;i++) #define FORE(i,a,b) for(int i = a;i<=b;i++) #define ll long long int #define pb push_back #define vi vector<int> #define ff first #define ss second #define vv vector #define ii pair<int,int> using namespace std; const int MAXN = 2*100*1000 +1; const int INF = 2*MAXN; vi g[MAXN]; struct SegmentTree{ int st1[4*MAXN]; void build(int node,int ss,int se,int* arr){ if(ss == se){ st1[node] = arr[ss]; return; } int mid = (ss+se)/2; build(node*2+1,ss,mid,arr); build(node*2+2,mid+1,se,arr); st1[node] = min(st1[node*2+1],st1[node*2+2]); // st2[node] = min(st2[node*2+1],st2[node*2+2]); } int getLastValue(int node,int ss,int se,int bound,int val){ if(ss > bound)return -1; if(st1[node] >= val)return -1; int mid = (ss+se)/2; if(ss == se)return ss; int vv = getLastValue(node*2+2,mid+1,se,bound,val); if(vv == -1)return getLastValue(node*2+1,ss,mid,bound,val); return vv; } }; SegmentTree human_normal,human_reverse,wolf_normal,wolf_reverse; int place[MAXN]; int rplace[MAXN]; int T = 0; void dfs(int node,int p = -1){ place[node] = T; rplace[T] = node; T++; for(auto e : g[node]){ if(e != p)dfs(e,node); } } bool solve(int n,int l,int r,int s,int e){ s = place[s]; e = place[e]; ii p1; ii p2; p1.ff = human_normal.getLastValue(0,0,n-1,s,l) + 1; p1.ss = n - human_reverse.getLastValue(0,0,n-1,n-s-1,l) - 1 -1; p2.ff = wolf_normal.getLastValue(0,0,n-1,e,-r) + 1; p2.ss = n - wolf_reverse.getLastValue(0,0,n-1,e,-r) - 1 -1; if(p1.ff == p2.ff)return true; if(p1.ff > p2.ff)swap(p1,p2); return p1.ss >= p2.ff; } vi check_validity(int n,vi x,vi y,vi s,vi e,vi l,vi r){ FOR(i,(int)x.size()){ g[x[i]].pb(y[i]); g[y[i]].pb(x[i]); } int q = s.size(); vi ret;FOR(i,q)ret.pb(0); // preprocess stuff dfs(0); int arr[n]; FOR(i,n)arr[i] = rplace[i]; human_normal.build(0,0,n-1,arr); FOR(i,n)arr[i] = rplace[n-i-1]; human_reverse.build(0,0,n-1,arr); FOR(i,n)arr[i] = -rplace[i]; wolf_normal.build(0,0,n-1,arr); FOR(i,n)arr[i] = -rplace[n-i-1]; wolf_reverse.build(0,0,n-1,arr); ////////////////////////////////// FOR(i,q){ ret[i] = solve(n,l[i],r[i],s[i],e[i]); } return ret; } int ma1in(){ ios_base::sync_with_stdio(0); cin.tie(0); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...