Submission #988874

# Submission time Handle Problem Language Result Execution time Memory
988874 2024-05-26T14:13:15 Z Essa2006 Werewolf (IOI18_werewolf) C++14
0 / 100
4000 ms 123036 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)

const int lg = 20, inf = 1e9;
int n, cur;
vector<vector<int>> A;
vector<array<int, 2>> P, Anc, L, R, Dsc, Fin;
vector<vector<array<int, 2>>> Up;

int find(int ind, int id) {
    if (P[ind][id] == ind) {
        return ind;
    }
    return P[ind][id] = find(P[ind][id], id);
}

array<int, 2> cnt;
void merge(int a, int b, int id) {
    int ga = find(a, id), gb = find(b, id);
    if (ga == gb) {
        return ;
    }

    assert(cnt[id] >= n);
    Anc[cnt[id]][id] = cur;
    L[cnt[id]][id] = ga, R[cnt[id]][id] = gb;
    Up[ga][0][id] = Up[gb][0][id] = P[ga][id] = P[gb][id] = cnt[id]++;

    return;
}

array<int, 2> time_;
void build(int u, int id) {
    Dsc[u][id] = time_[id]++;

    if (Up[u][0][id] == -1) {
        Up[u][0][id] = u;
    }
    for (int j = 1; j <= lg; j++) {
        Up[u][j][id] = Up[Up[u][j - 1][id]][j - 1][id];
    }

    if (u >= n) {
        build(L[u][id], id);
        build(R[u][id], id);
    }

    Fin[u][id] = time_[id]++;
}

int lca(int u, int c, int id) {
    for (int j = lg; j >= 0; j--) {
        if (Anc[Up[u][j][id]][id] <= c) {
            u = Up[u][j][id];
        }
    }
    return u;
}

vector<int> check_validity(int nn, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> LL, vector<int> RR) {
    n = nn;
    cnt[0] = cnt[1] = n;
    A.resize(n), P.resize(2 * n), Anc.resize(2 * n, {inf, inf}), L.resize(2 * n, {-1, -1}), R.resize(2 * n, {-1, -1}), Dsc.resize(2 * n), Fin.resize(2 * n);
    Up.resize(2 * n, vector<array<int, 2>>(lg + 1, {-1, -1}));
    for (int i = 0; i < 2 * n; i++) {
        P[i][0] = P[i][1] = i;
    }


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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < A[i].size(); j++) {
            if (A[i][j] < i) {
                cur = i;
                merge(i, A[i][j], 0);
            }
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < A[i].size(); j++) {
            if (A[i][j] > i) {
                cur =  n - 1 - i;
                merge(i, A[i][j], 1);
            }
        }
    }


    build(cnt[0] - 1, 0);
    build(cnt[1] - 1, 1);

    vector<int> Ans(LL.size());
    for (int i = 0; i < S.size(); i++) {
        int u = lca(S[i], RR[i], 0), v = lca(E[i], (n - 1) - LL[i], 1);
        if (E[i] < LL[i] || S[i] > RR[i]) {
            continue;
        }
        for (int j = 0; j < n; j++) {
            if (Dsc[u][0] <= Dsc[j][0] && Dsc[j][0] <= Fin[u][0]) {
                if (Dsc[v][1] <= Dsc[j][1] && Dsc[j][1] <= Fin[v][1]) {
                    Ans[i] = 1;
                }
            }
        }
    }


    return Ans;
}

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:76:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for (int i = 0; i < X.size(); i++) {
      |                     ~~^~~~~~~~~~
werewolf.cpp:82:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (int j = 0; j < A[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
werewolf.cpp:90:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for (int j = 0; j < A[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
werewolf.cpp:103:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |     for (int i = 0; i < S.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4099 ms 123036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -