Submission #542892

#TimeUsernameProblemLanguageResultExecution timeMemory
542892zggfWerewolf (IOI18_werewolf)C++14
0 / 100
4057 ms524288 KiB
#include "werewolf.h" #define f first #define s second #include <bits/stdc++.h> using namespace std; vector<int> graf[200100]; vector<int> cent[200100], nr[200100], wart[200100]; vector<int> p1, sz1, par[20], szi[20]; vector<unordered_map<int, int>> rep[20]; int find(int x, vector<int> &parent){ if(parent[x]==-1) return x; parent[x] = find(parent[x], parent); return parent[x]; } void join(int a, int b, vector<int> &parent, vector<int> &ranga, int pt=-1){ a = find(a, parent); b = find(b, parent); if(a==b) return; if(ranga[a]>ranga[b]){ parent[b] =a; if(pt!=-1){ wart[a][pt] = max(wart[a][pt], wart[b][pt]); for(auto it:rep[pt][b]){ rep[pt][a][it.f] = it.s; } rep[pt][b].clear(); } }else if(ranga[b]>ranga[a]){ parent[a] = b; if(pt!=-1){ wart[b][pt] = max(wart[a][pt], wart[b][pt]); for(auto it:rep[pt][a]){ rep[pt][b][it.f] = it.s; } rep[pt][a].clear(); } }else{ parent[b] = a; if(pt!=-1){ wart[a][pt] = max(wart[a][pt], wart[b][pt]); for(auto it:rep[pt][b]){ rep[pt][a][it.f] = it.s; } rep[pt][b].clear(); } ranga[a]++; } } vector<int> G[200100]; vector<int> bylo; vector<int> sz; void dfs(int x, int pr=-1){ sz[x] = 1; for(int it:G[x]){ if(it!=pr){ dfs(it, x); sz[x]+=sz[it]; } } } int centroid(int x){ for(int it:G[x]){ if(bylo[it])continue; if(sz[x]-sz[it]<sz[it]){ swap(sz[x], sz[it]); sz[x] = sz[it]-sz[x]; return centroid(it); } } return x; } int globNr, globCent; void dfs2(int x, int pr, int mini){ mini = min(mini, x); nr[x].push_back(globNr); cent[x].push_back(globCent); wart[x].push_back(mini); int pt = wart[x].size()-1; rep[pt][x][globNr] = x+1; for(auto it:G[x]){ if(it!=pr){ dfs2(it, x, mini); } } } void solve(int x){ x = centroid(x); bylo[x] = true; globCent = x; globNr = 0; for(auto it:G[x]){ if(!bylo[it]){ dfs2(it, x, x); globNr++; } } for(auto it:G[x]){ if(!bylo[it]) solve(it); } } void makeTree(int N){ p1.resize(N, -1); sz.resize(N); sz1.resize(N); bylo.resize(N); for(int i = 0; i < 20; i++){ szi[i].resize(N); par[i].resize(N, -1); rep[i].resize(N); } for(int i = N-1; i>=0; i--){ for(auto it:graf[i]){ if(find(it, p1)!=find(i, p1)){ join(it, i, p1, sz1); G[it].push_back(i); G[i].push_back(it); } } } dfs(0); solve(0); } void add(int x){ for(auto it:graf[x]){ int pt = 0; while(pt<cent[it].size()&&pt<cent[x].size()&&cent[it]==cent[x]){ join(it, x, par[pt], szi[pt], pt); pt++; } } } bool qur(int a, int b, int k){ int pt = 0; while(pt<cent[a].size()){ int w1 = wart[a][pt]; int vb = find(b, par[pt]); int w2 = wart[vb][pt]; if(min(w1, w2)>=k) return true; b = rep[pt][vb][nr[a][pt]]; b--; if(b<0) return false; } return false; } vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y, std::vector<int> S, std::vector<int> E, std::vector<int> L, std::vector<int> R) { int Q = S.size(); int M = X.size(); for(int i = 0; i < M; i++){ graf[X[i]].push_back(Y[i]); graf[Y[i]].push_back(X[i]); } makeTree(N); vector<pair<pair<pair<int, int>, pair<int, int>>, int>> inp; for(int i = 0; i < Q; i++){ inp.push_back({{{R[i], L[i]}, {S[i], E[i]}}, i}); } sort(inp.begin(), inp.end()); int poprz = 0; vector<int> A(Q); for(int i = 0; i < inp.size(); i++){ int l = inp[i].f.f.s; int r = inp[i].f.f.f; int a = inp[i].f.s.f; int b = inp[i].f.s.s; while(poprz<=r){ add(poprz); poprz++; } A[inp[i].s] = qur(a, b, l); } return A; }

Compilation message (stderr)

werewolf.cpp: In function 'void add(int)':
werewolf.cpp:139:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |         while(pt<cent[it].size()&&pt<cent[x].size()&&cent[it]==cent[x]){
      |               ~~^~~~~~~~~~~~~~~~
werewolf.cpp:139:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |         while(pt<cent[it].size()&&pt<cent[x].size()&&cent[it]==cent[x]){
      |                                   ~~^~~~~~~~~~~~~~~
werewolf.cpp: In function 'bool qur(int, int, int)':
werewolf.cpp:148:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  148 |     while(pt<cent[a].size()){
      |           ~~^~~~~~~~~~~~~~~
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:177:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<std::pair<int, int>, std::pair<int, int> >, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |     for(int i = 0; i < inp.size(); i++){
      |                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...