Submission #878026

# Submission time Handle Problem Language Result Execution time Memory
878026 2023-11-24T02:47:06 Z sleepntsheep Werewolf (IOI18_werewolf) C++17
0 / 100
836 ms 190816 KB
#include "werewolf.h"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstddef>
using namespace std;
#define NN 200000
 
 
struct kruskal_reconstruction_tree
{
    vector<int> p, tin, tout, rv;
    int l;
    vector<vector<int>> g;
 
    kruskal_reconstruction_tree(int n, int n0) : p(n), tin(n), tout(n), rv(n), l(n0), g(n)
    {
        iota(p.begin(), p.end(), 0);
    }
 
    int find(int x)
    {
        if (p[x] == x) return x;
        return p[x] = find(p[x]);
    }
 
    int unite(int x, int y)
    {
        x = find(x); y = find(y);
        if (x == y) return 0;
        g[p[x] = p[y] = ++l] = {x, y};
        return 1;
    }
 
    int timer = 0;
    void dfs(int u, int p)
    {
        rv[tin[u] = timer++] = u;
        for (auto v : g[u]) if (v != p) dfs(v, u);
        tout[u] = timer - 1;
    }
 
    void tour()
    {
        for (int i = l; i--;) if (!tin[i]) dfs(i, i);
    }
};
 
kruskal_reconstruction_tree krt1(NN<<2, NN);
kruskal_reconstruction_tree krt2(NN<<2, NN);
 
vector<int> t[NN<<3];
 
void add(int v, int l, int r, int p, int k)
{
    t[v].push_back(k);
    if (l == r) return;
    if (p <= (l+r)/2) add(2*v+1, l, (l+r)/2, p, k);
    else add(2*v+2, (l+r)/2+1, r, p, k);
}
 
int qry(int v, int l, int r, int x, int y, int k)
{
    if (r < x || y < l) return 1e9;
    if (x <= l && r <= y)
    {
        auto it = lower_bound(t[v].begin(), t[v].end(), k);
        return it == t[v].end() ? 1e9 : *it;
    }
    return min(qry(2*v+1, l, (l+r)/2, x, y, k), qry(2*v+2, (l+r)/2+1, r, x, y, k));
}
 
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 Q = S.size();
    vector<int> A(Q);
    vector<vector<int>> g(N);
 
    for (int i = 0; i < (int)X.size(); ++i) g[X[i]].push_back(Y[i]), g[Y[i]].push_back(X[i]);
 
    /* build krt */
    vector<int> rtl(Q), rtr(Q);
    {
        vector<vector<int>> byl(N), byr(N);
        for (int i = 0; i < Q; ++i) byl[L[i]].push_back(i), byr[R[i]].push_back(i);
        for (int i = N; i--;)
        {
            for (auto v : g[i]) if (v >= i) krt1.unite(v, i);
            for (auto j : byl[i]) rtl[j] = krt1.find(S[j]);
        }
        for (int i = 0; i < N; ++i)
        {
            for (auto v : g[i]) if (v <= i) krt2.unite(v, i);
            for (auto j : byr[i]) rtr[j] = krt2.find(E[j]);
        }
    }
 
    krt1.tour();
    krt2.tour();
 
     int LL = krt1.timer;
    /* build merge sort tree */
    {
        for (int i = 0; i < krt2.timer; ++i)
            add(0, 0, LL, krt1.tin[krt2.rv[i]], i);
    }
 
    for (int i = 0; i < Q; ++i)
    {
        auto u = qry(0, 0, LL, krt1.tin[rtl[i]], krt1.tout[rtl[i]], krt2.tin[rtr[i]]);
        A[i] = u <= krt2.tout[rtr[i]];
    }
 
    return A;
}
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 127484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 127484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 836 ms 190816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 127484 KB Output isn't correct
2 Halted 0 ms 0 KB -