Submission #1083667

#TimeUsernameProblemLanguageResultExecution timeMemory
1083667TymondWerewolf (IOI18_werewolf)C++17
0 / 100
475 ms101720 KiB
#include <bits/stdc++.h> #include "werewolf.h" using namespace std; using ll = long long; using ld = long double; #define fi first #define se second #define vi vector<int> #define vll vector<long long> #define pii pair<int, int> #define pll pair<long long, long long> #define pb push_back #define mp make_pair #define eb emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);} inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);} #ifdef DEBUG auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";} #define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X) #else #define debug(...){} #endif struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; struct Query{ int s, e, l, p, id; Query(int ns = 0, int ne= 0, int nl= 0, int np= 0, int nid= 0){ s = ns; e = ne; l = nl; p = np; id = nid; } }; bool comp(Query& a, Query& b){ if(a.p != b.p){ return a.p < b.p; } return a.l < b.l; } const int MAXN = 2e5 + 7; vi g[MAXN]; Query tab[MAXN]; vector<pii> repL[MAXN]; int szL[MAXN]; vector<pii> repP[MAXN]; int szP[MAXN]; vi ans; int n,m, q; int FindL(int a){ if(repL[a].back().fi == a){ return a; } return FindL(repL[a].back().fi); } int FindP(int a){ if(repP[a].back().fi == a){ return a; } return FindP(repP[a].back().fi); } vector<pii> vecL[MAXN]; vector<pii> vecP[MAXN]; void genL(int ind){ vecL[ind] = repL[ind]; int akt = vecL[ind].back().fi; while(akt != repL[akt].back().fi){ vecL[ind].pb(repL[akt].back()); akt = repL[akt].back().fi; } } void genP(int ind){ vecP[ind] = repP[ind]; int akt = vecP[ind].back().fi; while(akt != repP[akt].back().fi){ vecP[ind].pb(repP[akt].back()); akt = repP[akt].back().fi; } } vi check_validity(int N, vi X, vi Y,vi S, vi E, vi L, vi R) { n = N; q = sz(S); m = sz(X); ans.assign(q, 0); for(int i = 0; i < m; i++){ g[X[i]].pb(Y[i]); g[Y[i]].pb(X[i]); } for(int i = 0; i < q; i++){ tab[i] = Query(S[i], E[i], L[i], R[i], i); } for(int i = 0; i < n; i++){ repL[i].pb({i, i}); szL[i] = 1; } for(int i = n - 1; i >= 0; i--){ for(auto u : g[i]){ if(u > i){ int rep1 = FindL(i); int rep2 = FindL(u); if(szL[rep1] > szL[rep2]){ szL[rep1] += szL[rep2]; repL[rep2].pb({rep1, i}); }else{ szL[rep2] += szL[rep1]; repL[rep1].pb({rep2, i}); } } } } for(int i = 0; i < n; i++){ repP[i].pb({i, i}); szP[i] = 1; } for(int i = 0; i < n; i++){ for(auto u : g[i]){ if(u < i){ int rep1 = FindP(i); int rep2 = FindP(u); if(szP[rep1] > szP[rep2]){ szP[rep1] += szP[rep2]; repP[rep2].pb({rep1, i}); }else{ szP[rep2] += szP[rep1]; repP[rep1].pb({rep2, i}); } } } } for(int i = 0; i < n; i++){ genL(i); genP(i); } for(int i = 0; i < q; i++){ //dla s sprawdz vecP, dla e sprawdz vecL unordered_map<int, int, custom_hash> cnt; int mx = 0; for(auto ele : vecP[tab[i].s]){ if(ele.se >= tab[i].l && ele.se <= tab[i].p){ cnt[ele.fi] |= 2; mx = max(mx, cnt[ele.fi]); } } for(auto ele : vecL[tab[i].e]){ if(ele.se >= tab[i].l && ele.se <= tab[i].p){ cnt[ele.fi] |= 1; mx = max(mx, cnt[ele.fi]); } } if(mx == 3){ ans[i] = 1; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...