Submission #725425

#TimeUsernameProblemLanguageResultExecution timeMemory
725425SanguineChameleonGame (APIO22_game)C++17
100 / 100
1407 ms58216 KiB
#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]; pair<int, int> range[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; } for (int i = 0; i < n; i++) { range[i] = {0, k + 1}; } } void update(int u); void push(int u) { for (auto v: adj1[u]) { if (L[u] > L[v]) { L[v] = L[u]; update(v); } } for (auto v: adj2[u]) { if (R[u] < R[v]) { R[v] = R[u]; update(v); } } } void update(int u) { if (done) { return; } if (L[u] >= R[u]) { done = true; return; } int lt = range[u].first; int rt = range[u].second; int mt = (lt + rt) / 2; if (L[u] <= mt && R[u] <= mt) { range[u] = {lt, mt}; push(u); } else if (L[u] > mt && R[u] > mt) { range[u] = {mt + 1, rt}; push(u); } } int add_teleporter(int u, int v) { int val = max(L[u], (u < k ? u + 1 : 0)); if (val > L[v]) { L[v] = val; update(v); } if (R[v] < R[u]) { R[u] = R[v]; update(u); } 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...