Submission #1200117

#TimeUsernameProblemLanguageResultExecution timeMemory
1200117InvMODWerewolf (IOI18_werewolf)C++20
0 / 100
451 ms115080 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define eb emplace_back #define vi vector<int> #define pi pair<int,int> #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) template<class T> using upq = priority_queue<T, vector<T>, greater<T>>; template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());} template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());} #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define ROF(i, a, b) for(int i = (a); i >= (b); i--) #define sumof(x) accumulate(all(x), 0ll) #define dbg(x) "[" << #x " = " << (x) << "]" #define el "\n" using ll = long long; using ld = long double; template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);} template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);} const int N = 2e5 + 5; int n, m, q, dsu[N], tin[N], tout[N], timerDFS; vector<int> Edge[N], tree[N]; set<int> sub[N]; vector<int> Q[N]; int asc(int x){ return dsu[x] == x ? x : dsu[x] = asc(dsu[x]); } bool inSub(int u, int v){ return tin[u] <= tin[v] && tout[v] <= tout[u]; } void unite(int u, int v){ u = asc(u), v = asc(v); // u is par if(u != v){ // merge st v -> u dsu[v] = u; if(sz(sub[u]) < sz(sub[v])) swap(sub[u], sub[v]); for(int x : sub[v]) sub[u].insert(x); } } void dfs1(int x, int p){ tin[x] = ++timerDFS; for(int v : tree[x])if(v != p){ dfs1(v, x); } tout[x] = ++timerDFS; } 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, m = sz(X), q = sz(E); FOR(i, 0, m - 1) Edge[X[i]].eb(Y[i]), Edge[Y[i]].eb(X[i]); FOR(i, 0, n - 1) dsu[i] = i; FOR(x, 0, n - 1){ for(int v : Edge[x]){ if(v >= x) continue; auto join = [&](int u, int v) -> void{ // u > v u = asc(u), v = asc(v); if(u != v){ dsu[v] = u; tree[u].eb(v); } }; join(x, v); } } dfs1(n - 1, -1); FOR(i, 0, n - 1){ dsu[i] = i; sub[i].insert(tin[i]); } vector<int> ans(q); FOR(i, 0, q - 1) Q[L[i]].eb(i); ROF(x, n - 1, 0){ for(int v : Edge[x]){ if(v <= x) continue; unite(x, v); } for(int id : Q[x]){ //cout << id <<" " << R[id] <<" " << E[id] << el; if(!inSub(R[id], E[id])){ ans[id] = 0; } else{ //cout << id << el; if(sub[x].find(tin[S[id]]) != sub[x].end()){ auto it = sub[x].upper_bound(tin[R[id]]); if(it != sub[x].end() && *it < tout[R[id]]){ ans[id] = 1; } else ans[id] = 0; } else{ ans[id] = 0; } } } } return ans; } //#define name "InvMOD" #ifdef name signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int n,m,q; cin >> n >> m >> q; vector<vector<int>> E(2, vector<int>(m)); FOR(i, 0, 1){ FOR(j, 0, m - 1){ cin >> E[i][j]; } } vector<vector<int>> Q(4, vector<int>(q)); FOR(i, 0, 3){ FOR(j, 0, q - 1){ cin >> Q[i][j]; } } vector<int> answer = check_validity(n, E[0], E[1], Q[0], Q[1], Q[2], Q[3]); for(int v : answer) cout << v <<" "; cout <<"\n"; return 0; } #endif // name
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...