Submission #700900

# Submission time Handle Problem Language Result Execution time Memory
700900 2023-02-19T11:37:29 Z cig32 Inside information (BOI21_servers) C++17
0 / 100
43 ms 9624 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
int mparw[MAXN];
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(parw[node]<parw[prv]) {
      u2[node]=de[node];
      u1[node]=u1[prv];
    }
    else {
      u1[node]=de[node];
      u2[node]=u2[prv];
    }
  }
  for(auto x: adj[node]) {
    if(x.first!=prv) {
      parw[x.first]=x.second;
      mparw[x.first]=max(mparw[node],parw[x.first]);
      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)];
}
void solve(int tc) {
  cin >> n >> k;
  vector<pair<pair<int, int>, int> > vt;
  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});
    }
    else {
      int a, d;
      cin >> a >> d;
      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))]);
  }
  for(auto x: vt) {
    int a=x.first.first, d=x.first.second, i=x.second;
    int maw=max(mparw[a],mparw[d]);
    if(par[a]==d || par[d]==a) cout<<"yes\n";
    else if(maw>i) cout<<"no\n";
    else if(u1[d]<=de[lca(a,d)] && u2[a]<=de[lca(a,d)]) cout << "yes\n";
    else cout<<"no\n";
  }


}
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:82: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]
   82 |   for(int i=0; i<et.size(); i++) r[et[i]]=i;
      |                ~^~~~~~~~~~
servers.cpp:84: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]
   84 |   for(int i=0; i<et.size(); i++) spt[0][i] = {de[et[i]], et[i]};
      |                ~^~~~~~~~~~
servers.cpp:86: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]
   86 |     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))]);
      |                  ~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 9540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 9540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 9548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 9548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 9624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 9624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 9580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 9580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 9556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 9556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 9564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 9564 KB Output isn't correct
2 Halted 0 ms 0 KB -