답안 #494819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494819 2021-12-16T18:07:47 Z dxz05 늑대인간 (IOI18_werewolf) C++14
0 / 100
1494 ms 150408 KB
#include "werewolf.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 4e5 + 3e2;

vector<int> g[MAXN];

vector<int> vec, ord;
void dfs(int v, int p){
    ord[v] = vec.size();
    vec.push_back(v);
    for (int u : g[v]){
        if (u != p) dfs(u, v);
    }
}

int Tmin[MAXN][20], Tmax[MAXN][20], Log[MAXN];

int get_min(int l, int r){
    if (l > r) return 1e9;
    int j = Log[r - l + 1];
    return min(Tmin[l][j], Tmin[r - (1 << j) + 1][j]);
}

int get_max(int l, int r){
    if (l > r) return -1e9;
    int j = Log[r - l + 1];
    return max(Tmax[l][j], Tmax[r - (1 << j) + 1][j]);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
    int M = X.size(), Q = S.size();
    vector<int> A(Q, 0);

    if (M != N - 1) return A;

    for (int i = 0; i < M; i++){
        g[X[i]].push_back(Y[i]);
        g[Y[i]].push_back(X[i]);
    }

    ord.resize(N);

    for (int i = 0; i < N; i++){
        if (g[i].size() == 1){
            dfs(i, i);
            break;
        }
    }

    Log[1] = 0;
    for (int i = 0; i < MAXN; i++){
        if (i < N) Tmin[i][0] = Tmax[i][0] = vec[i];
        if (i > 1) Log[i] = Log[i / 2] + 1;
    }

    for (int j = 1; j < 20; j++){
        for (int i = 0; i < N; i++){
            if (i + (1 << j) - 1 < N){
                Tmin[i][j] = min(Tmin[i][j - 1], Tmin[i + (1 << (j - 1))][j - 1]);
                Tmax[i][j] = max(Tmax[i][j - 1], Tmax[i + (1 << (j - 1))][j - 1]);
            }
        }
    }

    for (int i = 0; i < Q; i++){
        S[i] = ord[S[i]], E[i] = ord[E[i]];

        if (S[i] < E[i]){
            int l = S[i], r = N - 1;
            while (l <= r){
                int mid = (l + r) >> 1;
                if (get_min(S[i], mid) >= L[i]) l = mid + 1; else
                    r = mid - 1;
            }

            int x = l - 1;

            l = 0, r = E[i];
            while (l <= r){
                int mid = (l + r) >> 1;
                if (get_max(mid, E[i]) <= R[i]) r = mid - 1; else
                    l = mid + 1;
            }

            int y = r + 1;

            A[i] = x >= y;

        } else {
            int l = 0, r = S[i];
            while (l <= r){
                int mid = (l + r) >> 1;
                if (get_min(mid, S[i]) >= L[i]) r = mid - 1; else
                    l = mid + 1;
            }

            int x = r + 1;

            l = E[i], r = N - 1;
            while (l <= r){
                int mid = (l + r) >> 1;
                if (get_max(E[i], mid) <= R[i]) l = mid + 1; else
                    r = mid - 1;
            }

            int y = l - 1;

            A[i] = x <= y;
        }

    }

}

Compilation message

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:116:1: warning: control reaches end of non-void function [-Wreturn-type]
  116 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1494 ms 150408 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9932 KB Output isn't correct
2 Halted 0 ms 0 KB -