Submission #972384

# Submission time Handle Problem Language Result Execution time Memory
972384 2024-04-30T11:36:01 Z vladilius Werewolf (IOI18_werewolf) C++17
0 / 100
730 ms 71320 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

vector<int> check_validity(int n, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r){
    vector<int> g[n + 1];
    int m = (int) x.size();
    if (m != (n - 1)) exit(0);
    for (int i = 0; i < m; i++){
        x[i]++; y[i]++;
        g[x[i]].pb(y[i]);
        g[y[i]].pb(x[i]);
    }
    for (int i = 0; i < n; i++){
        l[i]++; r[i]++;
        s[i]++; e[i]++;
    }
    int f = 0;
    for (int i = 1; i <= n; i++){
        if (g[i].size() == 1){
            f = i;
            break;
        }
    }
    vector<int> a = {0};
    function<void(int, int)> dfs = [&](int v, int pr){
        a.pb(v);
        for (int i: g[v]){
            if (i != pr){
                dfs(i, v);
            }
        }
    };
    dfs(f, 0);
    
    const int lg = ceil(log2(n));
    vector<vector<int>> sp(n + 1, vector<int>(lg + 1));
    for (int i = 1; i <= n; i++){
        sp[i][0] = a[i];
    }
    for (int k = 1; k <= lg; k++){
        for (int i = 1; i + (1 << k) <= n + 1; i++){
            sp[i][k] = min(sp[i][k - 1], sp[i + (1 << (k - 1))][k - 1]);
        }
    }
    vector<int> log(n + 1);
    for (int i = 2; i <= n; i++){
        log[i] = log[i / 2] + 1;
    }
    
    auto get = [&](int l, int r){
        int k = log[r - l + 1];
        return min(sp[l][k], sp[r - (1 << k) + 1][k]);
    };
    
    auto check = [&](int x, pii& R){
        return (R.ff <= x && x <= R.ss);
    };
    
    auto find = [&](int x, pii R){
        int l1 = x, r1 = n;
        while (l1 + 1 < r1){
            int m = (l1 + r1) / 2;
            if (!check(get(x, m), R)){
                r1 = m - 1;
            }
            else {
                l1 = m;
            }
        }
        if (x <= r1 && check(get(x, r1), R)){
            l1 = r1;
        }
        
        int l2 = 1, r2 = x;
        while (l2 + 1 < r2){
            int m = (l2 + r2) / 2;
            if (!check(get(m, x), R)){
                l2 = m + 1;
            }
            else {
                r2 = m;
            }
        }
        if (l2 <= x && check(get(l2, x), R)){
            r2 = l2;
        }
        return make_pair(r2, l1);
    };
    
    auto inter = [&](pii A, pii B){
        if (A.ff > B.ff) swap(A, B);
        return (A.ss >= B.ff);
    };
    
    int q = (int) s.size();
    vector<int> out;
    for (int i = 0; i < q; i++){
        int u = s[i], v = e[i];
        pii A = find(u, {l[i], n});
        pii B = find(v, {1, r[i]});
        out.pb(inter(A, B));
    }
    return out;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 730 ms 71320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 436 KB Output isn't correct
2 Halted 0 ms 0 KB -