Submission #1128585

#TimeUsernameProblemLanguageResultExecution timeMemory
1128585guagua0407Werewolf (IOI18_werewolf)C++20
0 / 100
2047 ms115884 KiB
//#include "grader.cpp" #include "werewolf.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); namespace{ const int mxn=2e5+5; vector<int> adj[mxn]; set<pair<int,int>> S[mxn]; } struct DSU{ vector<int> e; vector<vector<int>> B; DSU(int n){ e=vector<int>(n,-1); B.resize(n); for(int i=0;i<n;i++){ B[i].push_back(i); S[i].insert({i,-1}); } } int find(int x){ return (e[x]<0?x:e[x]=find(e[x])); } bool unite(int a,int b,int t){ a=find(a); b=find(b); if(a==b) return false; if(e[a]>e[b]) swap(a,b); e[a]+=e[b]; e[b]=a; for(auto v:B[b]){ S[v].insert({a,t}); B[a].push_back(v); } vector<int>().swap(B[b]); return true; } }; struct DSU2{ vector<int> e; DSU2(int n){ e=vector<int>(n,-1); } int find(int x){ return (e[x]<0?x:e[x]=find(e[x])); } bool unite(int a,int b,int t){ a=find(a); b=find(b); if(a==b) return false; if(e[a]>e[b]) swap(a,b); e[a]+=e[b]; e[b]=a; for(auto v:S[b]){ S[a].insert(v); } set<pair<int,int>>().swap(S[b]); return true; } bool query(int a,int b,int t){ a=find(a); b=find(b); auto R=S[a].upper_bound({b,t}); auto L=S[a].lower_bound({b,-1}); return (R!=L); } }; std::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 m=(int)X.size(); for(int i=0;i<m;i++){ adj[X[i]].push_back(Y[i]); adj[Y[i]].push_back(X[i]); } DSU dsu(n); for(int i=0;i<n;i++){ for(auto v:adj[i]){ if(v<i){ dsu.unite(i,v,i); } } } int q=(int)L.size(); vector<vector<int>> qs(n); vector<int> ans(q); for(int i=0;i<q;i++){ qs[L[i]].push_back(i); } DSU2 dsu2(n); for(int i=n-1;i>=0;i--){ //cout<<"diaob "<<i<<'\n'; for(auto v:adj[i]){ if(v>i){ dsu2.unite(i,v,i); } } for(auto v:qs[i]){ ans[v]=dsu2.query(S[v],E[v],R[v]); } } return ans; } /* 6 6 3 5 1 1 2 1 3 3 4 3 0 5 2 4 2 1 2 4 2 2 2 5 4 3 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...