Submission #700898

# Submission time Handle Problem Language Result Execution time Memory
700898 2023-02-19T11:33:50 Z cig32 Inside information (BOI21_servers) C++17
0 / 100
27 ms 10508 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 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);
  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(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:80: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]
   80 |   for(int i=0; i<et.size(); i++) r[et[i]]=i;
      |                ~^~~~~~~~~~
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++) spt[0][i] = {de[et[i]], et[i]};
      |                ~^~~~~~~~~~
servers.cpp:84: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]
   84 |     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 22 ms 10428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 10428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 10428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 10428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 10484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 10484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 10508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 10508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 10472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 10472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 10432 KB Output isn't correct
2 Halted 0 ms 0 KB -