Submission #854005

#TimeUsernameProblemLanguageResultExecution timeMemory
854005mychecksedadInside information (BOI21_servers)C++17
50 / 100
234 ms128192 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 1e6+100, M = 1e5+10, K = 22; struct Edge{ int to, tm; }; struct Query{ int a, b, tm, ans; }; int n, k, timer = 0, dep[N], up[N][K], tin[N], tout[N]; array<int, 3> I[N][K], D[N][K]; vector<Edge> g[N]; void dfs(int v, int p){ tin[v] = timer++; dep[v] = dep[p] + 1; up[v][0] = p; for(auto e: g[v]){ int u = e.to; if(u != p){ I[u][0] = { e.tm, e.tm, 1 }; D[u][0] = { e.tm, e.tm, 1 }; dfs(u, v); } } tout[v] = timer++; } bool is_ancestor(int u, int v){ return tin[u] <= tin[v] && tout[v] <= tout[u]; } int _lca(int u, int v){ if(is_ancestor(u, v)) return u; if(is_ancestor(v, u)) return v; for(int j = K-1; j >= 0; --j) if(!is_ancestor(up[u][j], v)) u = up[u][j]; return up[u][0]; } void solve(){ cin >> n >> k; vector<Query> Q; for(int i = 1; i < n + k; ++i){ char tp; cin >> tp; int u, v; cin >> u >> v; if(tp == 'S'){ g[u].pb({v, i}); g[v].pb({u, i}); }else Q.pb({u, v, i, 0}); } dep[1] = 0; dfs(1, 1); for(int j = 1; j < K; ++j) for(int i = 1; i <= n; ++i){ up[i][j] = up[up[i][j - 1]][j - 1]; I[i][j] = { min(I[i][j - 1][0], I[up[i][j - 1]][j - 1][0]), max(I[i][j - 1][1], I[up[i][j - 1]][j - 1][1]), I[i][j - 1][2] && I[up[i][j - 1]][j - 1][2] && (I[i][j - 1][1] < I[up[i][j - 1]][j - 1][0]) }; D[i][j] = { min(D[i][j - 1][0], D[up[i][j - 1]][j - 1][0]), max(D[i][j - 1][1], D[up[i][j - 1]][j - 1][1]), D[i][j - 1][2] && D[up[i][j - 1]][j - 1][2] && (D[i][j - 1][0] > D[up[i][j - 1]][j - 1][1]) }; } for(auto &q: Q){ int u = q.a, v = q.b; int lca = _lca(u, v); // v to lca increasing, u to lca decreasin int lastu = -1, lastv = -1, mx = 0; bool ok = 1; for(int j = K - 1; j >= 0; --j){ if((dep[v] - dep[lca]) & (1<<j)){ mx = max(mx, I[v][j][1]); ok &= I[v][j][2]; if(lastv == -1){ lastv = I[v][j][1]; }else if(lastv < I[v][j][0]){ lastv = I[v][j][1]; }else ok = 0; v = up[v][j]; } if((dep[u] - dep[lca]) & (1<<j)){ mx = max(mx, D[u][j][1]); ok &= D[u][j][2]; if(lastu == -1){ lastu = D[u][j][0]; }else if(lastu > D[u][j][1]){ lastu = D[u][j][0]; }else ok = 0; u = up[u][j]; } } if(ok && lastu != -1 && lastv != -1){ ok = lastu > lastv; } if(ok && mx > q.tm) ok = 0; q.ans = ok; } for(auto q: Q) cout << (q.ans ? "yes\n" : "no\n"); } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

servers.cpp: In function 'int main()':
servers.cpp:137:15: warning: unused variable 'aa' [-Wunused-variable]
  137 |   int tt = 1, aa;
      |               ^~
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...