Submission #853996

#TimeUsernameProblemLanguageResultExecution timeMemory
853996mychecksedadInside information (BOI21_servers)C++17
0 / 100
41 ms38344 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{ char tp; int a, b, tm, ans = 0; }; 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[v][j], u)) v = up[v][j]; } return up[v][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({tp, u, v, i}); } 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); if(v == up[u][0] || u == up[v][0]){ q.ans = 1; continue; } // v to lca increasing, u to lca decreasin int lastu = -1, lastv = -1, maxu = 0, maxv = 0; bool ok = 1; int last = -1; for(int j = K - 1; j >= 0; --j){ if((dep[v] - dep[lca]) & (1<<j)){ maxv = max(maxv, I[u][j][1]); if(lastv == -1){ lastv = I[v][j][1]; v = up[v][j]; }else if(lastv < I[v][j][1]){ lastv = I[v][j][1]; v = up[v][j]; }else v = up[v][j], ok = 0; } if((dep[u] - dep[lca]) & (1<<j)){ maxu = max(maxu, D[u][j][1]); if(lastu == -1){ lastu = D[u][j][0]; u = up[u][j]; }else if(lastu > D[u][j][0]){ lastu = D[u][j][0]; u = up[u][j]; }else u = up[u][j], ok = 0; } } if(ok && lastu != -1 && lastv != -1){ ok = lastu > lastv; } if(ok && max(maxu, maxv) > 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 'void solve()':
servers.cpp:97:9: warning: unused variable 'last' [-Wunused-variable]
   97 |     int last = -1;
      |         ^~~~
servers.cpp: In function 'int main()':
servers.cpp:136:15: warning: unused variable 'aa' [-Wunused-variable]
  136 |   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...