제출 #1072565

#제출 시각아이디문제언어결과실행 시간메모리
1072565ewirlan늑대인간 (IOI18_werewolf)C++17
100 / 100
521 ms135500 KiB
// #ifndef __SIZEOF_INT128__ #define __SIZEOF_INT128__ #endif #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace chrono; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define rep(i, p, k) for(int i(p); i < (k); ++i) #define per(i, p, k) for(int i(p); i > (k); --i) #define sz(x) (int)(x).size() #define sc static_cast typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef __int128_t lll; //#define int ll template <typename T = int> using par = std::pair <T, T>; #define fi first #define se second #define test int _number_of_tests(in()); while(_number_of_tests--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb emplace_back struct Timer { string name{""}; time_point<high_resolution_clock> end, start{high_resolution_clock::now()}; duration<float, std::milli> dur; Timer() = default; Timer(string nm): name(nm) {} ~Timer() { end = high_resolution_clock::now(); dur= end - start; cout << "@" << name << "> " << dur.count() << " ms" << '\n'; } }; template <typename T = int> inline T in() { static T x; std::cin >> x; return x; } std::string yn(bool b) { if(b) return "YES\n"; else return "NO\n"; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par); template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek) { for(const auto& i : wek)out << i << ' '; return out; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par) { out << '{'<<par.first<<", "<<par.second<<"}"; return out; } #define show(x) cerr << #x << " = " << x << '\n'; constexpr int maxn = 2e5 + 3; vector <int> graf[maxn]; int rep[maxn][2]; int find(int w, bool b){ if(!~rep[w][b])return w; return rep[w][b] = find(rep[w][b], b); } vector <int> syn[maxn][2]; int ojc[maxn][20][2]; vector <int> pv[2]; int pro[maxn][2], poo[maxn][2]; void dfs(int w, bool b){ pro[w][b] = sz(pv[b]); pv[b].pb(w); for(auto i: syn[w][b])dfs(i, b); poo[w][b] = sz(pv[b])-1; } constexpr int pol = 1<<18; vector <int> pyt[pol*2]; vector <int> check_validity (int n, vector <int> x, vector <int> y, vector <int> a, vector <int> b, vector <int> l, vector <int> r) { int m(sz(x)), q(sz(a)); pv[0].clear(); pv[1].clear(); rep(i, 0, n){ syn[i][0].clear(); syn[i][1].clear(); graf[i].clear(); rep[i][0] = rep[i][1] = -1; } rep(i, 0, m){ graf[x[i]].pb(y[i]); graf[y[i]].pb(x[i]); } rep(i, 0, n)ojc[i][0][0] = ojc[i][0][1] = i; rep(i, 0, n){ set <int> s; for(auto j: graf[i])if(j < i)s.insert(find(j, 0)); for(auto j: s){ syn[i][0].pb(j); rep[j][0] = i; ojc[j][0][0] = i; } } per(i, n-1, -1){ set <int> s; for(auto j: graf[i])if(j > i)s.insert(find(j, 1)); for(auto j: s){ syn[i][1].pb(j); rep[j][1] = i; ojc[j][0][1] = i; } } rep(b, 0, 2)rep(k, 1, 20)rep(i, 0, n)ojc[i][k][b] = ojc[ojc[i][k-1][b]][k-1][b]; dfs(0, 1); dfs(n-1, 0); // cout <<pv[0] << '\n' << pv[1] << '\n'; vector <int> odp(q); vector <pair <int, int>> py0(q); vector <vector <int>> zac(n), kon(n); vector <bool> act(q); rep(i, 0, q){ int k(19); while(a[i] != ojc[a[i]][0][1] && ojc[a[i]][0][1] >= l[i]){ while(k && ojc[a[i]][k][1] < l[i])--k; a[i] = ojc[a[i]][k][1]; } k = 19; while(b[i] != ojc[b[i]][0][0] && ojc[b[i]][0][0] <= r[i]){ while(k && ojc[b[i]][k][0] > r[i])--k; b[i] = ojc[b[i]][k][0]; } int p1(pro[a[i]][1]), k1(poo[a[i]][1]), p0(pro[b[i]][0]), k0(poo[b[i]][0]); py0[i] = {p0, k0}; zac[p1].pb(i); kon[k1].pb(i); } rep(i, 0, n){ for(auto j: zac[i]){ act[j] = 1; int a(py0[j].first + pol-1), b(py0[j].second + pol+1); while(a+1 != b){ if(a % 2 == 0)pyt[a+1].pb(j); if(b % 2 == 1)pyt[b-1].pb(j); a /= 2; b /= 2; } } int g(pro[pv[1][i]][0] + pol); while(g > 0){ for(auto j: pyt[g])if(act[j])odp[j] = 1; pyt[g].clear(); g /= 2; } for(auto j: kon[i])act[j] = 0; } return odp; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...