Submission #434194

# Submission time Handle Problem Language Result Execution time Memory
434194 2021-06-20T17:28:26 Z Tiago_Marques Werewolf (IOI18_werewolf) C++17
0 / 100
4000 ms 54240 KB
#include "werewolf.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define REP(i, a, b) for (ll i=a; i<b; i++)
#define pb push_back

int ordem[200000];
vector<int> graph[200000];
int sparse_maximo[200000][20];
int sparse_minimo[200000][20];
int posicao[200000];

void create (int N)
{
    for (ll i=N-1; i>=0; i--)
    {
        sparse_maximo[i][0] = ordem[i];
        sparse_minimo[i][0] = ordem[i];
        REP(j, 1, 20)
        {
            if (i + (1<<j) > N)
                break;
            sparse_maximo[i][j] = max (sparse_maximo[i][j-1], sparse_maximo[i + (1<<(j-1))][j-1]);
            sparse_minimo[i][j] = max (sparse_minimo[i][j-1], sparse_minimo[i + (1<<(j-1))][j-1]);
        }
    }
}

int maximizar (int a, int b)
{
    int i = log2(b - a + 1);
    return max (sparse_maximo[a][i], sparse_maximo[b - (1<<i) + 1][i]);
}

int minimizar (int a, int b)
{
    int i = log2(b - a + 1);
    return min (sparse_minimo[a][i], sparse_minimo[b - (1<<i) + 1][i]);
}

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)
{
    int Q = S.size();
    vector<int> ans(Q);
    REP(i, 0, (int)X.size())
    {
        graph[X[i]].pb (Y[i]);
        graph[Y[i]].pb (X[i]);
    }
    REP(i, 0, N)
    {
        if ((int)graph[i].size() == 1)
        {
            ordem[0] = i;
            posicao[i] = 0;
            break;
        }
    }
    ordem[1] = graph[ordem[0]][0];
    posicao[ordem[1]] = 1;
    REP(i, 2, N)
    {
        if (graph[ordem[i-1]][0] == ordem[i-2])
            ordem[i] = graph[ordem[i-1]][1];
        else
            ordem[i] = graph[ordem[i-1]][0];
        posicao[ordem[i]] = i;
    }
    create(N);
    REP(i, 0, Q)
    {
        int inicio = posicao[S[i]];
        int fim = posicao[E[i]];
        if (S[i] < L[i] || E[i] > R[i])
        {
            ans[i] = 0;
            continue;
        }
        if (inicio < fim)
        {
            int minimo = inicio, maximo = fim;
            while (minimo != maximo)
            {
                int med = (minimo + maximo + 1)/2;
                if (minimizar(inicio, med) < L[i])
                    maximo = med - 1;
                else
                    minimo = med;
            }
            if (maximizar(minimo, fim) > R[i])
                ans[i] = 0;
            else
                ans[i] = 1;
        }
        else
        {
            int minimo = fim, maximo = inicio;
            while (minimo != maximo)
            {
                int med = (minimo + maximo + 1)/2;
                if (minimizar(med, inicio) < L[i])
                    minimo = med + 1;
                else
                    maximo = med;
            }
            if (maximizar(fim, minimo) > R[i])
                ans[i] = 0;
            else
                ans[i] = 1;
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4094 ms 4940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4094 ms 4940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4086 ms 54240 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4094 ms 4940 KB Time limit exceeded
2 Halted 0 ms 0 KB -