Submission #700905

# Submission time Handle Problem Language Result Execution time Memory
700905 2023-02-19T11:54:29 Z cig32 Inside information (BOI21_servers) C++17
5 / 100
184 ms 102596 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 2.5e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }

int n, k;
vector<pair<int,int> > adj[MAXN];
vector<int> et;
int l[MAXN], r[MAXN], de[MAXN];
pair<int, int> spt[18][MAXN];
int par[MAXN];
int u1[MAXN],u2[MAXN];//if strictly increasing/decreasing, min [height]
int parw[MAXN];//i->par[i] weight
void dfs(int node, int prv) {
  et.push_back(node);
  par[node]=prv;
  de[node] = (prv == -1 ? 0 : de[prv] + 1);
  if(prv != -1) {
    if(prv == 1) {
      u1[node]=u2[node]=0;
    }
    else if(parw[node]<parw[prv]) {
      u2[node]=de[node]-1;
      u1[node]=u1[prv];
    }
    else {
      u1[node]=de[node]-1;
      u2[node]=u2[prv];
    }
  }
  for(auto x: adj[node]) {
    if(x.first!=prv) {
      parw[x.first]=x.second;
      dfs(x.first, node);
      et.push_back(node);
    }
  }
}
int lca(int x, int y) {
  int m1=min(l[x],l[y]), m2=max(r[x],r[y]);
  int k=32-__builtin_clz(m2-m1+1)-1;
  return min(spt[k][m1],spt[k][m2-(1<<k)+1]).second;
}
int dist(int x, int y) {
  return de[x]+de[y]-2*de[lca(x,y)];
}
int dsu[MAXN];
int set_of(int u) {
  if(dsu[u] == u) return u;
  return dsu[u] = set_of(dsu[u]);
}
void union_(int u, int v) {
  dsu[set_of(u)] = set_of(v);
}
void solve(int tc) {
  cin >> n >> k;
  for(int i=1; i<=n; i++) dsu[i] = i;
  vector<pair<pair<int, int>, int> > vt;
  vector<int> oh;
  for(int i=0; i<n+k-1; i++) {
    char t; cin >> t;
    if(t == 'S') {
      int a, b;
      cin >> a >> b;
      adj[a].push_back({b, i});
      adj[b].push_back({a, i});
      union_(a, b);
    }
    else {
      int a, d;
      cin >> a >> d;
      if(set_of(a) == set_of(d)) oh.push_back(1);
      else oh.push_back(0);
      vt.push_back({{a, d}, i});
    }
  }
  dfs(1,-1);
  for(int i=0; i<et.size(); i++) r[et[i]]=i;
  for(int i=et.size()-1; i>=0; i--) l[et[i]]=i;
  for(int i=0; i<et.size(); i++) spt[0][i] = {de[et[i]], et[i]};
  for(int i=1; i<18; i++) {
    for(int j=0; j+(1<<i)-1<et.size(); j++) spt[i][j] = min(spt[i-1][j], spt[i-1][j+(1<<(i-1))]);
  }
  int ptr=0;
  for(auto x: vt) {
    int a=x.first.first, d=x.first.second, i=x.second;
    if(oh[ptr] == 0) cout << "no\n";
    else if(par[a] == d || par[d] == a) cout << "yes\n";
    else if(u1[d]<=de[lca(a,d)] && u2[a]<=de[lca(a,d)]) cout << "yes\n";
    else cout << "no\n";
    ptr++;
  }


}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}

Compilation message

servers.cpp: In function 'void solve(long long int)':
servers.cpp:96:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |   for(int i=0; i<et.size(); i++) r[et[i]]=i;
      |                ~^~~~~~~~~~
servers.cpp:98:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |   for(int i=0; i<et.size(); i++) spt[0][i] = {de[et[i]], et[i]};
      |                ~^~~~~~~~~~
servers.cpp:100:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for(int j=0; j+(1<<i)-1<et.size(); j++) spt[i][j] = min(spt[i-1][j], spt[i-1][j+(1<<(i-1))]);
      |                  ~~~~~~~~~~^~~~~~~~~~
servers.cpp:104:44: warning: unused variable 'i' [-Wunused-variable]
  104 |     int a=x.first.first, d=x.first.second, i=x.second;
      |                                            ^
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 10548 KB Output is correct
2 Correct 171 ms 102512 KB Output is correct
3 Correct 173 ms 102596 KB Output is correct
4 Correct 124 ms 101872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 10548 KB Output is correct
2 Correct 171 ms 102512 KB Output is correct
3 Correct 173 ms 102596 KB Output is correct
4 Correct 124 ms 101872 KB Output is correct
5 Incorrect 13 ms 10584 KB Extra information in the output file
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 10576 KB Output is correct
2 Correct 184 ms 102564 KB Output is correct
3 Correct 150 ms 102488 KB Output is correct
4 Correct 110 ms 101864 KB Output is correct
5 Incorrect 26 ms 11520 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 10576 KB Output is correct
2 Correct 184 ms 102564 KB Output is correct
3 Correct 150 ms 102488 KB Output is correct
4 Correct 110 ms 101864 KB Output is correct
5 Incorrect 26 ms 11520 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 10560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 10560 KB Output isn't correct
2 Halted 0 ms 0 KB -