답안 #854005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854005 2023-09-25T19:33:56 Z mychecksedad Inside information (BOI21_servers) C++17
50 / 100
234 ms 128192 KB
/* 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

servers.cpp: In function 'int main()':
servers.cpp:137:15: warning: unused variable 'aa' [-Wunused-variable]
  137 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 38036 KB Output is correct
2 Correct 61 ms 39888 KB Output is correct
3 Correct 45 ms 39884 KB Output is correct
4 Correct 55 ms 39888 KB Output is correct
5 Correct 40 ms 40124 KB Output is correct
6 Correct 46 ms 39908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 38036 KB Output is correct
2 Correct 61 ms 39888 KB Output is correct
3 Correct 45 ms 39884 KB Output is correct
4 Correct 55 ms 39888 KB Output is correct
5 Correct 40 ms 40124 KB Output is correct
6 Correct 46 ms 39908 KB Output is correct
7 Incorrect 23 ms 35784 KB Extra information in the output file
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 37828 KB Output is correct
2 Correct 147 ms 118280 KB Output is correct
3 Correct 142 ms 118280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 37828 KB Output is correct
2 Correct 147 ms 118280 KB Output is correct
3 Correct 142 ms 118280 KB Output is correct
4 Incorrect 23 ms 35784 KB Extra information in the output file
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 37832 KB Output is correct
2 Correct 144 ms 124860 KB Output is correct
3 Correct 147 ms 128192 KB Output is correct
4 Correct 168 ms 128140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 37832 KB Output is correct
2 Correct 144 ms 124860 KB Output is correct
3 Correct 147 ms 128192 KB Output is correct
4 Correct 168 ms 128140 KB Output is correct
5 Incorrect 23 ms 35784 KB Extra information in the output file
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 37784 KB Output is correct
2 Correct 148 ms 118456 KB Output is correct
3 Correct 141 ms 118716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 37784 KB Output is correct
2 Correct 148 ms 118456 KB Output is correct
3 Correct 141 ms 118716 KB Output is correct
4 Incorrect 24 ms 35792 KB Extra information in the output file
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 37840 KB Output is correct
2 Correct 145 ms 124860 KB Output is correct
3 Correct 147 ms 128184 KB Output is correct
4 Correct 161 ms 128188 KB Output is correct
5 Correct 38 ms 38680 KB Output is correct
6 Correct 152 ms 121532 KB Output is correct
7 Correct 153 ms 121972 KB Output is correct
8 Correct 182 ms 122420 KB Output is correct
9 Correct 153 ms 122556 KB Output is correct
10 Correct 201 ms 126396 KB Output is correct
11 Correct 228 ms 125708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 37840 KB Output is correct
2 Correct 145 ms 124860 KB Output is correct
3 Correct 147 ms 128184 KB Output is correct
4 Correct 161 ms 128188 KB Output is correct
5 Correct 38 ms 38680 KB Output is correct
6 Correct 152 ms 121532 KB Output is correct
7 Correct 153 ms 121972 KB Output is correct
8 Correct 182 ms 122420 KB Output is correct
9 Correct 153 ms 122556 KB Output is correct
10 Correct 201 ms 126396 KB Output is correct
11 Correct 228 ms 125708 KB Output is correct
12 Incorrect 23 ms 35792 KB Extra information in the output file
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 37832 KB Output is correct
2 Correct 51 ms 39888 KB Output is correct
3 Correct 46 ms 39888 KB Output is correct
4 Correct 56 ms 39888 KB Output is correct
5 Correct 44 ms 40056 KB Output is correct
6 Correct 46 ms 39908 KB Output is correct
7 Correct 38 ms 37784 KB Output is correct
8 Correct 148 ms 118452 KB Output is correct
9 Correct 141 ms 118232 KB Output is correct
10 Correct 25 ms 37832 KB Output is correct
11 Correct 144 ms 124860 KB Output is correct
12 Correct 147 ms 128188 KB Output is correct
13 Correct 161 ms 128104 KB Output is correct
14 Correct 38 ms 38600 KB Output is correct
15 Correct 148 ms 121532 KB Output is correct
16 Correct 143 ms 122000 KB Output is correct
17 Correct 192 ms 122488 KB Output is correct
18 Correct 158 ms 122556 KB Output is correct
19 Correct 195 ms 126252 KB Output is correct
20 Correct 234 ms 125724 KB Output is correct
21 Correct 149 ms 121788 KB Output is correct
22 Correct 148 ms 121788 KB Output is correct
23 Correct 155 ms 122040 KB Output is correct
24 Correct 159 ms 122084 KB Output is correct
25 Correct 178 ms 123256 KB Output is correct
26 Correct 140 ms 121532 KB Output is correct
27 Correct 134 ms 121788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 37832 KB Output is correct
2 Correct 51 ms 39888 KB Output is correct
3 Correct 46 ms 39888 KB Output is correct
4 Correct 56 ms 39888 KB Output is correct
5 Correct 44 ms 40056 KB Output is correct
6 Correct 46 ms 39908 KB Output is correct
7 Correct 38 ms 37784 KB Output is correct
8 Correct 148 ms 118452 KB Output is correct
9 Correct 141 ms 118232 KB Output is correct
10 Correct 25 ms 37832 KB Output is correct
11 Correct 144 ms 124860 KB Output is correct
12 Correct 147 ms 128188 KB Output is correct
13 Correct 161 ms 128104 KB Output is correct
14 Correct 38 ms 38600 KB Output is correct
15 Correct 148 ms 121532 KB Output is correct
16 Correct 143 ms 122000 KB Output is correct
17 Correct 192 ms 122488 KB Output is correct
18 Correct 158 ms 122556 KB Output is correct
19 Correct 195 ms 126252 KB Output is correct
20 Correct 234 ms 125724 KB Output is correct
21 Correct 149 ms 121788 KB Output is correct
22 Correct 148 ms 121788 KB Output is correct
23 Correct 155 ms 122040 KB Output is correct
24 Correct 159 ms 122084 KB Output is correct
25 Correct 178 ms 123256 KB Output is correct
26 Correct 140 ms 121532 KB Output is correct
27 Correct 134 ms 121788 KB Output is correct
28 Incorrect 23 ms 35876 KB Extra information in the output file
29 Halted 0 ms 0 KB -