Submission #139809

#TimeUsernameProblemLanguageResultExecution timeMemory
139809KewoWerewolf (IOI18_werewolf)C++17
34 / 100
2839 ms147576 KiB
#include "werewolf.h" #include <bits/stdc++.h> #define pb push_back #define ppb pop_back #define fi first #define se second #define mid ((x + y) / 2) #define left (ind * 2) #define right (ind * 2 + 1) #define mp make_pair #define timer ((double)clock() / CLOCKS_PER_SEC) #define endl "\n" #define spc " " #define d1(x) cerr<<#x<<":"<<x<<endl #define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl #define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl #define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; typedef long long int lli; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<double, double> dd; const int N = (int)(1e6 + 5); const int LOG = (int)(20); int ar[N], n, mark[N], treemax[N << 2], treemin[N << 2], pos[N]; vector<int> v[N]; void build(int ind, int x, int y) { if(x == y) { treemax[ind] = treemin[ind] = ar[x]; return; } build(left, x, mid); build(right, mid + 1, y); treemax[ind] = max(treemax[left], treemax[right]); treemin[ind] = min(treemin[left], treemin[right]); } int getmin(int ind, int x, int y, int a, int b) { if(y < a || b < x) return n; if(a <= x && y <= b) return treemin[ind]; return min(getmin(left, x, mid, a, b), getmin(right, mid + 1, y, a, b)); } int getmax(int ind, int x, int y, int a, int b) { if(y < a || b < x) return -1; if(a <= x && y <= b) return treemax[ind]; return max(getmax(left, x, mid, a, b), getmax(right, mid + 1, y, a, b)); } int bs1(int ind, int x, int y, int val) { if(x == y) return x; if(x + 1 == y) { if(getmin(1, 1, n, ind, y) >= val) return y; else return x; } if(getmin(1, 1, n, ind, mid) >= val) return bs1(ind, mid, y, val); else return bs1(ind, x, mid - 1, val); } int bs2(int ind, int x, int y, int val) { if(x == y) return x; if(x + 1 == y) { if(getmax(1, 1, n, x, ind) <= val) return x; else return y; } if(getmax(1, 1, n, mid, ind) <= val) return bs2(ind, x, mid, val); else return bs2(ind, mid + 1, y, val); } int bs3(int ind, int x, int y, int val) { if(x == y) return x; if(x + 1 == y) { if(getmin(1, 1, n, x, ind) >= val) return x; else return y; } if(getmin(1, 1, n, mid, ind) >= val) return bs3(ind, x, mid, val); else return bs3(ind, mid + 1, y, val); } int bs4(int ind, int x, int y, int val) { if(x == y) return x; if(x + 1 == y) { if(getmax(1, 1, n, ind, y) <= val) return y; else return x; } if(getmax(1, 1, n, ind, mid) <= val) return bs4(ind, mid, y, val); else return bs4(ind, x, mid - 1, val); } int solve(int x, int y, int l, int r) { if(ar[x] < l) return 0; if(ar[y] > r) return 0; if(x < y) { int idx1 = bs1(x, x, n, l); int idx2 = bs2(y, 1, y, r); return idx1 >= idx2; } else { int idx1 = bs3(x, 1, x, l); int idx2 = bs4(y, y, n, r); return idx1 <= idx2; } } void dfs(int x, int back) { ar[++n] = x; for(auto i : v[x]) if(i != back) dfs(i, x); } 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(); vector<int> ans(S.size()); for(int i = 0; i < X.size(); i++) { v[X[i]].pb(Y[i]); v[Y[i]].pb(X[i]); } int nd; for(int i = 0; i < N; i++) if(v[i].size() == 1) { nd = i; break; } dfs(nd, 0); for(int i = 1; i <= n; i++) pos[ar[i]] = i; build(1, 1, n); for(int i = 0; i < S.size(); i++) ans[i] = solve(pos[S[i]], pos[E[i]], L[i], R[i]); 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:144:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < X.size(); i++) {
                 ~~^~~~~~~~~~
werewolf.cpp:158:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < S.size(); i++)
                 ~~^~~~~~~~~~
werewolf.cpp:142:6: warning: unused variable 'q' [-Wunused-variable]
  int q = S.size();
      ^
werewolf.cpp:154:5: warning: 'nd' may be used uninitialized in this function [-Wmaybe-uninitialized]
  dfs(nd, 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...