Submission #295719

#TimeUsernameProblemLanguageResultExecution timeMemory
295719zoooma13Werewolf (IOI18_werewolf)C++14
49 / 100
624 ms52308 KiB
#include <bits/stdc++.h> #include "werewolf.h" using namespace std; #define MAX_N 200005 #define FL p<<1 #define FR p<<1|1 vector <vector <int>> adj; vector <int> a ,pos; int gt(int u ,int p=-1){ a.push_back(u); if(adj[u].size() == 1 && ~p) return u; if(adj[u][0] != p) return gt(adj[u][0] ,u); return gt(adj[u][1] ,u); } int n ,tree[2][4*MAX_N]; void bld(int l=0 ,int r=n-1 ,int p=1){ if(l == r){ tree[0][p] = tree[1][p] = a[l]; return; } int mid = (l+r)>>1; bld(l ,mid ,FL); bld(mid+1 ,r ,FR); tree[0][p] = min(tree[0][FL] ,tree[0][FR]); tree[1][p] = max(tree[1][FL] ,tree[1][FR]); } int getlastzero(int ql ,int qr ,int qq ,int l=0 ,int r=n-1 ,int p=1){ if(r < ql || qr < l) return -1; if(l == r) return tree[1][p] > qq? l : -1; int mid = (l+r)>>1; if(ql <= l && r <= qr){ if(tree[1][FR] > qq) return getlastzero(ql ,qr ,qq ,mid+1 ,r ,FR); if(tree[1][FL] > qq) return getlastzero(ql ,qr ,qq ,l ,mid ,FL); return -1; } int rt = getlastzero(ql ,qr ,qq ,mid+1 ,r ,FR); if(~rt) return rt; return getlastzero(ql ,qr ,qq ,l ,mid ,FL); } int getfirsttwo(int ql ,int qr ,int qq ,int l=0 ,int r=n-1 ,int p=1){ if(r < ql || qr < l) return -1; if(l == r) return tree[0][p] < qq? l : -1; int mid = (l+r)>>1; if(ql <= l && r <= qr){ if(tree[0][FL] < qq) return getfirsttwo(ql ,qr ,qq ,l ,mid ,FL); if(tree[0][FR] < qq) return getfirsttwo(ql ,qr ,qq ,mid+1 ,r ,FR); return -1; } int lf = getfirsttwo(ql ,qr ,qq ,l ,mid ,FL); if(~lf) return lf; return getfirsttwo(ql ,qr ,qq ,mid+1 ,r ,FR); } int ex ,pl ,pr; bool vis[2][3000]; bool go(int u ,bool st=0){ vis[st][u] = 1; if(pl <= u && u <= pr && ~st && !vis[1][u] && go(u ,1)) return 1; if(st && u > pr) return 0; if(!st && u < pl) return 0; if(u == ex) return st; vis[st][u] = 1; for(int&v : adj[u]) if(!vis[st][v] && go(v ,st)) return 1; return 0; } vector<int> check_validity(int N, vector<int> X, vector<int> Y,vector<int> S, vector<int> E,vector<int> L, vector<int> R) { n = N; adj.resize(N); for(int i=0; i<X.size(); i++){ adj[X[i]].push_back(Y[i]); adj[Y[i]].push_back(X[i]); } if(N <= 3000){ vector <int> ret(R.size()); for(int q = 0; q < R.size(); q++){ ex = E[q] ,pl = L[q] ,pr = R[q]; memset(vis ,0 ,sizeof vis); ret[q] = go(S[q]); } return ret; } int lf = gt(0); a.clear(); gt(lf); pos.resize(N); for(int i=0; i<N; i++) pos[a[i]] = i; bld(); vector <int> ret(R.size()); for(int q = 0; q < R.size(); q++){ int l = pos[S[q]] ,r = pos[E[q]]; if(r < l) continue; if(R[q] < a[r] || a[l] < L[q]) { ret[q] = 0; continue; } int last0 = getlastzero(l ,r ,R[q]); int first2 = getfirsttwo(l ,r ,L[q]); ret[q] = (~last0 && ~first2? last0+1 < first2 : 1); } reverse(a.begin() ,a.end()); for(int i=0; i<N; i++) pos[a[i]] = i; memset(tree ,0 ,sizeof tree); bld(); for(int q = 0; q < R.size(); q++){ int l = pos[S[q]] ,r = pos[E[q]]; if(r < l) continue; if(R[q] < a[r] || a[l] < L[q]) { ret[q] = 0; continue; } int last0 = getlastzero(l ,r ,R[q]); int first2 = getfirsttwo(l ,r ,L[q]); ret[q] = (~last0 && ~first2? last0+1 < first2 : 1); } return ret; }

Compilation message (stderr)

werewolf.cpp: In function 'bool go(int, bool)':
werewolf.cpp:67:31: warning: '~' on an expression of type bool [-Wbool-operation]
   67 |     if(pl <= u && u <= pr && ~st && !vis[1][u] && go(u ,1))
      |                               ^~
werewolf.cpp:67:31: note: did you mean to use logical not ('!')?
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:80:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int i=0; i<X.size(); i++){
      |                  ~^~~~~~~~~
werewolf.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(int q = 0; q < R.size(); q++){
      |                        ~~^~~~~~~~~~
werewolf.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int q = 0; q < R.size(); q++){
      |                    ~~^~~~~~~~~~
werewolf.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     for(int q = 0; q < R.size(); q++){
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...