Submission #600902

# Submission time Handle Problem Language Result Execution time Memory
600902 2022-07-21T08:59:41 Z Belgutei Werewolf (IOI18_werewolf) C++17
0 / 100
231 ms 36984 KB
#include "werewolf.h"
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second

vector<int> edge[200005];
bool visited[200005], ok;
int n, pos[200005];
int l,r;
vector<int > mn[30],mx[30],a,ans;
pair<int,int> p[200005];
int parent[200005], dad[200005];

void dfs(int node) {
  visited[node] = 1;
  pos[node] = a.size();
  a.pb(node);
  for(auto x: edge[node]) if(visited[x] == 0) dfs(x);
}

int level, ret;
void build_tree() {
  for(int i = 0; i < 30; i ++) {
    if((1 << i) >= n) {level = i; break;}
  }
  for(int i = 0; i < (1 << level); i ++) {
    if(i < n) {
      mx[level].pb(a[i]);
    }
    else {
      mx[level].pb(0);
    }
  }
  for(int i = level - 1; i >= 0; i --) {
    for(int j = 1; j < mx[i + 1].size(); j += 2) {
      mx[i].pb(max(mx[i + 1][j], mx[i + 1][j - 1]));
    }
  }
}

void dfs(int k, int x, int L, int R) {
  int y = (1 << (level - k)) * x;
  int z = (1 << (level - k)) * (x + 1) - 1;
  if(L <= y && z <= R) {
     ret = max(ret, mx[k][x]);
    return;
  }
  if(z < L || y > R || k == level) return;
  dfs(k + 1, x * 2, L, R);
  dfs(k + 1, x * 2 + 1, L, R);
}

int find(int node) {
  if(parent[node] == node) return node;
  return parent[node] = find(parent[node]);
}

int d_find(int node) {
  if(dad[node] == node) return node;
  return dad[node] = find(dad[node]);
}

std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,std::vector<int> S, std::vector<int> E,std::vector<int> L, std::vector<int> R) {
  n = N;
  for(int i = 0; i < X.size(); i ++) {
    edge[X[i]].pb(Y[i]);
    edge[Y[i]].pb(X[i]);
  }
  for(int i = N - 1; i >= 0; i --) if(edge[i].size() == 1) {dfs(i); break;}
  for(int i = 0; i < N; i ++) {parent[i] = i; dad[i] = i;}
  for(int i = 0; i < S.size(); i ++) {
    p[i].ff = -L[i];
    p[i].ss = i;
  }
  sort(p, p + S.size());
  build_tree();
  //
  for(int j = 0; j < 1; j ++) {

    int i = p[j].ss;
    if(S[i] < L[i] || E[i] > R[i]) {ans.pb(0); continue;}
    if(pos[S[i]] < pos[E[i]]) {
      int A = find(S[i]);
      if(pos[A] >= pos[E[i]]) {ans.pb(1); continue;}
      while(pos[A] < pos[E[i]]) {
        if(a[pos[A]+ 1] >= L[i]) {parent[A] = find(a[pos[A] + 1]); A = parent[A];}
        else break;
      }
      if(pos[A] >= pos[E[i]]) {ans.pb(1); continue;}
      ret = -1;
      dfs(0,0,pos[A],pos[E[i]]);
      if(ret <= R[i]) ans.pb(1);
      else ans.pb(0);
    } 
    else {
      int A = d_find(S[i]);
      if(pos[A] <= pos[E[i]]) {ans.pb(1); continue;}
      while(pos[A] > pos[E[i]]) {
        if(a[pos[A] - 1] >= L[i]) {dad[A] = d_find(dad[a[pos[A] - 1]]); A = dad[A];}
        else break;
      }
      if(pos[A] <= pos[E[i]]) {ans.pb(1); continue;}
      ret = -1;
      dfs(0,0,pos[E[i]],pos[A]);
      if(ret <= R[i]) ans.pb(1);
      else ans.pb(0);
    }
  }
  //
  return ans;
}

Compilation message

werewolf.cpp: In function 'void build_tree()':
werewolf.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int j = 1; j < mx[i + 1].size(); j += 2) {
      |                    ~~^~~~~~~~~~~~~~~~~~
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:69:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for(int i = 0; i < X.size(); i ++) {
      |                  ~~^~~~~~~~~~
werewolf.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for(int i = 0; i < S.size(); i ++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 36984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -