Submission #725418

#TimeUsernameProblemLanguageResultExecution timeMemory
725418SanguineChameleonGame (APIO22_game)C++17
60 / 100
4064 ms45496 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma") #include "game.h" #include <bits/stdc++.h> using namespace std; const int shift = 9; const int maxN = 3e5 + 20; int L[maxN]; int R[maxN]; vector<int> adj1[maxN]; vector<int> adj2[maxN]; bool done = false; int n, k; void init(int _n, int _k) { n = _n; k = _k; for (int i = 0; i < k; i++) { L[i] = i; R[i] = i + 1; } for (int i = k; i < n; i++) { L[i] = 0; R[i] = k + 1; } } void update_L(int u, int val); void update_R(int u, int val); void update_L(int u, int val) { if (done) { return; } bool diff = (L[u] >> shift) != (val >> shift); bool same = (L[u] >> shift) == (R[u] >> shift); L[u] = val; if (L[u] >= R[u]) { done = true; return; } if (diff) { for (auto v: adj1[u]) { if (L[u] > L[v]) { update_L(v, L[u]); } } } else if (same) { for (auto v: adj1[u]) { if (L[u] > L[v]) { update_L(v, L[u]); } } for (auto v: adj2[u]) { if (R[u] < R[v]) { update_R(v, R[u]); } } } } void update_R(int u, int val) { if (done) { return; } bool diff = (R[u] >> shift) != (val >> shift); bool same = (L[u] >> shift) == (R[u] >> shift); R[u] = val; if (L[u] >= R[u]) { done = true; return; } if (diff) { for (auto v: adj2[u]) { if (R[u] < R[v]) { update_R(v, R[u]); } } } else if (same) { for (auto v: adj1[u]) { if (L[u] > L[v]) { update_L(v, L[u]); } } for (auto v: adj2[u]) { if (R[u] < R[v]) { update_R(v, R[u]); } } } } int add_teleporter(int u, int v) { int val = max(L[u], (u < k ? u + 1 : 0)); if (val > L[v]) { update_L(v, val); } if (R[v] < R[u]) { update_R(u, R[v]); } adj1[u].push_back(v); adj2[v].push_back(u); return done; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...